Python 使用Arcpy变换特征

Python 使用Arcpy变换特征,python,arcpy,Python,Arcpy,我希望使用ArcPy移动一些几何特征。但是,每次运行脚本时,我都会收到以下错误消息。问题是什么 import arcpy def shift_features (in_features): ... with arcpy.da.UpdateCursor(in_features, ['SHAPE@XY','XShift',YShift']) as cursor: ... for row in cursor: ... cursor.updateRow([[

我希望使用ArcPy移动一些几何特征。但是,每次运行脚本时,我都会收到以下错误消息。问题是什么

import arcpy
def shift_features (in_features):  
...  with arcpy.da.UpdateCursor(in_features, ['SHAPE@XY','XShift',YShift']) as cursor:  
...       for row in cursor:  
...           cursor.updateRow([[row[0][0] + (row[1] or 0), 
...                              row[0][1] + (row[2] or 0)]])  
...  return
...     
然后我说:

shape=r'E:\Yael\All Sorts\Testing\MovingPolygon.shp'
shift_features(shape)
其中shape包含名为XShift、YShift的字段

我不断得到:

分析错误SyntaxError:扫描字符串文字时出现EOL


我猜你的代码是基于

调用cursor.updateRow时,需要向其传回一个参数:一个值列表,其长度与要处理的行列表长度相同。所以,举个例子

with arcpy.da.UpdateCursor(feature, ['FIELD', 'FOO', BAR']) as cursor:
    for row in cursor:
        print row                # prints a list of 3 values -- ['a', 'b', 'c']
        row[0] = 'd'             # changes element 0 of list
        print row                # ['d', 'b', 'c']
        cursor.updateRow(row)    # passes ['d', 'b', 'c']
我只更改了字段的值,还必须返回FOO和BAR的值。我还可以缩短它:

with arcpy.da.UpdateCursor(feature, ['FIELD', 'FOO', BAR']) as cursor:
    for row in cursor:
        cursor.updateRow(['d', 'b', 'c'])    # will work
但是在列表中传递较少的值是不起作用的:

with arcpy.da.UpdateCursor(feature, ['FIELD', 'FOO', BAR']) as cursor:
    for row in cursor:
        cursor.updateRow(['d'])    # will fail
如果我传递了太多的值,它同样会崩溃——列表中的元素数量需要与UpdateCursors调用的字段数量相匹配

因此,对于您的特定情况,您需要传回SHAPE@XY、XShift和YShift。现在,它只是SHAPE@XY这就是最初的代码片段配方所使用的全部内容

尝试:


你漏了一句话YShift@pbreach我已经添加了单引号,但是现在我收到了以下错误。运行时错误回溯最近的调用last:文件,第1行,在文件中,第6行,在shift\u功能类型错误:序列大小必须匹配行的大小
with arcpy.da.UpdateCursor(in_features, ['SHAPE@XY']) as cursor:
    for row in cursor:
        cursor.updateRow([[row[0][0] + (row[1] or 0),
                           row[0][1] + (row[2] or 0)]], row[1], row[2])