There is already few existing questions about this topic, but I unfortunately did not find something that could fix my problem.
I have a point Lat, Long coordinate i.e. Lat= 10 and Long = 10. I want to create a shape file of a 0.5 degree bounding box around this point, so the bounding box should be as follow:
Does anyone knows how to do that in Python?
Here's one way to do it using shapely, geopandas and pandas:
import geopandas as gpd
import pandas as pd
from shapely.geometry import Polygon
def bbox(lat,lng, margin):
return Polygon([[lng-margin, lat-margin],[lng-margin, lat+margin],
[lng+margin,lat+margin],[lng+margin,lat-margin]])
gpd.GeoDataFrame(pd.DataFrame(['p1'], columns = ['geom']),
crs = {'init':'epsg:4326'},
geometry = [bbox(10,10, 0.25)]).to_file('poly.shp')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With