[GRASS-dev] [GRASS GIS] #2893: Specify crs when exporting to GeoJSON

GRASS GIS trac at osgeo.org
Wed Feb 3 04:37:09 PST 2016


#2893: Specify crs when exporting to GeoJSON
-------------------------+-------------------------
 Reporter:  pmav99       |      Owner:  grass-dev@…
     Type:  defect       |     Status:  new
 Priority:  normal       |  Milestone:
Component:  Default      |    Version:  unspecified
 Keywords:  v.out.ogr    |        CPU:  Unspecified
 Platform:  Unspecified  |
-------------------------+-------------------------
 If the information is available, `v.out.ogr` should probably specify the
 "crs" attribute when exporting to GeoJSON. `ogr2ogr` seems to support this
 feature.

 {{{
 $ pacman -Qs gdal
 local/gdal 2.0.1-6
     A translator library for raster geospatial data formats
 }}}

 A `GeoJSON` file with no `crs`:
 {{{
 $ cat sample.json
 {
     "type": "Polygon",
     "coordinates": [
         [
             [ -84.32281494140625, 34.9895035675793 ],
             [ -84.29122924804688, 35.21981940793435 ],
             [ -84.24041748046875, 35.25459097465022 ],
             [ -84.32281494140625, 34.9895035675793 ]
         ]
     ]
 }
 }}}

 Reprojecting:
 {{{
 $ ogr2ogr -f GeoJSON -t_srs "EPSG:3857" 3857.json sample.json

 $ ogr2ogr -f GeoJSON -t_srs "EPSG:4326" 4326.json sample.json
 }}}

 The new files:
 {{{
 $ cat 3857.json
 {
 "type": "FeatureCollection",
 "crs": { "type": "name", "properties": { "name":
 "urn:ogc:def:crs:EPSG::3857" } },

 "features": [
 { "type": "Feature", "properties": { }, "geometry": { "type": "Polygon",
 "coordinates": [ [ [ -9386772.821532785892487, 4162454.812297557480633 ],
 [ -9383256.718231666833162, 4193793.993894479703158 ], [
 -9377600.378138564527035, 4198533.089648159220815 ], [
 -9386772.821532785892487, 4162454.812297557480633 ] ] ] } }
 ]
 }
 }}}

 {{{
 $ cat 4326.json
 {
 "type": "FeatureCollection",
 "crs": { "type": "name", "properties": { "name":
 "urn:ogc:def:crs:OGC:1.3:CRS84" } },

 "features": [
 { "type": "Feature", "properties": { }, "geometry": { "type": "Polygon",
 "coordinates": [ [ [ -84.32281494140625, 34.989503567579298 ], [
 -84.291229248046875, 35.219819407934352 ], [ -84.24041748046875,
 35.25459097465022 ], [ -84.32281494140625, 34.989503567579298 ] ] ] } }
 ]
 }
 }}}

 By the way, when crs is not defined `ogrinfo` seems to default to
 `EPSG:4326` which I guess is the most reasonable choice, although I think
 I would prefer something more explicit (e.g. a warning):
 {{{
 $ ogrinfo -so -al sample.json

 ERROR 4: GeoJSON Driver doesn't support update.
 Had to open data source read-only.
 INFO: Open of `sample.json'
       using driver `GeoJSON' successful.
 Layer name: OGRGeoJSON
 Geometry: Polygon
 Feature Count: 1
 Extent: (-84.322815, 34.989504) - (-84.240417, 35.254591)
 Layer SRS WKT:
 GEOGCS["WGS 84",
     DATUM["WGS_1984",
         SPHEROID["WGS 84",6378137,298.257223563,
             AUTHORITY["EPSG","7030"]],
         AUTHORITY["EPSG","6326"]],
     PRIMEM["Greenwich",0,
         AUTHORITY["EPSG","8901"]],
     UNIT["degree",0.0174532925199433,
         AUTHORITY["EPSG","9122"]],
     AUTHORITY["EPSG","4326"]]
 }}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2893>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list