I have polygons from coordinates in (python shapely) that looks like this
POLYGON ((24.8085317 46.8512821, 24.7986952 46.8574619, 24.8088238 46.8664741, 24.8155239 46.8576335, 24.8085317 46.8512821))
I would like to calculate the area of this polygon in km^2. What would be the best way to do this in Python?
Answer
It wasn't readily apparent to me how to use @sgillies answer, so here is a more verbose version:
import pyproj
import shapely
import shapely.ops as ops
from shapely.geometry.polygon import Polygon
from functools import partial
geom = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
geom_area = ops.transform(
partial(
pyproj.transform,
pyproj.Proj(init='EPSG:4326'),
pyproj.Proj(
proj='aea',
lat1=geom.bounds[1],
lat2=geom.bounds[3])),
geom)
# Print the area in m^2
print geom_area.area
No comments:
Post a Comment