Last active
August 19, 2022 15:54
-
-
Save thomas-maschler/267366a4b84d7858655d6179e917d22d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from math import pi, sqrt | |
def get_area(lat: float, d_lat: float, d_lng: float) -> float: | |
""" | |
Calculate geodesic area for lat/lng pixels using WGS 1984 as spatial reference. | |
Pixel area for a fix pixel width and hight various with latitude. | |
Pixels close to the equator have a larger areas. Area decreases towards the poles. | |
Arguments: | |
lat: Latitude of pixel | |
d_lat: pixel hight | |
d_lng: pixel width | |
Returns: | |
The geodesic area of the pixel in m2 | |
""" | |
a: float = 6378137.0 # Semi major axis of WGS 1984 ellipsoid | |
b: float = 6356752.314245179 # Semi minor axis of WGS 1984 ellipsoid | |
q: float = d_lng/360 | |
e: float = sqrt(1 - (b/a)**2) | |
area: float = abs( | |
(pi * b**2 * ( | |
2*np.arctanh(e*np.sin(np.radians(lat+d_lat))) / | |
(2*e) + | |
np.sin(np.radians(lat+d_lat)) / | |
((1 + e*np.sin(np.radians(lat+d_lat)))*(1 - e*np.sin(np.radians(lat+d_lat)))))) - | |
(pi * b**2 * ( | |
2*np.arctanh(e*np.sin(np.radians(lat))) / (2*e) + | |
np.sin(np.radians(lat)) / ((1 + e*np.sin(np.radians(lat)))*(1 - e*np.sin(np.radians(lat))))))) | |
* q | |
return area |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment