Skip to content

Commit

Permalink
Merge pull request #10675 from rouault/geojsonseq_write_bbox
Browse files Browse the repository at this point in the history
GeoJSONSeq: add a WRITE_BBOX layer creation option
  • Loading branch information
rouault authored Sep 7, 2024
2 parents ec26a9d + c09a264 commit 24d6a82
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions autotest/ogr/ogr_geojsonseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,25 @@ def test_ogr_geojsonseq_force_opening(tmp_vsimem):

drv = gdal.IdentifyDriverEx("http://example.com", allowed_drivers=["GeoJSONSeq"])
assert drv.GetDescription() == "GeoJSONSeq"


###############################################################################
# Test WRITE_BBOX option


def test_ogr_geojsonseq_WRITE_BBOX(tmp_vsimem):

filename = str(tmp_vsimem / "test.geojsonl")
ds = gdal.GetDriverByName("GeoJSONSeq").Create(filename, 0, 0, 0, gdal.GDT_Unknown)
lyr = ds.CreateLayer("test", options=["WRITE_BBOX=YES"])
f = ogr.Feature(lyr.GetLayerDefn())
f.SetGeometry(ogr.CreateGeometryFromWkt("LINESTRING(2 49,3 50)"))
lyr.CreateFeature(f)
ds.Close()

f = gdal.VSIFOpenL(filename, "rb")
assert f
data = gdal.VSIFReadL(1, 10000, f)
gdal.VSIFCloseL(f)

assert b'"bbox": [ 2.0, 49.0, 3.0, 50.0 ]' in data
8 changes: 8 additions & 0 deletions doc/source/drivers/vector/geojsonseq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ The following layer creation options are supported:
if they start and end with brackets and braces, even if they do
not have their subtype set to JSON.

- .. lco:: WRITE_BBOX
:choices: YES, NO
:default: NO
:since: 3.10

Set to YES to write a bbox property with the bounding box of the
geometry at the feature level.

Geometry coordinate precision
-----------------------------

Expand Down
5 changes: 5 additions & 0 deletions ogr/ogrsf_frmts/geojson/ogrgeojsonseqdriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ OGRGeoJSONSeqLayer::OGRGeoJSONSeqLayer(
OGRSpatialReference::GetWGS84SRS());
m_poCT = std::move(poCT);

m_oWriteOptions.bWriteBBOX =
CPLTestBool(CSLFetchNameValueDef(papszOptions, "WRITE_BBOX", "FALSE"));
m_oWriteOptions.SetRFC7946Settings();
m_oWriteOptions.SetIDOptions(papszOptions);

Expand Down Expand Up @@ -1057,6 +1059,9 @@ void RegisterOGRGeoJSONSeq()
" <Value>String</Value>"
" <Value>Integer</Value>"
" </Option>"
" <Option name='WRITE_BBOX' type='boolean' description='whether to "
"write a bbox property with the bounding box of each geometry' "
"default='NO'/>"
"</LayerCreationOptionList>");

poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
Expand Down

0 comments on commit 24d6a82

Please sign in to comment.