Last active
November 20, 2022 14:38
-
-
Save deangrant/cc75a4bbd0ba7cbfbd85505c2200556c to your computer and use it in GitHub Desktop.
Returns coordinates of a polygon object for a center point and radius.
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
from functools import ( | |
partial | |
) | |
import pyproj | |
from shapely.geometry import ( | |
Point, | |
Polygon | |
) | |
from shapely.ops import ( | |
transform | |
) | |
def buffer( | |
longitude, | |
latitude, | |
radius | |
): | |
""" | |
Returns coordinates of a polygon object for a center point and radius. | |
Parameters | |
---------- | |
longitude: the longitude expressed as a positive or negative double value. | |
latitude: the latitude expressed as a positive or negative double value. | |
radius: the distance in meters from the center point. | |
Returns | |
------- | |
polygon: shapely.geometry.polygon.Polygon | |
""" | |
# Sets the azimuthal equidistant projection using latitude, longitude coordinates. | |
azimuthal_projection = f"+proj=aeqd +R=6371000 +units=m +lat_0={latitude} +lon_0={longitude}" | |
# Transform the azimuthal equidistant projection from WGS84 to AEQD. | |
wgs84_to_aeqd = partial( | |
pyproj.transform, | |
pyproj.Proj( | |
"+proj=longlat +datum=WGS84 +no_defs" | |
), | |
pyproj.Proj( | |
azimuthal_projection | |
), | |
) | |
# Transform the azimuthal equidistant projection from AEQD to WGS84. | |
aeqd_to_wgs84 = partial( | |
pyproj.transform, | |
pyproj.Proj( | |
azimuthal_projection | |
), | |
pyproj.Proj( | |
"+proj=longlat +datum=WGS84 +no_defs" | |
), | |
) | |
# Specifies the center point of the buffer using the longitude, latitude coordinates. | |
center = Point( | |
float( | |
longitude | |
), | |
float( | |
latitude | |
) | |
) | |
# Transforms the center point of the buffer using AEQD azimuthal equidistant projection. | |
point = transform( | |
wgs84_to_aeqd, | |
center | |
) | |
# Specifies the radius and computes a polygon that represents all points of the buffer. | |
point_buffer = point.buffer( | |
radius | |
) | |
# Transforms the polygon to WGS84 azimuthal equidistant projection. | |
polygon = transform( | |
aeqd_to_wgs84, | |
point_buffer | |
) | |
# Returns the coordinates of the polygon geometry. | |
return ( | |
polygon | |
) |
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
pyproj>=3.0.1 | |
shapely>=1.8.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment