TransWikia.com

Updating Z values on points using UpdateCursor

Geographic Information Systems Asked by MoRu02 on July 14, 2021

I have created the following script, which moves the points from my_input_points_fc to my_output_points_fc by user input
Furthermore, the z-values in my_output_points_fc should also be updated. However, after executing the script I get zero values in the my_output_pointy_fc under the height_field.
What am I doing wrong?

import arcpy
arcpy.env.overwriteOutput = 1
arcpy.env.workspace = "my_path"
inputFC = "my_input_points_fc"
outputFC = "my_output_points_fc"
xValue = -1
yValue = -1
while xValue == -1:
    try:
        xOffset = input("Please enter the X coordinate by which the point should be move: ")
        xValue = float(xOffset)
    except Exception:
        print()
        print("The entry was not correct! Please try again")
while yValue == -1:
    try:
        yOffset = input("Please enter the Y coordinate by which the point should move ")
        yValue = float(yOffset)
    except Exception:
        print()
        print("The entry was not correct! Please try again")
spatialRef = arcpy.Describe(inputFC).spatialReference
arcpy.management.CreateFeatureclass(arcpy.env.workspace, outputFC, "POINT",inputFC, has_z = "ENABLED", spatial_reference= spatialRef)
cur = arcpy.da.InsertCursor(outputFC, ("SHAPE@XYZ"))
cur2 = arcpy.da.SearchCursor(inputFC, ("SHAPE@X", "SHAPE@Y", "height_field"))
for row in cur2:
    insert_row = (row[0] + xValue, row[1] + yValue, row[2])
    cur.insertRow([insert_row])
print ("Points have been moved")
del cur
del cur2
del row

One Answer

This should work if I correctly understand what you are trying to do:

with arcpy.da.InsertCursor(outputFC, ("SHAPE@X", "SHAPE@Y", "SHAPE@Z", "height_field")) as ic:
    with arcpy.da.SearchCursor(inputFC, ("SHAPE@X", "SHAPE@Y", "height_field")) as sc:
        for row in sc:
            ic.insertRow((row[0] + xValue, row[1] + yValue, row[2], row[2]))

Correct answer by Dan Jurgella on July 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP