【问题标题】:Arcpy - Selecting Attribute and adding attributes to a feature classArcpy - 选择属性并将属性添加到要素类
【发布时间】:2014-05-14 22:36:12
【问题描述】:

我有一个 .gdb 和 1 个名为 waterlevelDifference 的要素类。有两列称为 Label(文本字段)和 Difference(双字段)。 Difference 列包含数字,而 Label 列为空并等待填充。

我想做的是从 Difference 中选择属性(例如 Difference > 0.30),然后填充 Label(例如 Label = "Greater than 0.30")基于在选择上。最初我打算使用 arcpy.SelectLayerByAttribute_management(选择属性),然后使用 arcpy.CalculateField_management(填充),但您不能使用 arcpy。 SelectLayerByAttribute_management 在要素类上。

我的问题是,我可以使用要素类选择和填充属性的其他方法是什么?

【问题讨论】:

    标签: selection populate arcpy


    【解决方案1】:

    最简单的方法是在 ArcMap 的字段计算器中使用 python 代码块,但是如果您想在脚本中执行此操作,我将创建一个 arcpy.UpdateCursor(),然后计算标记并逐行添加。

    feature_class = r"path\to\class"
    cursor = arcpy.UpdateCursor(feature_class)
    for row in cursor:
      label = ""
      difference = row.getValue('Difference')
      if difference == 0:
        label += "Label is 0"
      elif difference > 0.30:
        // ...
      row.setValue("Label", label)
      cursor.updateRow(row)
    

    【讨论】:

    • 这就像一种享受!非常感谢您的帮助!
    猜你喜欢
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    • 2013-09-09
    • 2023-03-04
    • 2015-08-30
    • 2013-09-02
    • 2014-12-18
    • 2010-09-23
    相关资源
    最近更新 更多