-
Notifications
You must be signed in to change notification settings - Fork 417
Add GEOSGeom_homogenize #1493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dbaston
wants to merge
2
commits into
libgeos:main
Choose a base branch
from
dbaston:homogenize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add GEOSGeom_homogenize #1493
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #include <tut/tut.hpp> | ||
| // geos | ||
| #include <geos_c.h> | ||
|
|
||
| #include "capi_test_utils.h" | ||
|
|
||
| namespace tut { | ||
| struct test_capigeosgeom_homogenize : public capitest::utility { | ||
|
|
||
| void testHomogenize(const std::string& wkt_in, const std::string& wkt_expected) { | ||
| GEOSGeometry* input = fromWKT(wkt_in.c_str()); | ||
| result_ = GEOSGeom_homogenize(input); | ||
| expected_ = fromWKT(wkt_expected.c_str()); | ||
|
|
||
| ensure_geometry_equals(result_, expected_); | ||
| } | ||
|
|
||
| void testHomogenizeUnchanged(const std::string& wkt) { | ||
| testHomogenize(wkt, wkt); | ||
| } | ||
| }; | ||
|
|
||
| typedef test_group<test_capigeosgeom_homogenize> group; | ||
| typedef group::object object; | ||
|
|
||
| group test_capigeosgeom_homogenize_group("capi::GEOSGeom_homogenize"); | ||
|
|
||
| template<> | ||
| template<> | ||
| void object::test<1>() | ||
| { | ||
| set_test_name("non-collection type"); | ||
|
|
||
| testHomogenizeUnchanged("LINESTRING (0 0, 1 1)"); | ||
| } | ||
|
|
||
| template<> | ||
| template<> | ||
| void object::test<2>() | ||
| { | ||
| set_test_name("non-homogeneous collection"); | ||
|
|
||
| testHomogenizeUnchanged("GEOMETRYCOLLECTION (LINESTRING (0 0, 1 1), POINT (2 2))"); | ||
| } | ||
|
|
||
| template<> | ||
| template<> | ||
| void object::test<3>() | ||
| { | ||
| set_test_name("single-element collection"); | ||
|
|
||
| testHomogenize("GEOMETRYCOLLECTION (POINT (0 2))", "POINT (0 2)"); | ||
| testHomogenize("MULTIPOINT ((8 2))", "POINT (8 2)"); | ||
| } | ||
|
|
||
| template<> | ||
| template<> | ||
| void object::test<4>() | ||
| { | ||
| set_test_name("homogeneous collection"); | ||
|
|
||
| testHomogenize("GEOMETRYCOLLECTION (LINESTRING (0 0, 1 1), LINESTRING (4 3, 2 7))", | ||
| "MULTILINESTRING ((0 0, 1 1), (4 3, 2 7))" ); | ||
| } | ||
|
|
||
| template<> | ||
| template<> | ||
| void object::test<5>() | ||
| { | ||
| set_test_name("empty collection"); | ||
|
|
||
| testHomogenizeUnchanged("GEOMETRYCOLLECTION EMPTY"); | ||
| } | ||
|
|
||
| template<> | ||
| template<> | ||
| void object::test<6>() | ||
| { | ||
| set_test_name("nested homogeneous collection"); | ||
|
|
||
| testHomogenize("GEOMETRYCOLLECTION (LINESTRING (0 0, 1 1), GEOMETRYCOLLECTION(LINESTRING EMPTY, MULTILINESTRING ((1 1, 2 2), (2 2, 3 3))))", | ||
| "MULTILINESTRING ((0 0, 1 1), (1 1, 2 2), (2 2, 3 3), EMPTY)"); | ||
| } | ||
|
|
||
| template<> | ||
| template<> | ||
| void object::test<7>() | ||
| { | ||
| set_test_name("nested non-homogeneous collection"); | ||
|
|
||
| testHomogenize("GEOMETRYCOLLECTION (LINESTRING (0 0, 1 1), GEOMETRYCOLLECTION(COMPOUNDCURVE ((1 1, 2 2))))", | ||
| "MULTICURVE (LINESTRING (0 0, 1 1), COMPOUNDCURVE ((1 1, 2 2)))"); | ||
| } | ||
|
|
||
| } // namespace tut | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the current logic is all collection specific, should the function be named accordingly? ie "GEOSGeom_homogenizeCollection"?
There's an argument to be made that generic homogenization should also do things like turn a multilinestring containing a single linestring to a linestring, or turning a curve polygon which only consists of linestring rings into a non-curved polygon, or a compound curve with only straight segments to a linestring, etc...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the function should be
GEOSGeom_simplifyStructure, and it should handle the curve->line cases you're describing.