Change Z coordinates of vertexes by UpdateCursor

1402
3
Jump to solution
11-04-2013 08:39 PM
YvoWeidmann
New Contributor II
Dear list

I try to set the Z values of all vertex of individual lines by a fixed value / attribute. All vertex of a single geometry are getting the same value. Somehow I tried to set the values through the geometry object I retrieve from the cursor. But the values are not written back to the geodatabase.
updateRows = arcpy.UpdateCursor(targetLayer)     for updateRow in updateRows:         shapeObj = updateRow.getValue(shapeFieldName)         # Multipart geometries.         for partObj in shapeObj:             for pointObj in partObj:                 # Only valid points.                 if (pointObj != None):                     # Setting the values of the z cooridnates to a fixed value.                     pointObj.Z = 9999       updateRow.setValue(shapeFieldName, shapeObj)     updateRows.updateRow(updateRow)


I don't understand why the changed geometries are not written to the database. What would be the correct way to do it?

I am looking forward to any hint and ideas.

Best regards,
Yvo
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor
Hi Yvo,

Try this:

import arcpy targetLayer = r'C:\Project\_Forums\multipart\test.gdb\myPolylineZ_multipart' shapeFieldName = 'SHAPE'  cursor = arcpy.UpdateCursor(targetLayer) for row in cursor:     geom = row.getValue(shapeFieldName)     geomArr = arcpy.Array()     for part in geom:         partArr = arcpy.Array()         for pnt in part:             if pnt != None:                 pntOut = arcpy.Point(pnt.X, pnt.Y, 9999)                 partArr.add(pntOut)          geomArr.add(partArr)      polyline = arcpy.Polyline(geomArr)     row.setValue(shapeFieldName, polyline)     cursor.updateRow(row)  del row del cursor


Kind regards,

Xander

View solution in original post

0 Kudos
3 Replies
XanderBakker
Esri Esteemed Contributor
Dear list

I try to set the Z values of all vertex of individual lines by a fixed value / attribute. All vertex of a single geometry are getting the same value. Somehow I tried to set the values through the geometry object I retrieve from the cursor. But the values are not written back to the geodatabase.
updateRows = arcpy.UpdateCursor(targetLayer)
    for updateRow in updateRows:
        shapeObj = updateRow.getValue(shapeFieldName)
        # Multipart geometries.
        for partObj in shapeObj:
            for pointObj in partObj:
                # Only valid points.
                if (pointObj != None):
                    # Setting the values of the z cooridnates to a fixed value.
                    pointObj.Z = 9999 

    updateRow.setValue(shapeFieldName, shapeObj)
    updateRows.updateRow(updateRow)


I don't understand why the changed geometries are not written to the database. What would be the correct way to do it?

I am looking forward to any hint and ideas.

Best regards,
Yvo


Hi Yvo,

The 3D Analyst extension comes with a tool to convert features to 3D by attribute: "Feature To 3D By Attribute (3D Analyst)".

If the featureclass you are updating isn't "Z-aware" you will not be able to write the Z-values to a feature. The alternative is to create a new featureclass through "Create Feature Class (Data Management)" and set the has_z to "ENABLED" and write your feature to the new feature class. Use a search cursor on your input features and an insert cursor on your output features.

Kind regards,

Xander
0 Kudos
XanderBakker
Esri Esteemed Contributor
Hi Yvo,

Try this:

import arcpy targetLayer = r'C:\Project\_Forums\multipart\test.gdb\myPolylineZ_multipart' shapeFieldName = 'SHAPE'  cursor = arcpy.UpdateCursor(targetLayer) for row in cursor:     geom = row.getValue(shapeFieldName)     geomArr = arcpy.Array()     for part in geom:         partArr = arcpy.Array()         for pnt in part:             if pnt != None:                 pntOut = arcpy.Point(pnt.X, pnt.Y, 9999)                 partArr.add(pntOut)          geomArr.add(partArr)      polyline = arcpy.Polyline(geomArr)     row.setValue(shapeFieldName, polyline)     cursor.updateRow(row)  del row del cursor


Kind regards,

Xander
0 Kudos
XanderBakker
Esri Esteemed Contributor
Hi Yvo,

If you think the answer was helpful you  can use the "arrow" button in order to help other  members find useful information:



More info here: http://resources.arcgis.com/en/help/forums-mvp/

Kind regards,

Xander
0 Kudos