pyproj4 / pyproj

Python interface to PROJ (cartographic projections and coordinate transformations library)
https://pyproj4.github.io/pyproj
MIT License
1.02k stars 211 forks source link

Calculate area of arbitrary polygon on Earth's surface #1401

Open jonathan-geoseer opened 2 months ago

jonathan-geoseer commented 2 months ago

geometry_area_perimeter has limitations that means it cannot calculate the area of many polygons: https://pyproj4.github.io/pyproj/stable/api/geod.html#pyproj.Geod.geometry_area_perimeter

Suggestion: A method/function/class that allows calculation of the area of a polygon anywhere on the earth's surface (in m^2). Should scale up to global-coverage sized polygons.

This is a fairly commonly sought use-case: https://gis.stackexchange.com/questions/127607/calculating-area-in-km%C2%B2-for-polygon-in-wkt-using-python - I don't believe any of the answers on there work any more, so maybe this should be a bug (regression), rather than a feature request?

snowman2 commented 2 months ago

This is calculated using geod_polygonarea. This code originated from: https://geographiclib.sourceforge.io/. It is likely that your request would be best handled upstream.

snowman2 commented 2 months ago

I don't believe any of the answers on there work any more

What issues are you seeing?

jonathan-geoseer commented 1 month ago

What issues are you seeing?

Five of the answers use a combination of shapely.ops.transform, pyproj.transform, and partial - This is what I used to use, but upon upgrading the shapely version to 2.x, I was getting a lot of errors and the results were wrong. I assume something was deprecated, I forget the details.

Other option is geod = Geod(ellps="WGS84") - which doesn't work on 50% of shapes (see bug ticket this suggestion comes from).

https://pypi.org/project/area/ - this is what I'm now using.

snowman2 commented 1 month ago

upon upgrading the shapely version to 2.x, I was getting a lot of errors and the results were wrong

This upgrade guide should resolve your issues: https://shapely.readthedocs.io/en/stable/manual.html#shapely.ops.transform