Introduction
In this document, we will discuss how to calculate the area of a specific region defined by a set of points with latitudes and longitudes using Python. This is a commonly used technique in various fields such as geography, geology, and remote sensing.
Define a geographical area by specifying its longitude and latitude coordinates
Before we dive into calculating the area, let's first understand what latitudes and longitudes are and how they help define a specific location on the Earth's surface. Latitudes and longitudes are imaginary lines that crisscross the globe, creating a grid-like structure. Latitudes run horizontally around the Earth while longitudes run vertically.
The combination of latitudes and longitudes allows us to pinpoint any location on the Earth's surface. This is extremely useful when calculating the area of a specific region as it helps define the boundaries of that region accurately.
Using Python, let's begin by defining a geographical area through the specification of its longitude and latitude coordinates:
coords = ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0) ) # point: (longitude,latitude)
Calculating Area using Python
There are various methods to calculate the area of a specific region with python
Using shapely and pyproj
from pyproj import Geodfrom shapely.geometry import Polygongeod = Geod(ellps="WGS84")coords = ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0) ) # point: (longitude,latitude)poly = Polygon(coords)area = abs(geod.geometry_area_perimeter(poly)[0])print('Area {:.3f} m^2'.format(area))print('Area {:.3f} km^2'.format(area/1000**2.0))
which returns
Area 12308778361.469 m^2Area 12308.778 km^2
Since our area is approximately a square, we can calculate the length of a side using the following formula
import numpy as npprint( np.sqrt(area) / 1000 )
gives
110.94493391529625
in km.This makes sense because approximately 1 degree corresponds to 111.1 km at the equator (see How big is a degree ?).
Using shapely transform function
import pyprojimport shapelyimport shapely.ops as opsfrom shapely.geometry.polygon import Polygonfrom functools import partialgeom = Polygon([(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.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)area_m2 = geom_area.area# Print the area in m^2print(area_m2)print( np.sqrt(area_m2) / 1000 )
returns
12308463846.396065110.9435164684988
Using wkt loads to get area of a specific region
from pyproj import Geodfrom shapely import wkt# specify a named ellipsoidgeod = Geod(ellps="WGS84")poly = wkt.loads('''\POLYGON ((0.0 0.0, 0.0 1.0, 1.0 1.0, 1.0 0.0, 0.0 0.0))''')area = abs(geod.geometry_area_perimeter(poly)[0])print('Area: {:.3f} m^2'.format(area))
returns
Area: 12308778361.469 m^2
References
| Links | Site |
|---|---|
| shapely.Polygon | shapely.readthedocs.io |
| geopandas.GeoSeries.area | geopandas.org |
| How big is a degree ? | sco.wisc.edu |
