mfogel / polygon-clipping

Apply boolean polygon clipping operations (union, intersection, difference, xor) to your Polygons & MultiPolygons.
MIT License
554 stars 64 forks source link

Feature request: provide a function to calculate the area of a (multi)polygon #131

Open Peque opened 2 years ago

Peque commented 2 years ago

In example:

const polygonClipping = require('polygon-clipping')

const polygon = [[[0,0],[2,0],[0,2],[0,0]]]
polygonClipping.area(polygon) == 2
const multi = [[[[0,0],[2,0],[0,2],[0,0]]], [[[2,2],[4,2],[2,4],[2,2]]]]
polygonClipping.area(multi) == 4
rowanwins commented 2 years ago

There are many other libraries already available which do this, for example @turf/area does it with geojson data or 2d-polygon-area.

Dylan190774 commented 2 months ago

I'd like to see this too. The 2d-polygon-area library is very old and doesn't work well with ES6 and Typescript.

I also can't figure out how to calculate the different parts of MultiPolygon, since the rings (holes) should not be counted of course.