golang / geo

S2 geometry library in Go
Apache License 2.0
1.69k stars 182 forks source link

Implement Polygon.Intersection #44

Open ctessum opened 6 years ago

ctessum commented 6 years ago

Since it seems acceptable to use this space to indicate interest in specific features, I would like to request polygon intersections. The Go language currently lacks a high quality library for boolean operations on geographic features, and having one would help me out greatly. (I am one of the maintainers of a low-to-medium quality library.) I greatly appreciate all the work that has happened so far to port this library to Go.

dsymonds commented 6 years ago

Yep, it is totally acceptable. ;-)

e7cfa0c added Polygon.Contains and Polygon.Intersects. To clarify, you're after the equivalent of C++'s S2Polygon::InitToIntersection?

ctessum commented 6 years ago

Yes, I mean the equivalent of S2Polygon::InitToIntersection. Thanks!

brendanashworth commented 5 years ago

I'm interested in contributing a PR for this — are there any thoughts on using Martinez-Rueda for the boolean operation algorithm? Or would it be best to port the C++ version accordingly?

ctessum commented 5 years ago

There is a port of (one of) the Martinez-Rueda algorithms here. However, that one is for planar geometry, not sure that it would work here?

brendanashworth commented 5 years ago

@ctessum I'm not sure myself. The projection onto a plane would conserve intersection points but not lengths.. is it naive to assume the lengths are proportional and thus area is conserved after we project back to the sphere?

alphairys commented 4 years ago

any update on this? Curious if anyone is actively working on this piece?

brendanashworth commented 4 years ago

@alphairys I don't have an update/I haven't been working on it. If you're looking for a workaround, I've been using CellUnions (after covering the polygon with cells) as a workaround, and they implement simple binary operations like CellUnionFromIntersection.

rsned commented 4 years ago

There is still work being done on this

ipipdotnet commented 2 years ago

I think someone has already done that https://github.com/davidreynolds/gos2/blob/master/s2/polygon_test.go