GIS/ArcPy:从栅格中提取土地利用数据并将其分配给 shapefile 多边形

GIS/ArcPy: extracting land use data from a raster and assignig to shapefile polygons

同一区域我有两张地图 (1) 栅格土地利用图和 (2) 包含数千个子流域的 shapefile。我正在尝试根据多数规则将栅格(地图 1)中的土地利用类型分配给每个子流域(地图 2)。我尝试了空间连接,但结果似乎是错误的。在 ArcMap 中或通过 arcpy 执行此操作的最佳方法是什么?

我建议使用 Zonal Statistics as Table (Spatial Analyst) 来完成此任务。以下是一般工作流程:

  1. 运行 Zonal Statistics as Table 使用 "Majority" 统计。
  2. 使用 Join Field 将 table 与分水岭特征 class 相结合 (数据管理)

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')