基于面要素腌膜提取栅格并生成各自的栅格文件

需求:

根据矢量面图层,腌膜提取栅格,同时基于面要素去生成各自的栅格文件

数据:

结果:

代码:

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "E:\\tttt"
path="E:\\tttt\\tt"
# Set local variables
inRaster = "090160.tif"
inMaskData = "mask.shp"

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

cursor = arcpy.SearchCursor(inMaskData)

for row in cursor:
    mask = row.getValue("Shape")
    code = row.getValue("COUNTRY_NA")  # name the output layer by COUNTRY_NA field
    outExtractByMask = ExtractByMask(inRaster,mask)
    outExtractByMask.save(path + "\\" +code + ".tif")

注意:

如果矢量面图层的COUNTRY_NA字段有重复的属性值,例如:两条记录的值是A,则运行代码时报下列问题:

转载自:https://blog.csdn.net/gislaozhang/article/details/82971703

You may also like...