From 110451d6d60a39ecdf6027f13a26fb5449a6f179 Mon Sep 17 00:00:00 2001 From: Al Date: Wed, 28 Oct 2015 21:19:35 -0400 Subject: [PATCH] [polygons] Polygon area calculations --- scripts/geodata/polygons/area.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 scripts/geodata/polygons/area.py diff --git a/scripts/geodata/polygons/area.py b/scripts/geodata/polygons/area.py new file mode 100644 index 00000000..460ba614 --- /dev/null +++ b/scripts/geodata/polygons/area.py @@ -0,0 +1,26 @@ +import pyproj + +from functools import partial +from shapely.ops import transform +from shapely.geometry import Polygon + + +def polygon_area(poly): + return transform( + partial(pyproj.transform, + pyproj.Proj(init='EPSG:4326'), + pyproj.Proj(proj='aea', + lat1=poly.bounds[1], + lat2=poly.bounds[2], + ) + ), + poly + ).area + + +def polygon_bounding_box_area(poly): + bbox = poly.bounds + p = Polygon([(bbox[0], bbox[3]), (bbox[0], bbox[1]), + (bbox[2], bbox[1]), (bbox[2], bbox[3]), + ]) + return polygon_area(p)