I have used R to calculate a Voronoi tessellation I now want to use in an OSM umap. Because I want different areas to be easily distinguishable, following some hint at their github, I need a nested field, in this case _umap_options$color
But when I try to export such a simple feature collection to an geoJSON file, I either loose the nested column or the export won’t work at all. Exporting to JSON works fine, but I would prefer R to output a geoJSON file I could use directly.
Here is a MWE:
library(osmdata)
library(sf)
library(geojsonsf)
df1 <- data.frame(osm_id=c(1:3), name=c("foo","bar","test"),lon=c(7,8,9),lat=52)
sf1 <- st_as_sf(df1,coords=c("lon","lat"))
df2 <- data.frame(fillColor=c("red","green","blue"))
df1$"_umap_options" <- df2
sf2 <- st_as_sf(df1,coords=c("lon","lat"))
# a simple JSON has the nested information correctly
toJSON(sf2, pretty=TRUE)
# won't accept the object as input
sf_geojson(sf2)
# while the sf without nested columns goes through
sf_geojson(sf1)
# ignores the nested column
st_write(sf2,"/tmp/test.geojson")
st_write also issues a warning:
In clean_columns(as.data.frame(obj), factorsAsCharacter) :
Dropping column(s) _umap_options of class(es) data.frame
Am I missing some neccessary modification in my data.frames to allow this to be possible?
mars412 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.