Skip to content Skip to sidebar Skip to footer

Creating A Shape File From A Bounding Box Coordinates List

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

Solution 1:

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


defbbox(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')

Solution 2:

I want to enchance Bruno Carballo's code. I hope it will easier for you

import geopandas as gpd
    import pandas as pd
    from shapely.geometry import Polygon

    # function to return polygondefbbox(long0, lat0, lat1, long1):
        return Polygon([[long0, lat0],
                        [long1,lat0],
                        [long1,lat1],
                        [long0, lat1]])

    test = bbox(9.75, 9.75, 10.25, 10.25)

    gpd.GeoDataFrame(pd.DataFrame(['p1'], columns = ['geom']),
         crs = {'init':'epsg:4326'},
         geometry = [test]).to_file('poly.shp')

Post a Comment for "Creating A Shape File From A Bounding Box Coordinates List"