酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

利用pycharm写一个代码 读取data3文件夹中的dltb.shp(地类图斑图层)和image.tif(栅格影像图层) (1)dltb图层中有三个图斑要素,根据qsdw(权属性质)字段的不同,分别提取31(组集体)、32(村集体)、33(镇集体)的影像,提取出的影响名称分别为31、32、33

```python import rasterio import geopandas as gpd # 读取地类图斑图层 dltb = gpd.read_file('data3/dltb.shp') # 读取栅格影像图层 image = rasterio.open('data3/image.tif') # 根据权属性质字段的不同,分别提取31(组集体)、32(村集体)、33(镇集体)的影像 group_image = image.read(1)[dltb[dltb['qsdw'] == '31'].geometry.values] village_image = image.read(1)[dltb[dltb['qsdw'] == '32'].geometry.values] town_image = image.read(1)[dltb[dltb['qsdw'] == '33'].geometry.values] # 保存提取出的影像 with rasterio.open('data3/group_image.tif', 'w', image.profile) as dst: dst.write(group_image, 1) with rasterio.open('data3/village_image.tif', 'w', image.profile) as dst: dst.write(village_image, 1) with rasterio.open('data3/town_image.tif', 'w', image.profile) as dst: dst.write(town_image, 1) ``` [2024-06-30 05:32:46 | AI写代码神器 | 545点数解答]

相关提问