Skip to main content
added 108 characters in body
Source Link
Ram
  • 111
  • 1
  • 1
  • 9

I am trying to update Z values of the vertices of the polygon shape. The script bellow works for polygons without multiparts and donuts. If I run this script for polygon shape that contains multiparts and donuts, I get error. How can I make it work?

My script:

import arcpy

fc = r"C:\Scratch\fcTest.shp"

# Get Spatial Reference of dataset
desc = arcpy.Describe(fc)
sr = desc.spatialReference

with arcpy.da.UpdateCursor(fc, ["SHAPE@"]) as cursor:
    for row in cursor:

        # Get Geometry
        geom = row[0]

        # Create an empty array object
        arr = arcpy.Array()

        # Read points, if Z is found to be zero reset it to 1
        for part in geom:
            for pnt in part:
                if not pnt:
                    arr.add(None)
                    continue

                if pnt.Z == 0:
                    pnt.Z = 1.0

                 # Add updated point to Array
                arr.add(pnt)

        # Construct new polygon geometry from array whilst setting spatial reference and indicating it has Z
        newpoly = arcpy.Polygon(arr,sr,True)

        #Update row
        cursor.updateRow([newpoly])

Error:

 Traceback (most recent call last):
 File "C:\Scratch\fcTest.py", line 21, in <module>
    if pnt.Z == 0:
  AttributeError: 'NoneType' object has no attribute 'Z'
   >>> 

I am trying to update Z values of the vertices of the polygon shape. The script bellow works for polygons without multiparts and donuts. If I run this script for polygon shape that contains multiparts and donuts, I get error. How can I make it work?

My script:

import arcpy

fc = r"C:\Scratch\fcTest.shp"

# Get Spatial Reference of dataset
desc = arcpy.Describe(fc)
sr = desc.spatialReference

with arcpy.da.UpdateCursor(fc, ["SHAPE@"]) as cursor:
    for row in cursor:

        # Get Geometry
        geom = row[0]

        # Create an empty array object
        arr = arcpy.Array()

        # Read points, if Z is found to be zero reset it to 1
        for part in geom:
            for pnt in part:
                if pnt.Z == 0:
                    pnt.Z = 1.0

                 # Add updated point to Array
                arr.add(pnt)

        # Construct new polygon geometry from array whilst setting spatial reference and indicating it has Z
        newpoly = arcpy.Polygon(arr,sr,True)

        #Update row
        cursor.updateRow([newpoly])

Error:

 Traceback (most recent call last):
 File "C:\Scratch\fcTest.py", line 21, in <module>
    if pnt.Z == 0:
  AttributeError: 'NoneType' object has no attribute 'Z'
   >>> 

I am trying to update Z values of the vertices of the polygon shape. The script bellow works for polygons without multiparts and donuts. If I run this script for polygon shape that contains multiparts and donuts, I get error. How can I make it work?

My script:

import arcpy

fc = r"C:\Scratch\fcTest.shp"

# Get Spatial Reference of dataset
desc = arcpy.Describe(fc)
sr = desc.spatialReference

with arcpy.da.UpdateCursor(fc, ["SHAPE@"]) as cursor:
    for row in cursor:

        # Get Geometry
        geom = row[0]

        # Create an empty array object
        arr = arcpy.Array()

        # Read points, if Z is found to be zero reset it to 1
        for part in geom:
            for pnt in part:
                if not pnt:
                    arr.add(None)
                    continue

                if pnt.Z == 0:
                    pnt.Z = 1.0

                 # Add updated point to Array
                arr.add(pnt)

        # Construct new polygon geometry from array whilst setting spatial reference and indicating it has Z
        newpoly = arcpy.Polygon(arr,sr,True)

        #Update row
        cursor.updateRow([newpoly])

Error:

 Traceback (most recent call last):
 File "C:\Scratch\fcTest.py", line 21, in <module>
    if pnt.Z == 0:
  AttributeError: 'NoneType' object has no attribute 'Z'
   >>> 
