Skip to content

Commit

Permalink
OGRGeometryFactory::forceTo(): fix assertion with empty geometry and …
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Feb 1, 2024
1 parent d1868de commit d55c91b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
25 changes: 25 additions & 0 deletions autotest/ogr/ogr_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,31 @@ def test_ogr_factory_8():
ogrtest.check_feature_geometry(dst_geom, exp_wkt)


###############################################################################
# Test forceTo() to wkbUnknown


def test_ogr_factory_forceTo_unknown():

tests = [
(
"POINT (1 2)",
ogr.wkbUnknown,
"POINT (1 2)",
),
(
"POINT EMPTY",
ogr.wkbUnknown,
"POINT EMPTY",
),
]
for (src_wkt, target_type, exp_wkt) in tests:
src_geom = ogr.CreateGeometryFromWkt(src_wkt)
dst_geom = ogr.ForceTo(src_geom, target_type)

ogrtest.check_feature_geometry(dst_geom, exp_wkt)


###############################################################################
# Test forceTo()

Expand Down
8 changes: 4 additions & 4 deletions ogr/ogrgeometryfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4551,6 +4551,10 @@ OGRGeometry *OGRGeometryFactory::forceTo(OGRGeometry *poGeom,
if (poGeom == nullptr)
return poGeom;

const OGRwkbGeometryType eTargetTypeFlat = wkbFlatten(eTargetType);
if (eTargetTypeFlat == wkbUnknown)
return poGeom;

if (poGeom->IsEmpty())
{
OGRGeometry *poRet = createGeometry(eTargetType);
Expand All @@ -4564,10 +4568,6 @@ OGRGeometry *OGRGeometryFactory::forceTo(OGRGeometry *poGeom,
return poRet;
}

const OGRwkbGeometryType eTargetTypeFlat = wkbFlatten(eTargetType);
if (eTargetTypeFlat == wkbUnknown)
return poGeom;

OGRwkbGeometryType eType = poGeom->getGeometryType();
OGRwkbGeometryType eTypeFlat = wkbFlatten(eType);

Expand Down

0 comments on commit d55c91b

Please sign in to comment.