Skip to content

Commit b10432b

Browse files
committed
OGRGeometryFactory::forceTo(): add a variant that takes and returns std::unique_ptr
1 parent 19d7aa3 commit b10432b

File tree

3 files changed

+172
-130
lines changed

3 files changed

+172
-130
lines changed

autotest/ogr/ogr_factory.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ def test_ogr_factory_7():
353353
# Test forceTo()
354354

355355

356-
def test_ogr_factory_8():
357-
358-
tests = [
356+
@pytest.mark.parametrize(
357+
"src_wkt,exp_wkt,target_type",
358+
[
359359
("POINT (2 5)", "POINT ZM (2 5 0 0)", ogr.wkbPointZM),
360360
("POINT ZM (2 5 3 4)", "POINT ZM (2 5 3 4)", ogr.wkbPointZM),
361361
("POINT ZM (2 5 3 4)", "MULTIPOINT ZM ((2 5 3 4))", ogr.wkbMultiPointZM),
@@ -866,23 +866,22 @@ def test_ogr_factory_8():
866866
ogr.wkbMultiCurve,
867867
),
868868
("MULTIPOINT (2 5)", "POINT(2 5)", ogr.wkbPoint),
869-
]
870-
for (src_wkt, exp_wkt, target_type) in tests:
869+
],
870+
)
871+
def test_ogr_factory_force_to(src_wkt, exp_wkt, target_type):
871872

872-
src_geom = ogr.CreateGeometryFromWkt(src_wkt)
873-
with gdal.config_option("OGR_ARC_STEPSIZE", "45"):
874-
dst_geom = ogr.ForceTo(src_geom, target_type)
875-
876-
if exp_wkt is None:
877-
exp_wkt = src_wkt
878-
elif (
879-
target_type != ogr.wkbUnknown and dst_geom.GetGeometryType() != target_type
880-
):
881-
print(target_type)
882-
print(dst_geom.ExportToIsoWkt())
883-
assert False, (src_wkt, exp_wkt, target_type)
873+
src_geom = ogr.CreateGeometryFromWkt(src_wkt)
874+
with gdal.config_option("OGR_ARC_STEPSIZE", "45"):
875+
dst_geom = ogr.ForceTo(src_geom, target_type)
884876

885-
ogrtest.check_feature_geometry(dst_geom, exp_wkt)
877+
if exp_wkt is None:
878+
exp_wkt = src_wkt
879+
elif target_type != ogr.wkbUnknown and dst_geom.GetGeometryType() != target_type:
880+
print(target_type)
881+
print(dst_geom.ExportToIsoWkt())
882+
assert False, (src_wkt, exp_wkt, target_type)
883+
884+
ogrtest.check_feature_geometry(dst_geom, exp_wkt)
886885

887886

888887
###############################################################################

ogr/ogr_geometry.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4265,6 +4265,10 @@ class CPL_DLL OGRGeometryFactory
42654265
OGRwkbGeometryType eTargetType,
42664266
const char *const *papszOptions = nullptr);
42674267

4268+
static std::unique_ptr<OGRGeometry>
4269+
forceTo(std::unique_ptr<OGRGeometry> poGeom, OGRwkbGeometryType eTargetType,
4270+
const char *const *papszOptions = nullptr);
4271+
42684272
static std::unique_ptr<OGRGeometry>
42694273
makeCompatibleWith(std::unique_ptr<OGRGeometry>,
42704274
OGRwkbGeometryType eTargetType);

0 commit comments

Comments
 (0)