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

Point in polygon check failing #96

Open
asinghvi17 opened this issue Apr 4, 2024 · 6 comments
Open

Point in polygon check failing #96

asinghvi17 opened this issue Apr 4, 2024 · 6 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@asinghvi17
Copy link
Member

asinghvi17 commented Apr 4, 2024

For a polygon with multiple holes, the point in polygon check seems to be failing.

import GeometryOps as GO, GeoInterface as GI
using GeometryBasics

rings = [[Point2f.(r*cos(θ), r*sin(θ)) for θ in LinRange(0, 2π, 90)] for r in 5:-1:1]
p = GI.Polygon(rings)
poly(p)

iTerm2 LexrsA

xmin, ymin = minimum(ax.finallimits[])
xmax, ymax = maximum(ax.finallimits[])
points = [Point2f(x, y) for x in LinRange(xmin, xmax, 500), y in LinRange(ymin, ymax, 500)]
f, a, p = heatmap(xmin..xmax, ymin..ymax, GeometryOps.within.(points, (p,)))
poly!(a, p; alpha = 0.6)
f

iTerm2 waAFrF

@asinghvi17 asinghvi17 added bug Something isn't working help wanted Extra attention is needed labels Apr 6, 2024
@rafaqz
Copy link
Member

rafaqz commented Apr 6, 2024

This isn't just "mutiple holes" its holes inside polygons inside holes! I don't know if anyone handles this?

@asinghvi17
Copy link
Member Author

It's an example in the Hao-Sun paper

@asinghvi17
Copy link
Member Author

Also earcut and Cairo, since Makie can display it

@skygering
Copy link
Collaborator

Is this a valid polygon though? Everything post the first ring is supposed to be a hole. So really this should be "validated" and split into three polygons, the first two each having holes and the last being a circle... Thoughts @asinghvi17? Do we still want it to work for this or should the polygon just be validated (once we have that functionality 😢 ).

@asinghvi17
Copy link
Member Author

Hmm that's a good point. By the even odd rule it should look like the first plot...let me check what the databases define this as first!

@asinghvi17
Copy link
Member Author

So to go back full circle (haha) it looks like this is an invalid polygon by a conservative reading of GIS standards. We could warn or error if necessary, but we should have a fix that lifts these up to become multipolygons!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants