如何使用arcpy.da和InsertCursor添加不同的坐标

时间:2015-07-09 21:46:38

标签: python arcgis arcpy

我学习了arcpy,我陷入了一个简单的步骤。

我有一个Shapefile(点几何)。我添加了一个新行:

busStopsL1 = "C:/temp/geometries/Estacions_L1.shp"
xy = (6014912,2116582)
with arcpy.da.InsertCursor(busStopsL1,("SHAPE@XY")) as cursor:
    cursor.insertRow([xy])

然后,我尝试同时添加不同的坐标:

busStopsL1 = "C:/temp/geometries/Estacions_L1.shp"
arrayCoordenades = [(6015581,2115858),(6015939,2115574),(6016239,2114585)]
with arcpy.da.InsertCursor(busStopsL1,["SHAPE@XY"]) as cursor:
      for row in arrayCoordenades:
          cursor.insertRow(row)

它没有用。我一直在尝试不同的选择,但我无法找到同时添加这三个坐标的方法。我在ESRI帮助中看到了一些例子,它们同时在其他字段中添加坐标和信息,看起来它和我尝试的方式相同但是......

2 个答案:

答案 0 :(得分:1)

将元组传递到列表中,就像在第一个示例中一样。最初在这里回答:https://gis.stackexchange.com/a/131970/560

cursor.insertRow([row])

答案 1 :(得分:0)

import arcpy
fc = r'{feature class}'
fields = arcpy.ListFields(fc)
fieldsList = []
for field in fields:
    fieldsList.append(str(field.name))
query = {valid sql query}
with arcpy.da.SearchCursor(fc,fieldsList,where_clause=query) as searchCursor:
    for row in searchCursor:
        print (row)
        row[{insert tuple index of the x,y values}]
        newX = point[0] - 45
        newY = point[1] + 35
        newPoint = (newX,newY)
        t = row
        newRow = list(t)
        newRow[1] = newPoint
        t = tuple(newRow)
        insertCursor.insertRow(t)
del insertCursor