Wednesday, 7 December 2016

arcgis 10.2 - ArcPy script error - NoneType object has no attribute X


I'm familiarising myself with using scripting in ArcMap 10.2 and as part of this I'm using the following to extract vertices from some polygons.


... 
... import arcpy
... from arcpy import env
... env.workspace = "C:/WORKING"
... fc = "Dist_Footprint.shp"
... cursor = arcpy.da.SearchCursor(fc, ["OID@", "SHAPE@"])
... for row in cursor:
... print("Feature {0}: ".format(row[0]))

... for point in row[1].getPart(0):
... print ("{0}, {1}".format(point.X,point.Y))

It chugs through pulling out co-ordinates ok until I get the following error message.


Runtime error 
Traceback (most recent call last):
File "", line 11, in
AttributeError: 'NoneType' object has no attribute 'X'

I've had a look at a few previous questions to try to get some answers eg. https://stackoverflow.com/questions/19946947/tkinter-nonetype-object-has-no-attribute-pack-still-works. These flag that there is a variable whose value is None, and the script is trying to do None.X(), or NoneType means that the data source could not be opened.





1) The script does not finish the first polygon. I have displayed the Python-generated co-ordinates in ArcMap and know which polygon it is. Also have run the geometry check on the polygon by itself. No apparent issues. ArcGIS still says no issues with main file. I have checked with QGIS which says there are some issues but NOT related to the polygon flagged by Python. In QGIS I get 4 invalid geometry errors along the lines of "segment 0 of ring 0 of polygon 0 intersect 0 of ring 0 of polygon 2 at X, Y location" related to other polygons.


2) I have run the script on a previous version of the problem file and it gets to Feature 16 before falling over. Running the original script on some simple polygons works fine so looks like the script is ok. Back to the drawing board with the original file (not sure where to go as the check geometry tool says it's ok).


Anybody suggest what other tools I can use to work out where the problem is?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...