遍历文件夹,读取边界,代码如下
import os
from osgeo import ogr
base = r"E:\shp" #文件夹路径
def findAllFile(base):
for root, ds, fs in os.walk(base):
for f in fs:
if f.endswith('.shp'):
fullname = os.path.join(root, f)
yield fullname
def main():
for shp in findAllFile(base):
inshp = shp
driver = ogr.GetDriverByName('ESRI Shapefile')
datasource = driver.Open(inshp, 0)
layer = datasource.GetLayer()
extent = layer.GetExtent()
print(shp+","+str(extent))
if __name__ == '__main__':
main()