简体   繁体   中英

"Invalid projection" when calculating area of a polygon

I try to calculate the area of a polygon in km2 and projected in EPSG: 3857, but it doesn't recognize my crs

raise GeodError("Invalid geometry provided.")
pyproj.exceptions.GeodError: Invalid geometry provided.

should I use another one? is the function wrong?

def area(polygon):
        geod = Geod('EPSG: 3857')
        x, y = polygon.exterior.coords.xy
        area, perimeter = geod.geometry_area_perimeter(x,y)
        return area

Geodesic calculations expect geographic data. Here is an example for your data in WGS84/EPSG:4326:

https://pyproj4.github.io/pyproj/stable/examples.html#creating-geod-class

from pyproj import Geod, CRS
geod = Geod(ellps='WGS84')
# or
geod = CRS("EPSG:4326").get_geod()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM