我有两个相同区域的地图(1)栅格土地利用地图和(2)具有数千个子流域的shapefile。我试图根据多数规则将栅格(地图1)中的土地利用类型分配给每个子流域(地图2)。我试过空间连接,但结果似乎是错误的。在ArcMap中或通过arcpy执行此操作的最佳方法是什么?
答案 0 :(得分:0)
我建议使用Zonal Statistics as Table (Spatial Analyst)来完成此任务。以下是一般工作流程:
import arcpy, os
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
# Your watershed feature class
watersheds = r'C:\path\to\your\geodatabase.gdb\watersheds'
# Your land cover raster
raster = r'C:\path\to\your\landcover_raster.tif'
# The workspace where the output table will go
zone_table = r'C:\path\to\your\geodatabase.gdb'
# Perform the zonal statistics and output a table
arcpy.sa.ZonalStatisticsAsTable (watersheds, 'watershed_id', raster, zone_table, 'DATA', 'MAJORITY')
# Join the table to the watershed feature class by the OBJECTID field (for feature class)
arcpy.JoinField_management(watersheds, 'watershed_id', zone_table, 'OBJECTID', 'MAJORITY')