2

I would like to find a way to edit shapefile (polyline) coordinate data using python. Basically, I want to edit all the z-coordinates in my shapefile so that they are 1 metre lower than they previously were.

I noticed that coordinate data can be manipulated en masse in the Esri Python tutorial video (https://www.youtube.com/watch?v=ge_U_w0PcFM, at 18:17 for anyone thats interested). They use a function within the field calculator to move all the x coordinates +5000m. I have reproduced the script below:

def shiftXCoord(Shape)
  point = shape.getpart(0)
  point.X  point.X + 5000
  return point
shiftXCoord(!Shape!)

I am experiencing two main problems using this script as a solution to my problem. (1) The commentators do not go into any great detail about what particular parts of the script mean/are used for. I know the above is a function but I do not know what lines 2 and 3 represent. (2) Also, without the field calculator I am unsure as to how to link this to the shapefile I am working on.

I am using ArcGIS Desktop 10.0.

2

Complete edit: After watching the video.
The section you got the solution from was to run python from the field calculator.
field calc

  1. open the attribute table of your shapefile.
  2. right click on the shape field.
  3. select field calculator.
  4. choose the python radio button at the top.
  5. select the show codeblock checkbox.
  6. paste the first part of your code into the pre-logic script code area.
  7. paste the results code into the results area (it says Shape =).
    Paste
    BTW I tested this and it works...

    def shiftXCoordinate(shape):
    shiftValue = 12000
    point = shape.getPart(0)
    point.X += shiftValue
    return point

1

Have you tried the out-of-the-box solution Adjust 3D Z (Data Management)?

import arcpy
arcpy.CheckOutExtension("3D")

shp = r"C:\data\yourSHP.shp"
arcpy.Adjust3DZ_management(shp, "NO_REVERSE", -1, "METERS", "METERS")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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