I have a shapefile of US Cities and I want to get the X and Y coordinate of EACH city in that shapefile. I've tried this:
for city in city_cursor:
geom = city.Shape
point = geom.getPart()
citylist_City_Name.append(city.CITY_NAME)
citylist_Country.append(city.CNTRY_NAME)
citylist_Admin.append(city.ADMIN_NAME)
citylist_Population.append(city.Population)
citylist_X_Coor.append(geom.point.X)
citylist_Y_Coor.append(geom.point.Y)
but I get the error:
Traceback (most recent call last):
File "C:/Users/workd.py", line 43, in
citylist_X_Coor.append(geom.point.X)
AttributeError: 'PointGeometry' object has no attribute 'point'
I don't really understand the error message? How can I fix it? Thanks!
Best Answer
You just need
point.X
andpoint.Y
notgeom.point.X
andgeom.point.Y
.Alternatively, if you are using ArcGIS for Desktop 10.1 or later then code like that below using the Data Access module should do the same thing but run faster.