Skip to content

Commit

Permalink
FlatGeoBuf: more explicit error message in case of feature geometry t…
Browse files Browse the repository at this point in the history
…ype != layer geometry type

Fixes OSGeo#9893
  • Loading branch information
rouault committed May 10, 2024
1 parent 09fed29 commit a2941e4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 18 additions & 0 deletions autotest/ogr/ogr_flatgeobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,3 +1401,21 @@ def test_ogr_flatgeobuf_write_arrow(tmp_vsimem):
"""
)


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


@gdaltest.enable_exceptions()
def test_ogr_flatgeobuf_write_mismatch_geom_type(tmp_vsimem):

filename = str(tmp_vsimem / "temp.fgb")
ds = ogr.GetDriverByName("FlatGeoBuf").CreateDataSource(filename)
lyr = ds.CreateLayer("src_lyr", geom_type=ogr.wkbPoint)
f = ogr.Feature(lyr.GetLayerDefn())
f.SetGeometry(ogr.CreateGeometryFromWkt("LINESTRING (1 2,3 4)"))
with pytest.raises(
Exception,
match="ICreateFeature: Mismatched geometry type. Feature geometry type is Line String, expected layer geometry type is Point",
):
lyr.CreateFeature(f)
6 changes: 5 additions & 1 deletion ogr/ogrsf_frmts/flatgeobuf/ogrflatgeobuflayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,11 @@ OGRErr OGRFlatGeobufLayer::ICreateFeature(OGRFeature *poNewFeature)
ogrGeometry->getGeometryType() != m_eGType)
{
CPLError(CE_Failure, CPLE_AppDefined,
"ICreateFeature: Mismatched geometry type");
"ICreateFeature: Mismatched geometry type. "
"Feature geometry type is %s, "
"expected layer geometry type is %s",
OGRGeometryTypeToName(ogrGeometry->getGeometryType()),
OGRGeometryTypeToName(m_eGType));
return OGRERR_FAILURE;
}

Expand Down

0 comments on commit a2941e4

Please sign in to comment.