ropensci / geojsonio

Convert many data formats to & from GeoJSON & TopoJSON
https://docs.ropensci.org/geojsonio
Other
151 stars 59 forks source link

object_name not passed to topojson_list, topojson_json #158

Closed camille-s closed 4 years ago

camille-s commented 4 years ago

Really appreciate this package. I'm trying to create a set of topojson objects with an object name other than "foo." I read #129 and see that the object_name argument was added to topojson_write, and that that argument is available in geo2topo.

Looking at the source code, topojson_json calls geojson_json, then geo2topo on that, but the ... gets passed only to the inner function (geojson_json), so the object_name argument gets lost. I have a weird workflow making a list of topojson lists, then writing that as a single json file for a React app, so topojson_write on its own doesn't work for this situation. Pretty sure I can put together a workaround, but wanted to bring this up anyway.

Again, thanks for the great code!

library(geojsonio)
#> 
#> Attaching package: 'geojsonio'
#> The following object is masked from 'package:base':
#> 
#>     pretty

shp <- us_cities[1:2,]

topo1 <- topojson_list(shp, object_name = "city")
#> Assuming 'long' and 'lat' are longitude and latitude, respectively
names(topo1$objects)
#> [1] "foo"

topo2 <- topojson_json(shp, object_name = "city")
#> Assuming 'long' and 'lat' are longitude and latitude, respectively
topo2
#> {"type":"Topology","objects":{"foo":{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[-99.74,32.45],"properties":{"name":"Abilene TX","country.etc":"TX","pop":"113888","capital":"0"}},{"type":"Point","coordinates":[-81.52,41.08],"properties":{"name":"Akron OH","country.etc":"OH","pop":"206634","capital":"0"}}]}},"arcs":[],"bbox":[-99.74,32.45,-81.52,41.08]}

geo1 <- geojson_json(shp)
#> Assuming 'long' and 'lat' are longitude and latitude, respectively
geo2topo(geo1, object_name = "city")
#> {"type":"Topology","objects":{"city":{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[-99.74,32.45],"properties":{"name":"Abilene TX","country.etc":"TX","pop":"113888","capital":"0"}},{"type":"Point","coordinates":[-81.52,41.08],"properties":{"name":"Akron OH","country.etc":"OH","pop":"206634","capital":"0"}}]}},"arcs":[],"bbox":[-99.74,32.45,-81.52,41.08]}

Created on 2020-01-08 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 3.6.1 (2019-07-05) #> os macOS Mojave 10.14.6 #> system x86_64, darwin15.6.0 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/New_York #> date 2020-01-08 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0) #> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.0) #> callr 3.4.0 2019-12-09 [1] CRAN (R 3.6.1) #> class 7.3-15 2019-01-01 [1] CRAN (R 3.6.1) #> classInt 0.4-2 2019-10-17 [1] CRAN (R 3.6.0) #> cli 2.0.0 2019-12-09 [1] CRAN (R 3.6.1) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0) #> crul 0.9.0 2019-11-06 [1] CRAN (R 3.6.0) #> curl 4.3 2019-12-02 [1] CRAN (R 3.6.1) #> DBI 1.1.0 2019-12-15 [1] CRAN (R 3.6.0) #> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0) #> devtools 2.2.1 2019-09-24 [1] CRAN (R 3.6.0) #> digest 0.6.23 2019-11-23 [1] CRAN (R 3.6.0) #> e1071 1.7-3 2019-11-26 [1] CRAN (R 3.6.0) #> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.0) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0) #> fansi 0.4.0 2018-10-05 [1] CRAN (R 3.6.0) #> foreign 0.8-74 2019-12-26 [1] CRAN (R 3.6.0) #> fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.0) #> geojson 0.3.2 2019-01-31 [1] CRAN (R 3.6.0) #> geojsonio * 0.9.0 2020-01-08 [1] Github (ropensci/geojsonio@5ddbf22) #> geojsonlint 0.3.0 2019-02-08 [1] CRAN (R 3.6.0) #> glue 1.3.1.9000 2020-01-08 [1] Github (tidyverse/glue@b9ffe6c) #> highr 0.8 2019-03-20 [1] CRAN (R 3.6.0) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.0) #> httpcode 0.2.0 2016-11-14 [1] CRAN (R 3.6.0) #> jqr 1.1.0 2018-10-22 [1] CRAN (R 3.6.0) #> jsonlite 1.6 2018-12-07 [1] CRAN (R 3.6.0) #> jsonvalidate 1.1.0 2019-06-25 [1] CRAN (R 3.6.0) #> KernSmooth 2.23-16 2019-10-15 [1] CRAN (R 3.6.0) #> knitr 1.26 2019-11-12 [1] CRAN (R 3.6.0) #> lattice 0.20-38 2018-11-04 [1] CRAN (R 3.6.1) #> lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.0) #> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0) #> maptools 0.9-9 2019-12-01 [1] CRAN (R 3.6.1) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.0) #> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.0) #> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.0) #> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.6.0) #> processx 3.4.1 2019-07-18 [1] CRAN (R 3.6.0) #> ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.0) #> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.0) #> Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.0) #> remotes 2.1.0 2019-06-24 [1] CRAN (R 3.6.0) #> rgeos 0.5-2 2019-10-03 [1] CRAN (R 3.6.0) #> rlang 0.4.2.9000 2020-01-08 [1] Github (r-lib/rlang@e48b07d) #> rmarkdown 2.0 2019-12-12 [1] CRAN (R 3.6.0) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0) #> sf 0.8-1 2020-01-08 [1] Github (r-spatial/sf@50c6508) #> sp 1.3-2 2019-11-07 [1] CRAN (R 3.6.0) #> stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0) #> testthat 2.3.1 2019-12-01 [1] CRAN (R 3.6.1) #> units 0.6-5 2019-10-08 [1] CRAN (R 3.6.0) #> usethis 1.5.1 2019-07-04 [1] CRAN (R 3.6.0) #> V8 2.3 2019-07-02 [1] CRAN (R 3.6.0) #> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0) #> xfun 0.11 2019-11-12 [1] CRAN (R 3.6.1) #> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.6.0) #> #> [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library ```
sckott commented 4 years ago

thanks for opening this issue @camille-s & for the kind words (its a group effort)

taking a look

sckott commented 4 years ago

@camille-s added object_name param to topojson fxns, let me know if that works fo ryou

camille-s commented 4 years ago

@sckott That works, thank you!

github-actions[bot] commented 1 year ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.