Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the overlapping area between two arbitrary polygons

I'm trying to create a method that will take in two arbitrary lists of nodes, for a subject and a clipping polygon, and output either:

a) the area of the overlap
b) a list of nodes for the resulting (clipped) polygon so that I can calculate the area

I've found lots of examples which clip an arbitrary polygon using a rectangular window (which is fairly standard in graphics) but that's not what I need. I understand that it's fairly complex, particularly when you get holes, convex polygons and the like. The only simplifying assumption which I can make is that the arbitrary polygons will not contain any holes.

I'm not at all an expert in this field, so would something like the Sutherland-Hodgman algorithm work? Are there any libraries out there which already do this, or is my best bet to simply implement the algorithm as described in pseudo-code on Wikipedia?

Thanks for the help!

like image 526
ahugenerd Avatar asked Nov 19 '10 21:11

ahugenerd


People also ask

How do you find the area of a overlapping polygon in ArcGIS?

The area of a polygon created in ArcGIS Pro can be determined in the attribute table of the polygon in the Shape_Area field. The area of the overlap between two or more polygon layers can also be determined with the Count Overlapping Features tool or the Clip tool.

How do you know if two polygons overlap?

To be able to decide whether two convex polygons are intersecting (touching each other) we can use the Separating Axis Theorem. Essentially: If two convex polygons are not intersecting, there exists a line that passes between them. Such a line only exists if one of the sides of one of the polygons forms such a line.

What is the overlapping area?

The OverlapArea function is a Spatial Numeric measurement that calculates the total area (or length or count) of overlap between features in the current layer and features in the target layer.


1 Answers

Are there any libraries out there which already do this ...

Polygon clipping is a complex task. I wouldn't recommend trying to do it yourself unless you want to spend many months on it. Wikipedia lists a number of clipping libraries (and IIRC in that list only Clipper is free for use in commercial applications): http://en.wikipedia.org/wiki/Boolean_operations_on_polygons#External_links

ps: I admit to a personal bias for Clipper since I'm the author :) More info here: http://angusj.com/delphi/clipper.php

like image 76
Angus Johnson Avatar answered Oct 08 '22 00:10

Angus Johnson