SymbolixAU / geojsonsf

Conversion between sf and geojson
Other
82 stars 7 forks source link

Allow nested `property` values #17

Closed SymbolixAU closed 6 years ago

SymbolixAU commented 6 years ago

e.g.

js <- '{"type":"Feature","properties":{"prop0":{"foo":"bar"}},"geometry":{"type":"Point","coordinates":[0,0]}}'

v0.2 converts the prop0 object to a 'string' (initially for speed and convenience).

Simple feature collection with 1 feature and 1 field
geometry type:  POINT
dimension:      XY
bbox:           xmin: 0 ymin: 0 xmax: 0 ymax: 0
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs
     geometry         prop0
1 POINT (0 0) {"foo":"bar"}
SymbolixAU commented 6 years ago

sf appears to do the same


sf <- sf::st_read('{"type":"Feature","properties":{"prop0":{"foo":"bar"}},"geometry":{"type":"Point","coordinates":[0,0]}}')
str(sf)
# Classes ‘sf’ and 'data.frame':    1 obs. of  2 variables:
#   $ prop0   : Factor w/ 1 level "{ \"foo\": \"bar\" }": 1
# $ geometry:sfc_POINT of length 1; first list element: Classes 'XY', 'POINT', 'sfg'  num [1:2] 0 0
# - attr(*, "sf_column")= chr "geometry"
# - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA
# ..- attr(*, "names")= chr "prop0"
sf

Simple feature collection with 1 feature and 1 field
geometry type:  POINT
dimension:      XY
bbox:           xmin: 0 ymin: 0 xmax: 0 ymax: 0
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs
             prop0    geometry
1 { "foo": "bar" } POINT (0 0)
SymbolixAU commented 6 years ago

If sf changes behaviour I will reopen this issue