-1

I am trying to remove my Z values from a points layer, and the Z Val field has already been field calc'd to 0, but when I select a point the z geometry is still populated with an integer > 0. I need to change the SHAPE@z to 0. The data set is a Utility Network, so a hosted feature layer, not a map image layer. From a few combinations of sources, I have this:

from arcgis.gis import GIS from arcgis.features import FeatureLayer gis = GIS("gis_portal_link", "username", "password") layer_url = "featureservice_url" layer = FeatureLayer(layer_url) with arcpy.da.UpdateCursor(geom, "SHAPE@Z") as cursor: for row in cursor: if row[0] == >0: row[0] = 0 cursor.updateRow(row) print(results) 
3
  • 1
    if row[0] == >0: should probably be if row[0] >0: Commented Nov 10 at 18:54
  • 4
    But are you trying to update the Z geometry, or a field called "Z Val"? Commented Nov 10 at 18:54
  • Was one of combination of sources AI? The code block has the content randomness found in AI generated code. If your code results in a syntax error, it's a Python question not a GIS one. Given the comparison error and the references to non-existent variables, this code isn't ready for review. Commented Nov 10 at 22:28

1 Answer 1

0

REPLACE Z VALUES

If a feature has an attribute called "Z Val", that is entirely independent of the feature's geometry. The geometry is not stored as a standard attribute. (A point geometry's coordinate can be copied to a standard attribute, but they remain as two independent values - updating one does not update the other).

If you want to update the geometry, you may want to use the SHAPE@Z token in the UpdateCursor instead of (or as well as) the Z Val field. See: https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/updatecursor-class.htm

with arcpy.da.UpdateCursor(geom, ["Z Val", "SHAPE@Z"]) as cursor: for row in cursor: row[0] = 0 row[1] = 0 cursor.updateRow(row) 

NB: This version excludes your if condition. If you want to leave negative numbers as-is without changing them to zero, then you would need to re-add the if condition. If you do add the if condition back in, don't run the updateRow() outside of the if. No point updating the row if nothing has changed.

(In datasets that I manage, I never store coordinates as an attribute, such as Z Val, as there is no guarantee that this is the true coordinate of the feature (geometry is stored separately). If my users want to see coordinates in a table, I create a copy of the feature class, use the 'Calculate Geometry Attributes' tool to add and populate coordinate fields to the copy, export the copy to a spreadsheet and then delete the copy. If this is something my users may want frequently, then I'll create a simple tool that does all this with the click of a button.)

REMOVE Z VALUES

If removing z values altogether (rather than setting them all to zero) is what you're after, then refer to ESRI's instructions at: https://support.esri.com/en-us/knowledge-base/how-to-remove-z-values-or-m-values-from-a-feature-layer-000026846

(In this case, you may also want to delete the 'Z Val' field).

3
  • In order to "remove Z values", a new feature class, without Z enabled, would need to be created. This just sets the Z values to zero (which is still a valid Z value) Commented Nov 10 at 22:38
  • Yes, that's true. It's unclear if that is what they want to do. I assumed they wanted to keep the (zero) Z values. Otherwise, they might have attempted to delete the "Z Val" field, rather than set it so zero. The title also says "replace" not "remove", although the body itself does say "remove". Commented Nov 10 at 22:39
  • Thanks for the advice, and it makes sense to use the shape@z. I already used the field calc for the field Z Val to zero out the z value. Also, the reasoning behind zeroing out the z value is to validate network topology connectivity rules in our UN and since the point feature class is Z and M enabled, I need to revert all lines, points, and polygons back to zero and then update based on the coordinate system and a DEM. We have very spotty z data, and it is also not the correct elevation. Commented Nov 10 at 23:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.