Select to view content in your preferred language

Writing from/to Z values from fields

4988
12
Jump to solution
05-18-2014 04:01 PM
MikeLouwrens
Frequent Contributor
Hi all,

I have some Z-enabled lines that have no values currently set in the Z property, however I have FromLevel and ToLevel fields as attributes in the feature class.  I'd like to have a script that loops through all my lines and populates the Start Vertex with the value in the "FromLevel" field, and the End Vertex with the value in the "ToLevel" field.  Is this possible?  I started playing around with an UpdateCursor as I thought this would be the quickest/easiest way to get it done, but am unsure how to write to the Z property through the UpdateCursor.

I'm using ArcGIS Desktop 10.2.2

import arcpy, sys, string, os, fpformat  mxd = arcpy.mapping.MapDocument("CURRENT")  layers = arcpy.mapping.ListLayers(mxd)  for layer in layers:    if layer.name == "3dLine":     layerexists = 1          fields = ["SHAPE@Z","FromLevel","ToLevel"]      if layerexists == 1:       strLineFC = "3dLine"          lineRows = arcpy.da.UpdateCursor(strLineFC, fields)          lineRow = lineRows.next()          while lineRow:           linePointsArray = lineRow.Shape.getPart(0)           pt_count = linePointsArray.count           pt_begin = linePointsArray.next() # First Vertex on line            row[0] = row[1]           vertices = 2            while vertices < pt_count:             pt_end = linePointsArray.next()             vertices = vertices + 1                      pt_end = linePointsArray.next() # Last Vertex on line           row[0] = row[2]


This tells me there is no Shape property to get the vertex info from... (this script was butchered from another similar script, however that script writes to an attribute, not the Z property, and uses arcpy.updatecursor not arcpy.da.updatecursor.  Can I write to the Z property through the arcpy.updatecursor?

I'd appreciate any tips/suggestions to allow me to do this.

Cheers,
Mike.
Tags (2)
0 Kudos
12 Replies
MikeLouwrens
Frequent Contributor
Interpolating Z values should be done with caution.
Thanks for your caution.  The datasets I am working with are sewer pipes, so they don't have a direct relation to the actual terrain (other than being below the terrain elevation).  Interpolation in this situation should work for most of the lines where required I think 🙂

Cheers,
Mike.
0 Kudos
MikeLouwrens
Frequent Contributor
If the data comes as shapefiles there are no true curves.  True curves would only be created and preserved in a geodatabase.  But it is a potential gotcha if you ever do work with geodatabase true curves.
Most of our third party data comes from AutoCAD DWG file, which I think does also allow for curves.  We shouldn't have many/any though.

Cheers,
Mike.
0 Kudos
RichardFairhurst
MVP Alum
Thanks for your caution.  The datasets I am working with are sewer pipes, so they don't have a direct relation to the actual terrain (other than being below the terrain elevation).  Interpolation in this situation should work for most of the lines where required I think 🙂

Cheers,
Mike.


For pipeline data I agree that interpolation will more than likely work, since line breaks are probably being made where changes related to gravity flow occur.
0 Kudos