deleted 4 characters in body
Source Link
Ram
  • 111
  • 1
  • 1
  • 9

I am trying to update Z values of the vertices of the polygon shape. The script bellow works for polygons without multiparts and donuts. If I run this script for polygon shape that contains multiparts and donuts, I get error. How can I make it work?

My script:

import arcpy

fc = r"C:\Scratch\fcTest.shp"

# Get Spatial Reference of dataset
desc = arcpy.Describe(fc)
sr = desc.spatialReference

with arcpy.da.UpdateCursor(fc, ["SHAPE@"]) as cursor:
    for row in cursor:

        # Get Geometry
        geom = row[0]

        # Create an empty array object
        arr = arcpy.Array()

        # Read points, if Z is found to be zero reset it to 1
        for part in geom:
            for pnt in part:
                if pnt.Z == 0:
                    pnt.Z = 1.0

                 # Add updated point to Array
                arr.add(pnt)

        # Construct new polygon geometry from array whilst setting spatial reference and indicating it has Z
        newpoly = arcpy.Polygon(arr,sr,True)

        #Update row
        cursor.updateRow([newpoly])

Error:

 Traceback (most recent call last):
 File "C:\Scratch\fcTest.shp.py", line 21, in <module>
    if pnt.Z == 0:
  AttributeError: 'NoneType' object has no attribute 'Z'
   >>> 

I am trying to update Z values of the vertices of the polygon shape. The script bellow works for polygons without multiparts and donuts. If I run this script for polygon shape that contains multiparts and donuts, I get error. How can I make it work?

My script:

import arcpy

fc = r"C:\Scratch\fcTest.shp"

# Get Spatial Reference of dataset
desc = arcpy.Describe(fc)
sr = desc.spatialReference

with arcpy.da.UpdateCursor(fc, ["SHAPE@"]) as cursor:
    for row in cursor:

        # Get Geometry
        geom = row[0]

        # Create an empty array object
        arr = arcpy.Array()

        # Read points, if Z is found to be zero reset it to 1
        for part in geom:
            for pnt in part:
                if pnt.Z == 0:
                    pnt.Z = 1.0

                 # Add updated point to Array
                arr.add(pnt)

        # Construct new polygon geometry from array whilst setting spatial reference and indicating it has Z
        newpoly = arcpy.Polygon(arr,sr,True)

        #Update row
        cursor.updateRow([newpoly])

Error:

 Traceback (most recent call last):
 File "C:\Scratch\fcTest.shp.py", line 21, in <module>
    if pnt.Z == 0:
  AttributeError: 'NoneType' object has no attribute 'Z'
   >>> 

I am trying to update Z values of the vertices of the polygon shape. The script bellow works for polygons without multiparts and donuts. If I run this script for polygon shape that contains multiparts and donuts, I get error. How can I make it work?

My script:

import arcpy

fc = r"C:\Scratch\fcTest.shp"

# Get Spatial Reference of dataset
desc = arcpy.Describe(fc)
sr = desc.spatialReference

with arcpy.da.UpdateCursor(fc, ["SHAPE@"]) as cursor:
    for row in cursor:

        # Get Geometry
        geom = row[0]

        # Create an empty array object
        arr = arcpy.Array()

        # Read points, if Z is found to be zero reset it to 1
        for part in geom:
            for pnt in part:
                if pnt.Z == 0:
                    pnt.Z = 1.0

                 # Add updated point to Array
                arr.add(pnt)

        # Construct new polygon geometry from array whilst setting spatial reference and indicating it has Z
        newpoly = arcpy.Polygon(arr,sr,True)

        #Update row
        cursor.updateRow([newpoly])

Error:

 Traceback (most recent call last):
 File "C:\Scratch\fcTest.py", line 21, in <module>
    if pnt.Z == 0:
  AttributeError: 'NoneType' object has no attribute 'Z'
   >>> 
Text edit.
Source Link
TomazicM
  • 27k
  • 24
  • 31
  • 42

update z Update Z values polygonsof polygon veritices with multiparts enand donuts

