Select to view content in your preferred language

Creating 3D line from points with python

13023
10
Jump to solution
09-16-2014 09:29 AM
MartinSirkovsky
Occasional Contributor

Hi.

I have a series of points with X,Y,Z coordinates. I am trying to create a polylines from the points. Points should be vertexes of the polyline and Z-Coordinate should be used to define the elevation of vertexes.

I have created a script which works, but the Z-Coordinate is lost on vertexes and is recorded as ZERO. I am sure that my script is correct because if I pass the Z-Coordinate into the M value, it is recorded correctly. The part of the script which creates the line can be seen below:

vertexArray = arcpy.Array()

     for points in pointArray:

     xCoord = valueX

     yCoord = valueY

     zCoord = valueZ

         

     # valueZ is also passed to M dimension to test if there are some problems with values

     currentPoint = arcpy.Point(valueX, valueY, valueZ, valueZ)

     vertexArray.add(currentPoint)

newLineCursor = arcpy.da.InsertCursor(outputFc, ["SHAPE@"])

  polyline = arcpy.Polyline(vertexArray)

  newLineCursor.insertRow([polyline])

The script runs wihtout problems, and the polylines are created. But when I check in ArcMAP the polyline under sketch properties all the vertexes on line have null as Z-Coordinate (see image bellow).

edit sketch properties.jpg

I have just tested to convert points with arcpy.PointsToLine_management, and it works correctly. I could implement this in my script, but I am still curious as to why is Z-Coordinate not recorded properly with my script.

Thanks,

Martin

0 Kudos
10 Replies
DanielBean1
New Contributor

Michael Fells point is important, but be aware that there is some strange behavior in arcpy (as of 10.4.1)

polyline = arcpy.Polyline(line_array, sr, True)                      # This works
.. but this fails
polyline = arcpy.Polyline(line_array, spatial_reference=sr, has_z=True)    
If you supply the arguments by position it works, but if you use keyword args it fails.
0 Kudos