Area in KM from Polygon of coordinates
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
It looks like your coordinates are longitude and latitude, yes? Use Shapely's shapely.ops.transform
function to transform the polygon to projected equal area coordinates and then take the area.
python
import pyproj
from functools import partial
geom_aea = transform(
partial(
pyproj.transform,
pyproj.Proj(init='EPSG:4326'),
pyproj.Proj(
proj='aea',
lat1=geom.bounds[1],
lat2=geom.bounds[3])),
geom)
print(geom_aea.area)
# Output in m^2: 1083461.9234313113
The above answers seem to be correct, EXCEPT that at some point recently, the lat1 and lat2 parameters in the pyproj code were renamed with underscores: lat_1 and lat_2 (see https://stackoverflow.com/a/55259718/1538758). I don't have enough rep to comment, so I'm making a new answer (sorry not sorry)
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',
lat_1=geom.bounds[1],
lat_2=geom.bounds[3])),
geom)
# Print the area in m^2
print geom_area.area