操作方法

操作方法:使用 Python 脚本将起始和结束 z 值添加到线要素

Last Published: April 25, 2020

摘要

无法直接将线要素的起始和结束高程作为属性值插入。 “插值 Shape”工具只能将 z 值添加到要素几何,而“添加表面信息”工具只能通过定义高程表面来添加要素的平均高程。 但是,通过合并“插值 Shape”工具和 Python 脚本,可以将起始和结束 z 值作为属性值添加到线要素。

过程

提供的说明描述了将起始和结束 z 值添加到线要素的方法。

  1. 运行插值 Shape 工具,将 z 值折点添加到所需的线要素。 在输入表面字段中输入高程数据,然后从输入要素类下拉列表中选择所需的线要素。

    The image of the Interpolate Shape tool.
     
  2. 打开新创建的线要素的属性表,并为起始和结束 z 值添加两个包含浮点型 双精度数据类型的新字段。 有关添加字段的详细信息,请参阅以下 Web 帮助文档 ArcGIS Desktop:添加字段

    Image of newly created Z fields.
     
  3. 通过 Python 控制台运行以下脚本(地理处理 > Python。)
     
    import arcpy
    
    #Specify the desired workspace.
    input_fc = r'\'
    
    #Modify this part according to the specified field names created in step 2.
    myfield1 = "Z_Start"
    myfield2 = "Z_End"
    myshape = "SHAPE@"
    
    #Iterate between rows available in the attribute table of the line feature and input the z-values.
    with arcpy.da.UpdateCursor(input_fc, (myshape, myfield1, myfield2)) as cursor:
    for row in cursor:
    geom = row[0]
    startpt = row[0].firstPoint
    endpt = row[0].lastPoint
    row[1] = round(startpt.Z, 2)
    row[2] = round(endpt.Z, 2)
    cursor.updateRow(row)

    The image of the sample script.
     
  4. 结果将填充在步骤 2 中创建的两个新字段中。

    Image of populated Z fields.

文章 ID:000014433

从 ArcGIS 专家处获得帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项

相关信息

发现关于本主题的更多内容