【问题标题】:Creating a shape file from a bounding box coordinates list从边界框坐标列表创建形状文件
【发布时间】:2019-06-24 23:39:17
【问题描述】:

关于这个主题的现有问题已经很少,但不幸的是我没有找到可以解决我的问题的东西。

我有一个点 Lat, Long 坐标,即 Lat= 10 和 Long = 10。我想在这个点周围创建一个 0.5 度边界框的形状文件,所以边界框应该如下:

  1. 最小多头 = 9.75
  2. 最小纬度 = 9.75
  3. 最大多头 = 10.25
  4. 最大纬度 = 10.25

有谁知道如何在 Python 中做到这一点?

【问题讨论】:

标签: python gis shapefile


【解决方案1】:

我想增强 Bruno Carballo 的代码。我希望这对你来说会更容易

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

    # function to return polygon
    def bbox(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')

【讨论】:

    【解决方案2】:

    这是使用 shapely、geopandas 和 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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      • 1970-01-01
      • 2021-12-25
      • 2013-08-28
      • 2021-02-02
      • 2015-08-08
      相关资源
      最近更新 更多