Skip to content

Commit db4e1d0

Browse files
authored
Merge pull request OSGeo#12055 from rouault/fix_qgis_61266
GeoJSON: fix detection of features starting with {"geometry":{"type":"xxxxx","coordinates":[...
2 parents 40758a7 + d7a01fc commit db4e1d0

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

autotest/ogr/ogr_geojson.py

+31
Original file line numberDiff line numberDiff line change
@@ -3941,6 +3941,37 @@ def test_ogr_geojson_starting_with_geometry_coordinates(tmp_vsimem):
39413941
assert ds is not None
39423942

39433943

3944+
###############################################################################
3945+
# Test fix for https://github.com/qgis/QGIS/issues/61266
3946+
3947+
3948+
@pytest.mark.parametrize(
3949+
"start,end",
3950+
[
3951+
('{"type":"Point","coordinates":[', "2,49]}"),
3952+
('{"type":"LineString","coordinates":[[', "2,49],[3,50]]}"),
3953+
('{"type":"Polygon","coordinates":[[[', "0,0],[0,1],[1,1],[0,0]]]}"),
3954+
('{"type":"MultiPoint","coordinates":[[', "2,49]]}"),
3955+
('{"type":"MultiLineString","coordinates":[[[', "2,49],[3,50]]]}"),
3956+
('{"type":"MultiPolygon","coordinates":[[[[', "0,0],[0,1],[1,1],[0,0]]]]}"),
3957+
('{"type":"GeometryCollection","geometries":[', "]}"),
3958+
],
3959+
)
3960+
def test_ogr_geojson_starting_with_geometry_type(tmp_vsimem, start, end):
3961+
3962+
tmpfilename = tmp_vsimem / "temp.json"
3963+
gdal.FileFromMemBuffer(
3964+
tmpfilename,
3965+
'{ "geometry":'
3966+
+ start
3967+
+ (" " * 10000)
3968+
+ end
3969+
+ ', "type":"Feature","properties":{}}',
3970+
)
3971+
ds = gdal.OpenEx(tmpfilename, gdal.OF_VECTOR)
3972+
assert ds is not None
3973+
3974+
39443975
###############################################################################
39453976
# Test serialization of Float32 values
39463977

ogr/ogrsf_frmts/geojson/ogrgeojsonutils.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,24 @@ static bool IsGeoJSONLikeObject(const char *pszText, bool &bMightBeSequence,
247247
// See https://github.com/OSGeo/gdal/issues/2720
248248
if (osWithoutSpace.find("{\"coordinates\":[") == 0 ||
249249
// and https://github.com/OSGeo/gdal/issues/2787
250-
osWithoutSpace.find("{\"geometry\":{\"coordinates\":[") == 0)
250+
osWithoutSpace.find("{\"geometry\":{\"coordinates\":[") == 0 ||
251+
// and https://github.com/qgis/QGIS/issues/61266
252+
osWithoutSpace.find(
253+
"{\"geometry\":{\"type\":\"Point\",\"coordinates\":[") == 0 ||
254+
osWithoutSpace.find(
255+
"{\"geometry\":{\"type\":\"LineString\",\"coordinates\":[") == 0 ||
256+
osWithoutSpace.find(
257+
"{\"geometry\":{\"type\":\"Polygon\",\"coordinates\":[") == 0 ||
258+
osWithoutSpace.find(
259+
"{\"geometry\":{\"type\":\"MultiPoint\",\"coordinates\":[") == 0 ||
260+
osWithoutSpace.find(
261+
"{\"geometry\":{\"type\":\"MultiLineString\",\"coordinates\":[") ==
262+
0 ||
263+
osWithoutSpace.find(
264+
"{\"geometry\":{\"type\":\"MultiPolygon\",\"coordinates\":[") ==
265+
0 ||
266+
osWithoutSpace.find("{\"geometry\":{\"type\":\"GeometryCollection\","
267+
"\"geometries\":[") == 0)
251268
{
252269
return true;
253270
}

0 commit comments

Comments
 (0)