R: rgdal writing GeoJSON

778 Views Asked by At

I'm having a problem with rgdal which drops the projection information when writing geoJSON files.

library(rgdal)

inputJSON<- readOGR("test.geojson", "OGRGeoJSON") # works!

If i type summary(inputJSON) i get the following output:

Object of class SpatialPointsDataFrame

Coordinates:
          min      max
coords.x1   0 499690.8
coords.x2   0 321771.2
Is projected: TRUE 
proj4string :
[+proj=tmerc +lat_0=0 +lon_0=13.33333333333333 +k=1 +x_0=450000 +y_0=-5000000
+ellps=bessel +towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232 +units=m +no_defs]

Thats telling me that the file was successfully read into R and that it also gets the projection information.

After some data manipulating I then want to save my data.frame (inputJSON) as a new geoJSON file using the following command:

writeOGR(inputJSON, "outTest.geojson", layer="inputJSON", driver="GeoJSON",check_exists = FALSE)

that also produces the desired geoJSON file but it does not write the projection information into it and well a geoJSON file without that information is pretty much (for my proposes) useless.

For comparison the beginning of the input file (test.geojson):

{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::31258" } },

"features": [

The file produced (outTest.geojson):

{
"type": "FeatureCollection",

"features": [

so this:

"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::31258" } },

important part is missing.

If I`m not mistaken my rgdal version is

rgdal’ version 1.0-6

and should be the newest. Well I also tried other packages with a available geoJSON file writer (geojsonio,leafletR) but non of them considers the projection. So what Im I missing? Is there any possibility to make that work? Im thinking that the GeoJSON driver of ogr2ogr (which the package is based on) does not handle the projection at all. Transferring a shapefile to a geoJSON file over the commandline the resulting geoJSON file also misses the projection information. Im really confused!

So what im i missing?

Does anyone have (any) solution?

0

There are 0 best solutions below