基於面要素醃膜提取柵格並生成各自的柵格檔案
阿新 • • 發佈:2018-12-14
需求:
根據向量面圖層,醃膜提取柵格,同時基於面要素去生成各自的柵格檔案
資料:
結果:
程式碼:
# 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,則執行程式碼時報下列問題: