Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeoJSON writer: insert GDAL_RELEASE_NICKNAME #11875

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading