使用gdal获取全球地图中国家的边界框经纬度

    技术2022-05-19  20

    地图从http://thematicmapping.org/downloads/world_borders.php下载,使用vpn下载。

    确保安装好python和gdal

    import os

    os.chdir("Pah/to/thefile/world.shp")

    import osgeo.ogr

    shapefile = ogr.Open("world.shp")

    layer = shapefile.GetLayer(0)

    for i in range(layer.GetFeatureCount())

    feature = layer.GetFeature(i)

    countryName = feature.GetField("NAME")

    countryCode = feature.GetField("ISO3")

    geometry = feature.GetGeometryRef()

    minlong,maxlong,minLat,maxLat = geometry.GetEnvelope()

    print countryName,countryCode,minlong,maxlong,minLat,maxLat

     


    最新回复(0)