Search code examples
jsonrgeojson

how to convert data from r to json and can be readable by geojson?


I have retrieve data from JSON to R and edited the data to dissolve the boundary. The data from JSON consist of list of Daerah and the coordinates, longitude and latitude. So I already dissolved the boundary to Wilayah which each Wilayah consist of many Daerah and I have several Wilayah.

ditu <- readOGR('mys2.json', 'OGRGeoJSON')    
lookup <- read.csv("json/aaa")    
soa1 <- merge(ditu, lookup, by.x="Name", by.y = "Daerah", all.x = TRUE)    
slsoa1 <- gUnaryUnion(soa1, id = soa1$Wilayah)
plot(slsoa1) 

My main problem is I want to save the data in JSON format and can be readable by GeoJSON. Any help would be appreciated.


Solution

  • library(geojsonio)

    library(rjsonio)

    mapwilayah<-geojson_json(slsoa1)

    all<-toJSON(mapwilayah)

    write(all,"mapwilayah.json")