-1

有人可以告诉我如何在 ArcPy 中进行简单的字段计算,例如从“A”复制到“B”吗?我在网上找到了很多例子,它们都使用了额外的表达式,而且很复杂。我需要的是 ArcMap Gui 之类的东西:

B = !A!

更新:这是我到目前为止的代码,但我在运行时遇到错误

NameError:名称“A”未定义

point_shp = "G:\\Temp\\All_Provinces.shp"
arcpy.AddField_management(point_shp, "B", "TEXT", "", "", "25", "", "NON_NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(point_shp, "B", "A", "PYTHON_9.3")
4

3 回答 3

1

或者,如果您希望计算字段工具使用 VB 进行计算,那么您可以这样做:

arcpy.CalculateField_management(point_shp, "B","[A]")

那只是如果您有一个需要使用 Visual Basic 的应用程序。

于 2014-01-23T15:40:04.257 回答
0

Ok i got it, the A must be wrapped like "!A!"

arcpy.CalculateField_management(point_shp, "B","!A!", "PYTHON_9.3")

wow this forum is awesome! so many help!

于 2013-12-22T04:23:43.500 回答
0

我会通过使用更新游标来解决这个问题,尽管我不知道这是否满足您对简单性的需求。

point_shp = "G:\\Temp\\All_Provinces.shp" 
updateCursor = arcpy.UpdateCursor(point_shp)
for row in updateCursor:
    a = row.getValue("name of the "a" field name")
    b = a # --> any manipulations to b can also go here.. example b = a + c  etc... 
          # --> alternatively if you need to do string manipulations you can always make use of specifiers.  such that a = "!%s!" %(a) note:use %d if "a" is a number. This would produce a string "!a!" if you needed it in that format. 
    row.setValue("name of "b" field", b)
    updateCursor.update(row)

以上将允许您获取字段“A”的值,如果需要,对这些值执行某些操作并将其存储为 b。然后用 b 填充字段“B”。

注意:如果尚未创建字段 B,则需要这样做...

于 2015-12-18T19:24:03.347 回答