0

我正在尝试使用存储在 SQL Server Express 表中的值对栅格文件(表示植被和土地覆盖类型)进行重新分类。我在表中有一组约 400 个物种的记录,每一行代表一个不同的物种,每个植被类型都有一个列。如果每种植被类型适合该物种的栖息地,则将其编码为“1”,如果不适合,则将其编码为“0”。然后,植被栅格将根据与物种记录相关的值重新分类为两个值,“1”或“0”(每个物种的值会略有不同)。

在 PythonWin 中,我使用 pyodbc 连接到 SQL Server Express 数据库表,然后执行选择查询语句将物种记录(行)的值收集到 pyodbc 游标中。然后我想在 remap 语句中将每个列值分配给输出栅格值(参见附加代码)。不幸的是,我不断收到以下错误:

TypeError: list indices must be integers, not tuple

游标具有基于选择查询的 SQL Server Express 表中的所有值,我可以通过游标对象的row参数访问数据。所以 row.BIOME_X 变量肯定存储的是 1 或 0 值。或者我只是在用 Python 语法做一些愚蠢的事情。有任何想法吗?

谢谢!

# Load Python libraries          
import pyodbc
import arcpy
from arcpy import env
from arcpy.sa import *
import os
arcpy.env.overwriteOutput = 1

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

# set variables
modelList = arcpy.ListFiles() # build list of species model names for loop
biome_Cur = ("xxxxxxx/xxxx/xxxxxx/1_Input.gdb/biome_current") # the original raster which will be reclassed

# connect to SQL Server Express database
cnxn = pyodbc.connect('DRIVER={SQL Server Native Client 10.0};SERVER=DESKTOP\SQLEXPRESS;DATABASE=Species;UID=sa;PWD=XXXXXX')
cursor = cnxn.cursor()

# main processing loop
for model in modelList:

    # reclassifies biome raster based on suitability code from SQL Server Species database
    # select query
    cursor.execute("""
                SELECT [BIOME_1],[BIOME_6],[BIOME_7],[BIOME_8],[BIOME_9],[BIOME_10],[BIOME_14],[BIOME_19],[BIOME_20],
                [BIOME_21],[BIOME_22],[BIOME_23],[BIOME_24],[BIOME_25],[BIOME_27],[BIOME_29],[BIOME_30],[BIOME_31],
                [BIOME_32],[BIOME_35],[BIOME_36],[BIOME_37],[BIOME_38],[BIOME_39],[BIOME_40],[BIOME_41],[BIOME_42],
                [BIOME_43],[BIOME_44],[BIOME_45],[BIOME_46],[BIOME_47],[BIOME_48],[BIOME_50],[BIOME_100],[BIOME_200]
                FROM Species.dbo.BiomesPerSpp_Rehfeldt
                WHERE ID = ?""", (model))

    # assign remap variable for reclassification
    remap_cur = arcpy.sa.RemapValue([7, row.BIOME_7][8, row.BIOME_8],[9, row.BIOME_9],[14, row.BIOME_14],[20, row.BIOME_20],
    [21, row.BIOME_21], [22, row.BIOME_22], [23, row.BIOME_23], [25, row.BIOME_25], [30, row.BIOME_30],       
    [31,row.BIOME_31],[32, row.BIOME_32], [36, row.BIOME_36], [38, row.BIOME_38], [41, row.BIOME_41], 
    [42, row.BIOME_42], [43, row.BIOME_43],[44, row.BIOME_44], [45, row.BIOME_45], [46, row.BIOME_46], 
    [47, row.BIOME_47], [50, row.BIOME_50], [100, row.BIOME_100],[200, row.BIOME_200])

    biomeReClass_cur = arcpy.sa.Reclassify(biome_Cur, "Value", remap_cur, "NODATA")
4

1 回答 1

1

您在 RemapValue 下列出的 7 和 8 项之间遗漏了一个逗号。您还需要将整个列表列表括在括号内。

remap_cur = arcpy.sa.RemapValue([[7, row.BIOME_7],[8, row.BIOME_8]...[200, row.BIOME_200]])

有关更多信息,请参阅: http: //resources.arcgis.com/en/help/main/10.1/index.html#//005m0000007q000000

于 2012-10-15T17:18:17.880 回答