I am trying to update Z values of the vertices of the polygon shape. ThThe script bellow works for polygons without multiparts and donuts. If iI run this script i get error. This is because of thefor polygon shape that contains multiparts and donuts, I get error. can someone fix this How can I make it work?

My script:

import arcpy

fc = r"C:\Scratch\fcTest.shp"

# Get Spatial Reference of dataset
desc = arcpy.Describe(fc)
sr = desc.spatialReference

with arcpy.da.UpdateCursor(fc, ["SHAPE@"]) as cursor:
    for row in cursor:

        # Get Geometry
        geom = row[0]

        # Create an empty array object
        arr = arcpy.Array()

        # Read points, if Z is found to be zero reset it to 1
        for part in geom:
            for pnt in part:
                if pnt.Z == 0:
                    pnt.Z = 1.0

                 # Add updated point to Array
                arr.add(pnt)

        # Construct new polygon geometry from array whilst setting spatial reference and indicating it has Z
        newpoly = arcpy.Polygon(arr,sr,True)

        #Update row
        cursor.updateRow([newpoly])



 
error

Error:

 :
Traceback (most recent call last):
 File "C:\Scratch\fcTest.shp.py", line 21, in <module>
    if pnt.Z == 0:
  AttributeError: 'NoneType' object has no attribute 'Z'
   >>> 

update z values polygons with multiparts en donuts

I am trying to update Z values of the vertices of the polygon shape. Th script bellow works for polygons without multiparts and donuts. If i run this script i get error. This is because of the polygon shape contains multiparts and donuts. can someone fix this?

script:

import arcpy

fc = r"C:\Scratch\fcTest.shp"

# Get Spatial Reference of dataset
desc = arcpy.Describe(fc)
sr = desc.spatialReference

with arcpy.da.UpdateCursor(fc, ["SHAPE@"]) as cursor:
    for row in cursor:

        # Get Geometry
        geom = row[0]

        # Create an empty array object
        arr = arcpy.Array()

        # Read points, if Z is found to be zero reset it to 1
        for part in geom:
            for pnt in part:
                if pnt.Z == 0:
                    pnt.Z = 1.0

                 # Add updated point to Array
                arr.add(pnt)

        # Construct new polygon geometry from array whilst setting spatial reference and indicating it has Z
        newpoly = arcpy.Polygon(arr,sr,True)

        #Update row
        cursor.updateRow([newpoly])



 
error :
Traceback (most recent call last):
 File "C:\Scratch\fcTest.shp.py", line 21, in <module>
    if pnt.Z == 0:
  AttributeError: 'NoneType' object has no attribute 'Z'
   >>> 

Update Z values of polygon veritices with multiparts and donuts

I am trying to update Z values of the vertices of the polygon shape. The script bellow works for polygons without multiparts and donuts. If I run this script for polygon shape that contains multiparts and donuts, I get error. How can I make it work?

My script:

import arcpy

fc = r"C:\Scratch\fcTest.shp"

# Get Spatial Reference of dataset
desc = arcpy.Describe(fc)
sr = desc.spatialReference

with arcpy.da.UpdateCursor(fc, ["SHAPE@"]) as cursor:
    for row in cursor:

        # Get Geometry
        geom = row[0]

        # Create an empty array object
        arr = arcpy.Array()

        # Read points, if Z is found to be zero reset it to 1
        for part in geom:
            for pnt in part:
                if pnt.Z == 0:
                    pnt.Z = 1.0

                 # Add updated point to Array
                arr.add(pnt)

        # Construct new polygon geometry from array whilst setting spatial reference and indicating it has Z
        newpoly = arcpy.Polygon(arr,sr,True)

        #Update row
        cursor.updateRow([newpoly])

Error:

 Traceback (most recent call last):
 File "C:\Scratch\fcTest.shp.py", line 21, in <module>
    if pnt.Z == 0:
  AttributeError: 'NoneType' object has no attribute 'Z'
   >>> 
Source Link
Ram
  • 111
  • 1
  • 1
  • 9
Loading