Skip to content

WriteOGR to GeoJSON loses CRS

9 messages · Philip Greenwood, Frede Aakmann Tøgersen, Roger Bivand

#
Hi

Google points me to http://geojson.org/geojson-spec.html. See Section 3 about CRSs.

Yours sincerely / Med venlig hilsen


Frede Aakmann T?gersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender.
#
Sorry. I was too hasty. I suppose that your problem is with the GDAL drivers. I see that http://www.gdal.org/drv_geojson.html points to http://www.gdal.org/drv_geojson.html.

Which package belong writeOGR to. What is the version of the package? What is the version of your GDAL installation. What does e.g. 'gdalinfo --formats' show?

Yours sincerely / Med venlig hilsen


Frede Aakmann T?gersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender.
#
Dooh, it must be Monday morning and not Tuesday. A copy and paste error: http://www.gdal.org/drv_geojson.html points to http://wiki.geojson.org/GeoJSON_draft_version_5. 

Yours sincerely / Med venlig hilsen


Frede Aakmann T?gersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender.
#
On Tue, 12 Aug 2014, Philip Greenwood wrote:

            
Which is from February 2013, current is 0.8-16. More importantly, we don't 
know which version of GDAL is loaded when rgdal loads - messages are 
printed on-screen to tell you - nor do we know how you installed rgdal.

With GDAL 1.11.0, released 2014/04/16, I see:

dsn <- system.file("vectors", package = "rgdal")[1]
cities <- readOGR(dsn=dsn, layer="cities")
summary(cities)
#...
#[+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0]
#...
td <- tempdir()
writeOGR(cities, paste(td, ".geojson", sep=.Platform$file.sep),
  "OGRGeoJSON", driver="GeoJSON")
summary(readOGR(paste(td, ".geojson", sep=.Platform$file.sep),
  "OGRGeoJSON"))
#...
#[+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs]
#...

with the head of:

file.show(paste(td, ".geojson", sep=.Platform$file.sep))

"crs": { "type": "name", "properties": { "name": 
"urn:ogc:def:crs:OGC:1.3:CRS84" } },

where urn:ogc:def:crs:OGC:1.3:CRS84 is WGS 84 longitude-latitude on p. 18 
of https://portal.opengeospatial.org/files/?artifact_id=24045.

Not quite the same CRS, but a CRS is recorded. I think that your problem 
is related to the version of GDAL loaded into rgdal. The driver page on 
www.gdal.org relates to the current release and may include information 
for the development version. Your version seems to be old.
ogrinfo --formats, or equivalently ogrDrivers() in R with rgdal loaded.

Hope this clarifies,

Roger

  
    
#
Hi

I can get your example (SpatialPointsDataFrame) to work. On my windows box I have:
Loading required package: sp
rgdal: version: 0.8-16, (SVN revision 498)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.11.0, released 2014/04/16
Path to GDAL shared files: c:/Programmer/R/R-3.1.0/library/rgdal/gdal
GDAL does not use iconv for recoding strings.
Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
Path to PROJ.4 shared files: c:/Programmer/R/R-3.1.0/library/rgdal/proj

However I cannot get this (using SpatialPolygonsDataFrame) to work:
Checking rgeos availability: TRUE
IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
Object of class SpatialPolygonsDataFrame
Coordinates:
        min       max
x -84.32385 -75.45698
y  33.88199  36.58965
Is projected: FALSE 
proj4string : [+proj=longlat +ellps=clrk66]
Data attributes:
      AREA          PERIMETER         CNTY_         CNTY_ID            NAME   
 Min.   :0.0420   Min.   :0.999   Min.   :1825   Min.   :1825   Alamance : 1
No crs information at top of file.

Tried this giving no crs information in xx.geojson:

ogr2ogr -f GeoJSON c:\Users\frtog\xx.geojson c:\\Programmer\\R\\R-3.1.0\\library\\maptools\\shapes\\sids.shp

But this gave crs information:

ogr2ogr -f GeoJSON  -s_srs EPSG:4008 -t_srs EPSG:4008 c:\Users\frtog\xx.geojson c:\\Programmer\\R\\R-3.1.0\\library\\maptools\\shapes\\sids.shp

Had to include both -s_srs and -t_srs to get it to work. EPSG:4008 specifies "+proj=longlat +ellps=clrk66" as the shape file was read with. 

Yours sincerely / Med venlig hilsen


Frede Aakmann T?gersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender.
#
On Tue, 12 Aug 2014, Frede Aakmann T?gersen wrote:

            
The definition is clearly not being recognised by the OGR driver, possibly 
needing a +towgs84= key or +datum= defintion:

proj4string(xx) <- CRS("+proj=longlat +ellps=clrk66 +datum=NAD27")

gives:

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

which is: +proj=longlat +ellps=clrk66 +datum=NAD27 +no_defs

Without a +towgs84= or +datum=, it appears that the driver is choosing to 
omit an incomplete description.

Roger