2

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 "<string>", line 11, in <module>
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?

  • Does it just work for the first polygon only? Why don't you provide a simple example of your print statement output – user681 Jul 17 '14 at 8:37
  • Starts with Feature 1 and prints out heap of co-ordinates then error. I assume it should then go to Feature 2? Note that this a clean file (used Repair Geometries) according to Arc although I had issues with invalid geometries in QGIS. PS I'll need to familiarise myself with img for this site. – DirkB Jul 17 '14 at 13:38
  • Apologies should be Feature 0 – DirkB Jul 17 '14 at 13:57
4

This look like there is a null geometry somewhere. To solve this, you should first run the "repair" tool. To avoid you code to crash (as you said that it works for the first polygons), you can add some testing

if point:
    print ("{0}, {1}".format(point.X,point.Y))
else:
    print "No point"
  • 1
    A null point is used to separate inner rings in polygons, hence, it would throw an error, that is why I suggested, as you have pointed out, that they print the results and look at their polygon – user681 Jul 17 '14 at 9:29
  • Hi radouxju, I had run the repair geometries on the file and appeared ok for use. Where do I put the above code? I replaced the "for point in row...." with your code and get 96 Features with no points, including Feature 0. As Dan mentioned I can output the co-ords and look at the polygon. – DirkB Jul 17 '14 at 13:58
  • 1
    try adding one more loop on the part (for part in range(row[1].partCount): ) – radouxju Jul 17 '14 at 14:05
  • It doesn't appear to get through the first polygon. Where do I put the loop? – DirkB Jul 18 '14 at 0:23
  • 1
    Show the code as edited, I suspect that the if statement is in the wrong place. Have a look at my function (ie a def) posted on my blog obidangis.blogspot.ca/2013/06/… to get an idea how it should work – user681 Jul 18 '14 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.