Skip to content

Commit

Permalink
GeoJSON: parse '{"type": "GeometryCollection", "geometries": []}' as …
Browse files Browse the repository at this point in the history
…empty geometrycollection
  • Loading branch information
rouault committed Jul 3, 2018
1 parent 7cd9487 commit 6250a7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 12 additions & 0 deletions autotest/ogr/ogr_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -4148,6 +4148,17 @@ def ogr_geojson_append_flush():
###############################################################################


def ogr_geojson_empty_geometrycollection():

g = ogr.CreateGeometryFromJson('{"type": "GeometryCollection", "geometries": []}')
if g.ExportToWkt() != 'GEOMETRYCOLLECTION EMPTY':
print(g.ExportToWkt())
return 'fail'
return 'success'

###############################################################################


def ogr_geojson_cleanup():

gdal.SetConfigOption('CPL_CURL_ENABLE_VSIMEM', None)
Expand Down Expand Up @@ -4256,6 +4267,7 @@ def ogr_geojson_cleanup():
ogr_geojson_geom_export_failure,
ogr_geojson_starting_with_crs,
ogr_geojson_append_flush,
ogr_geojson_empty_geometrycollection,
ogr_geojson_cleanup]

if __name__ == '__main__':
Expand Down
9 changes: 3 additions & 6 deletions gdal/ogr/ogrsf_frmts/geojson/ogrgeojsonreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3122,13 +3122,10 @@ OGRGeometryCollection* OGRGeoJSONReadGeometryCollection( json_object* poObj,

if( json_type_array == json_object_get_type( poObjGeoms ) )
{
const int nGeoms = json_object_array_length( poObjGeoms );
if( nGeoms > 0 )
{
poCollection = new OGRGeometryCollection();
poCollection->assignSpatialReference(poSRS);
}
poCollection = new OGRGeometryCollection();
poCollection->assignSpatialReference(poSRS);

const int nGeoms = json_object_array_length( poObjGeoms );
for( int i = 0; i < nGeoms; ++i )
{
json_object* poObjGeom = json_object_array_get_idx( poObjGeoms, i );
Expand Down

0 comments on commit 6250a7e

Please sign in to comment.