Skip to content

Commit

Permalink
GEOSDensify: Interpolate Z coordinate (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimcn authored May 15, 2024
1 parent a32469b commit 7d9ebd7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/geos/geom/LineSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ class GEOS_DLL LineSegment {
{
ret = Coordinate(
p0.x + segmentLengthFraction * (p1.x - p0.x),
p0.y + segmentLengthFraction * (p1.y - p0.y));
p0.y + segmentLengthFraction * (p1.y - p0.y),
p0.z + segmentLengthFraction * (p1.z - p0.z));
};

/** \brief
Expand Down
38 changes: 37 additions & 1 deletion tests/unit/capi/GEOSDensifyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct test_capigeosdensify_data : public capitest::utility
result_ = GEOSDensify(input_, tolerance);
ensure("result not NULL", result_ != nullptr);

ensure_geometry_equals(result_, expected_);
ensure_geometry_equals_identical(result_, expected_);
ensure_equals("result SRID == expected SRID", GEOSGetSRID(result_), srid);
}
};
Expand Down Expand Up @@ -169,4 +169,40 @@ void object::test<10>()
result_ = GEOSDensify(input_, 0.1);
ensure("curved geometries not supported", result_ == nullptr);
}
// Densify a LINESTRING Z, check that Z gets interpolated
template <>
template <>
void object::test<11>()
{
testDensify(
"LINESTRING Z (0 0 0, 0 6 2)",
"LINESTRING Z (0 0 0, 0 3 1, 0 6 2)",
3.0
);
}

// Densify a LINEARRING Z
template <>
template <>
void object::test<12>()
{
testDensify(
"LINEARRING Z (0 0 0, 0 6 2, 6 6 12, 0 0 0)",
"LINEARRING Z (0 0 0, 0 3 1, 0 6 2, 3 6 7, 6 6 12, 4 4 8, 2 2 4, 0 0 0)",
3.0
);
}

// Densify a POLYGON Z
template <>
template <>
void object::test<13>()
{
testDensify(
"POLYGON Z ((0 0 0, 10 0 2, 10 10 10, 0 10 2, 0 0 0), (1 1 0, 1 7 0, 7 7 0, 7 1 0, 1 1 0))",
"POLYGON Z ((0 0 0, 5 0 1, 10 0 2, 10 5 6, 10 10 10, 5 10 6, 0 10 2, 0 5 1, 0 0 0), (1 1 0, 1 4 0, 1 7 0, 4 7 0, 7 7 0, 7 4 0, 7 1 0, 4 1 0, 1 1 0))",
5.0
);
}

} // namespace tut
14 changes: 14 additions & 0 deletions tests/unit/capi/capi_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ namespace capitest {
tut::ensure_equals("GEOSEqualsExact(g1, g2, tolerance)", rslt, 1);
}

void
ensure_geometry_equals_identical(GEOSGeometry* g1, GEOSGeometry* g2)
{
char rslt;
if (g1 == nullptr || g2 == nullptr) {
rslt = (g1 == nullptr && g2 == nullptr) ? 1 : 0;
}
else {
rslt = GEOSEqualsIdentical(g1, g2);
}
report_not_equal("ensure_equals_identical", g1, g2, 1e-12, rslt);
tut::ensure_equals("GEOSEqualsIdentical(g1, g2)", rslt, 1);
}

void
ensure_geometry_equals(GEOSGeometry* g1, GEOSGeometry* g2)
{
Expand Down

0 comments on commit 7d9ebd7

Please sign in to comment.