Despite it being an abomination in so many ways, Pseudo/Spherical (Web) Mercator is a projection after all, so basic math on the Cartesian plane applies:
import math
R = 6378137.0
def LL2SM(ll):
return [math.radians(ll[0]) * R, math.log(math.tan(math.pi / 4 + math.radians(ll[1]) / 2)) * R]
def SM2LL(xy):
return [math.degrees(xy[0] / R), math.degrees(2 * math.atan(math.exp(xy[1] / R)) - math.pi / 2.0)]
def VERTEX(cxy, a, r):
return [cxy[0] + r * math.cos(math.radians(a)), cxy[1] + r * math.sin(math.radians(a))]
def main():
vertices = 32
center = [13.0, 52.0]
radius = 100000
circle = []
_angle = 360.0/vertices
for vertex in range(0, vertices):
sm = LL2SM(center)
cv = VERTEX(sm, vertex*_angle, radius)
ll = SM2LL(cv)
circle.append(ll)
# do sth. with your circle
print(circle)
if __name__ == "__main__":
main()
This POC script
- transforms a pair of Longitude/Latitude (
center
) into EPSG:3857 coordinates (LL2SM()
)
- generates
vertices
amount of points on a circle with a given radius
(in meter) around center
, using its parametric equations (VERTEX()
)
- transforms each vertex' coordinates back to Longitude/Latitude (
SM2LL()
)
circle
will then hold coordinate arrays ([Longitude, Latitude]
) which, when transformed again to EPSG:3857, will form a circle around center
.
Obviously, you can skip transforming back to Longitude/Latitude if you want.
You haven't specified any software environment other than Python, so I leave translating this into the framework of your choice to you; this includes generating an actual Polygon, for which there likely are built-in functions.
Edit:
...
# do sth. with your circle
wkt_polygon = ''.join(['POLYGON((', ','.join([' '.join(map(str, ll)) for ll in circle + [circle[0]]]), '))'])
print(wkt_polygon)
will output a Polygon as valid Well Known Text representation.