Skip to content
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

Add new CoverageEdgeExtractor class to extract unique edges from a polygonal coverage #1084

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nstrahl
Copy link

@nstrahl nstrahl commented Sep 29, 2024

Since CoverageValidator will only return the invalid edges of a coverage, it would be very convenient to be able to extract the valid edges of a coverage. This is what CoverageEdgeExtractor is for. The idea is to expose this functionality in the ports of JTS (e.g. in GEOS by adding a GEOSCoverageEdges funtion to the CAPI).

@dr-jts
Copy link
Contributor

dr-jts commented Sep 29, 2024

Yes, this functionality had occurred to me as well.

What is your use case for this?

Seems like it would also be nice to provide a reference back to the parent neighbour geometries for each edge (in some way - perhaps in the userData field). Would this be useful?

@nstrahl
Copy link
Author

nstrahl commented Oct 3, 2024

Yes, I had the exact same idea. Though I was shy to implement it since I was unsure whether it would be deemed necessary, or possible.

The extraction of ring edges is extremely useful because the caller can then manipulate these as desired and and then rebuild the coverage polygons from these.

I can add the change to the CoverageEdgeExtractor in this PR. Perhaps the user data can be the index of the parent polygon(s). From a GIS perspective, it would be useful to be able to add the feature ids of the parent polygons. Is there any way to retrieve the parent polygon indexes for any given CoverageEdge from the CoverageRingEdges class?

@dr-jts
Copy link
Contributor

dr-jts commented Oct 3, 2024

Perhaps the user data can be the index of the parent polygon(s). From a GIS perspective, it would be useful to be able to add the feature ids of the parent polygons.

Yes, that makes sense.

Is there any way to retrieve the parent polygon indexes for any given CoverageEdge from the CoverageRingEdges class?

Almost! Each CoverageEdge has the indexes of its neighbouring coverage geometries [here] (https://github.com/locationtech/jts/blob/master/modules/core/src/main/java/org/locationtech/jts/coverage/CoverageEdge.java#L131-L132). However, they currently aren't ordered to indicate which is left and which right. That will need to be done when the edge is created, here. The CoverageEdge.addIndex method needs to take a flag indicating which side of the edge the polygon ring lies. This can be determined by comparing the orientation of the point sequence in the CoverageEdge to the ring section which is matched to it.

@nstrahl
Copy link
Author

nstrahl commented Oct 19, 2024

The user data is now set. I ended up implementing the orientation logic inside the CoverageEdgeExtractor class to ensure zero-cost abstraction in the other coverage classes. (Only pay what you use for). I tried using the Orientation function for the checks but because the testHolesAndFillWithDifferentEndpoints test case failed using this approach (The coverage polygon was surrounding the edge) I ended up using a contains predicate with a (hopefully) sufficient precision model. Let me know if you think of a better/more elegant solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants