Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#5922 closed defect (fixed)

CreateGeometryFromJson() not setting SRS

Reported by: warmerdam Owned by: Even Rouault
Priority: normal Milestone: 2.0.0
Component: OGR_SF Version: unspecified
Severity: normal Keywords: geojson


In the following code sequence, creating a geometry from GeoJson? does not set the spatial reference (the first print is None), and so the TransformTo?() operator does not work since it is not apparent that the geometry is WGS84. I think GeoJSON geometry creators likely ought to set a spatial reference on the geometry though this may mean careful management of a WGS84 OGRSpatialReference with reference counting to avoid creating whole OGRSpatialReference objects for each geojson geometry operation. This may also cause problems if people are abusing GeoJSON to transform non-WGS84 geometries.

    fp_ogr = ogr.CreateGeometryFromJson(geojson_fp)
    print fp_ogr.GetSpatialReference()
    # Use Cylindrical Equal Area for stable global area calculations.
    cea_srs = osr.SpatialReference()
    cea_srs.SetFromUserInput('+proj=cea +datum=WGS84')

    cea_ogr = fp_ogr.TransformTo(cea_srs)

    print fp_ogr
    print cea_ogr

Change History (2)

comment:1 Changed 7 years ago by Even Rouault

Milestone: 2.0
Resolution: fixed
Status: newclosed

trunk r28898 "OGR_G_CreateGeometryFromJson(): attach a WGS84 SRS to the returned geometry if the json object has no 'crs' member (#5922)"

I contemplated at first using a global static instanciation of a OGRSpatialReference object, but from fear of subtle issues due to the "static initialization order fiasco" (, I ended up using a global OGRSpatialReference* object whose initialization is protected by a mutex.

comment:2 Changed 6 years ago by Even Rouault


Milestone renamed

Note: See TracTickets for help on using tickets.