I am trying to update Z values of polygon features with point features. The code is (found on GIS Stack Exchange) working good if no 'interor ring' or 'multipart' features are present in the polygon features. The polygon is large data set with several 'interor rings' or 'multiparts'. I have no idea how to solve it. I have understood that 'NoneType' AttributeError refers to 'multipart' or 'inner rings' issue.
My code is :
import os
import arcpy
arcpy.env.workspace = r"D:\acrpy\VV_test\scripts\map1"
point_fc = r"D:\acrpy\VV_test\scripts\map1\VRTX_ZM_KAD_test.shp"
polygon_fc = r"\acrpy\VV_test\scripts\map1\ZM_KAD__test.shp"
my_field = "SHAPE@"
my_field_pnt = "SHAPE@XYZ"
with arcpy.da.UpdateCursor(polygon_fc, my_field) as myUpdtCur:
for row in myUpdtCur:
geom = row[0]
arr_pol = arcpy.Array()
for part in geom:
arr_part = arcpy.Array()
pnt_count = 0
for pnt in part:
with arcpy.da.SearchCursor(point_fc, my_field_pnt) as mySrcCur:
for srcPnt in mySrcCur:
if int(pnt.X) == int(srcPnt[0][0]) and int(pnt.Y) == int(srcPnt[0][1]):
updZpnt=srcPnt[0][2]
del mySrcCur
pnt_count += 1
print pnt_count
myXYZPoint = arcpy.Point(pnt.X, pnt.Y, updZpnt)
arr_part.add(myXYZPoint)
arr_pol.add(arr_part)
polygon = arcpy.Polygon(arr_pol,None, True)
row[0] = polygon
myUpdtCur.updateRow(row)
del myUpdtCur
got the error:
76
77
78
79
80
81
82
Traceback (most recent call last):
File "D:\acrpy\VV_test\scripts_OK\GIS_stackexcahnge\test_update Z values from point vertices to polygon vertices .py", line 21, in <module>
if int(pnt.X) == int(srcPnt[0][0]) and int(pnt.Y) == int(srcPnt[0][1]):
AttributeError: 'NoneType' object has no attribute 'X'
>>>
z=100
and focus on proper geometry processing. Also, you should never use thePolygon
constructor without a validSpatialReference
parameter (doing so often corrupts the vertex stream).