How do I create a square polygon using center of the point (lat/lon) 25 kilometers (KM) by sides?
I am not looking for a radius i.e. buffer. Here I am creating edges of 25 KM from the center point my_lat
and my_lon
. I may be coming close to it, yet I don't know enough GeoPandas functions that can calculate the square/rectangle polygons. Any suggestions?
I have provided a picture below for a better understanding of the questions. Black lines are currently 35 KM apart.
import geopy
import geopy.distance as distance
import plotly.graph_objects as go
from haversine import haversine, Unit
from shapely.geometry import Polygon
# Each side is 25KM appart
d = distance.distance(kilometers=25) # 25 KM
print(d)
# Going clockwise, from lower-left to upper-left, upper-right...
my_lat = 38.696211
my_lon = -120.5
center_point = geopy.Point((my_lat,my_lon))
p2 = d.destination(point=center_point, bearing=45)
p3 = d.destination(point=center_point, bearing=135)
p4 = d.destination(point=center_point, bearing=-135)
p5 = d.destination(point=center_point, bearing=-45)
# print('p2','-->',p2)
# print('p3','-->',p3)
# print('p4','-->',p4)
# print('p5','-->',p5)
points = [(p.latitude, p.longitude) for p in [p2,p3,p4,p5]]
polygon = Polygon(points)[![enter image description here][1]][1]