Skip to content

Commit

Permalink
GeoJSON writer: insert GDAL_RELEASE_NICKNAME
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Feb 20, 2025
1 parent b51894d commit 8cad056
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
23 changes: 16 additions & 7 deletions autotest/ogr/ogr_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -2110,6 +2110,19 @@ def test_ogr_geojson_54():
assert fld.GetType() == ogr.OFTString


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


def strip_gdal_release_nickname(content):

start = content.find('"_gdal_release_nickname_":')
if start < 0:
return content
end = content.find('",\n', start)
ret = content[0:start] + content[end + 3 :]
return ret


###############################################################################
# Test RFC 7946

Expand All @@ -2120,7 +2133,7 @@ def read_file(filename):
return None
content = gdal.VSIFReadL(1, 10000, f).decode("UTF-8")
gdal.VSIFCloseL(f)
return content
return strip_gdal_release_nickname(content)


def test_ogr_geojson_55(tmp_vsimem):
Expand Down Expand Up @@ -4921,9 +4934,7 @@ def test_ogr_geojson_foreign_members_collection(tmp_vsimem):
)
ds.Close()

fp = gdal.VSIFOpenL(filename, "rb")
data = gdal.VSIFReadL(1, 10000, fp).decode("ascii")
gdal.VSIFCloseL(fp)
data = read_file(filename)

assert """{\n"type": "FeatureCollection",\n"foo":"bar",\n"name": "test",""" in data

Expand Down Expand Up @@ -4970,9 +4981,7 @@ def test_ogr_geojson_foreign_members_feature(tmp_vsimem):
lyr.CreateFeature(ogr.Feature(lyr.GetLayerDefn()))
ds.Close()

fp = gdal.VSIFOpenL(filename, "rb")
data = gdal.VSIFReadL(1, 10000, fp).decode("ascii")
gdal.VSIFCloseL(fp)
data = read_file(filename)

assert (
"""{\n"type": "FeatureCollection",\n"name": "test",\n"features": [\n{ "type": "Feature", "properties": { }, "geometry": null, "foo":"bar"}\n]\n}"""
Expand Down
3 changes: 3 additions & 0 deletions ogr/ogrsf_frmts/geojson/ogrgeojsondatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ OGRGeoJSONDataSource::ICreateLayer(const char *pszNameIn,

VSIFPrintfL(fpOut_, "{\n\"type\": \"FeatureCollection\",\n");

VSIFPrintfL(fpOut_, "\"_gdal_release_nickname_\": \"%s\",\n",
GDALVersionInfo("RELEASE_NICKNAME"));

if (pszForeignMembersCollection)
{
VSIFWriteL(pszForeignMembersCollection + 1, 1,
Expand Down

0 comments on commit 8cad056

Please sign in to comment.