1

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
4
  • 1
    Isnt the tool named arcpy.CreateFeatureclass_management, dont know if it matters. You are not calculating the "height_field". You are only using the values to set Z. Change cur = arcpy.da.InsertCursor(outputFC, ("SHAPE@XYZ")) to cur = arcpy.da.InsertCursor(outputFC, ["SHAPE@XYZ", "height_field"]) and modify insert_row row
    – BERA
    Nov 15, 2020 at 10:43
  • 1
    I think you should remove your try/except statements while testing because that can mask otherwise useful error messages.
    – PolyGeo
    Nov 15, 2020 at 11:26
  • I need the input values in order to shift the points to a new position
    – MoRu02
    Nov 15, 2020 at 12:06
  • @BERA I am not sure how to modify the insert_row. I get following message: TypeError: sequence size must match size of the row
    – MoRu02
    Nov 15, 2020 at 12:49

1 Answer 1

0

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]))
1
  • thank you Dan, it worked!
    – MoRu02
    Nov 16, 2020 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.