Skip to content

Commit

Permalink
OGRGeometry::exportToGEOS(): retain Z values for POLYHEDRALSURFACE Z …
Browse files Browse the repository at this point in the history
…/ TIN Z / GEOMETRYCOLLECTION Z of surfaces (master only)
  • Loading branch information
rouault committed Mar 16, 2024
1 parent 883f918 commit 507a09d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
22 changes: 22 additions & 0 deletions autotest/ogr/ogr_geos.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,3 +634,25 @@ def test_ogr_geos_set_precision():
g = ogr.CreateGeometryFromWkt("LINESTRING (1 1,9 9)")
g = g.SetPrecision(10)
assert g.ExportToWkt() == "LINESTRING (0 0,10 10)"


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


def test_ogr_geos_set_unary_union_TINZ():

g = ogr.CreateGeometryFromWkt("TIN Z (((0 0 10,0 1 10,1 1 10,0 0 10)))")
g = g.UnaryUnion()
assert g.ExportToIsoWkt() == "POLYGON Z ((0 0 10,0 1 10,1 1 10,0 0 10))"


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


def test_ogr_geos_set_unary_union_GEOMETRYCOLLECTIONZ_POLYGONZ():

g = ogr.CreateGeometryFromWkt(
"GEOMETRYCOLLECTION Z (POLYGON Z ((0 0 10,0 1 10,1 1 10,0 0 10)))"
)
g = g.UnaryUnion()
assert g.ExportToIsoWkt() == "POLYGON Z ((0 0 10,0 1 10,1 1 10,0 0 10))"
4 changes: 2 additions & 2 deletions autotest/utilities/test_ogr2ogr_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,10 +1248,10 @@ def test_ogr2ogr_lib_clipsrc_3d_polygon(tmp_vsimem):
assert lyr.GetFeatureCount() == 2

feat = lyr.GetNextFeature()
ogrtest.check_feature_geometry(feat, "LINESTRING (0 0, 5 5)")
ogrtest.check_feature_geometry(feat, "LINESTRING Z (0 0 0, 5 5 5)")

feat = lyr.GetNextFeature()
ogrtest.check_feature_geometry(feat, "LINESTRING (5 5, 10 0)")
ogrtest.check_feature_geometry(feat, "LINESTRING Z (5 5 5, 10 0 10)")

ds = None

Expand Down
20 changes: 15 additions & 5 deletions ogr/ogrgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3318,18 +3318,22 @@ OGRGeometry::exportToGEOS(UNUSED_IF_NO_GEOS GEOSContextHandle_t hGEOSCtxt) const
else if (eType == wkbPolyhedralSurface || eType == wkbTIN)
{
OGRGeometry *poGC = OGRGeometryFactory::forceTo(
poLinearGeom->clone(), wkbGeometryCollection, nullptr);
poLinearGeom->clone(),
OGR_GT_SetModifier(wkbGeometryCollection, poLinearGeom->Is3D(),
poLinearGeom->IsMeasured()),
nullptr);
hGeom = convertToGEOSGeom(hGEOSCtxt, poGC);
delete poGC;
}
else if (eType == wkbGeometryCollection)
{
bool bCanConvertToMultiPoly = true;
// bool bMustConvertToMultiPoly = true;
OGRGeometryCollection *poGC = poLinearGeom->toGeometryCollection();
const OGRGeometryCollection *poGC =
poLinearGeom->toGeometryCollection();
for (int iGeom = 0; iGeom < poGC->getNumGeometries(); iGeom++)
{
OGRwkbGeometryType eSubGeomType =
const OGRwkbGeometryType eSubGeomType =
wkbFlatten(poGC->getGeometryRef(iGeom)->getGeometryType());
if (eSubGeomType == wkbPolyhedralSurface || eSubGeomType == wkbTIN)
{
Expand All @@ -3345,9 +3349,15 @@ OGRGeometry::exportToGEOS(UNUSED_IF_NO_GEOS GEOSContextHandle_t hGEOSCtxt) const
if (bCanConvertToMultiPoly /* && bMustConvertToMultiPoly */)
{
OGRGeometry *poMultiPolygon = OGRGeometryFactory::forceTo(
poLinearGeom->clone(), wkbMultiPolygon, nullptr);
poLinearGeom->clone(),
OGR_GT_SetModifier(wkbMultiPolygon, poLinearGeom->Is3D(),
poLinearGeom->IsMeasured()),
nullptr);
OGRGeometry *poGCDest = OGRGeometryFactory::forceTo(
poMultiPolygon, wkbGeometryCollection, nullptr);
poMultiPolygon,
OGR_GT_SetModifier(wkbGeometryCollection, poLinearGeom->Is3D(),
poLinearGeom->IsMeasured()),
nullptr);
hGeom = convertToGEOSGeom(hGEOSCtxt, poGCDest);
delete poGCDest;
}
Expand Down

0 comments on commit 507a09d

Please sign in to comment.