baddstats/polyclip

Expose PointInPolygon and other helpers

thomasp85 opened this issue · 5 comments

While my own interest is mainly in PointInPolygon, there are other helpers which would be nice to have access to from R, such as Area, Poly2ContainsPoly1, and IntersectPoint

This has been put on the to-do list..

Perfect - thanks.

Do you have any idea of a time-frame (not being pushy - just out of interest)

PointInPolygon is now exposed (through new function pointinpolygon)

Uh-oh,..., Poly2ContainsPoly1 seems to be incorrect. The code tests whether every vertex of Poly1 lies inside Poly2 but this doesn't deal with cases where an edge of Poly1 crosses outside Poly2. I will investigate whether this has been fixed in later versions of Clipper, and update.

To avoid opening a new issue, may I request another extension of PointInPolygon, via vectorization of polygons to return a matrix of [npoints, npolygons] (or the other way around)?

I also concur with @thomasp85 that it would be helpful to expose other clipper fns, with my choice being to use area in an extension of the main ClipperLib::Clipper::Execute routine to calculate overlap areas? I suspect a great many people using the main polyclip routine would do so because they are interested in areas of overlap, and since the Clipper::Area function directly accepts the Paths object from the solution to the clip, it would be much more efficient if that could be extended within the C++ code, like this:

# set up layer1, layer2
areas <- polyclip_areas (layer1, layer2)
head (areas)
# area1   area2
# 1 456   123
# 2 ...

where area1 is just the area of the "subject polygon" (in AJ's terminology); area2 comes straight from the clipper solution in each instance; and the units can be directly re-scaled with your eps value, because clipper::Area returns a <double>.