return shape.centroid.X
return shape.centroid.Y
I would like to calculate the centroid (x and y co-ordinate) of a polygon using model builder - ArcGIS 10.1 Standard. I don't have access to the tool Feature to Point as the standard licence doesn't allow this option and there doesn't seem to be a Calculate Geometry tool within model builder. Can anyone help please
Apologies!! I am coming into this thread several years too late. I am literally trying to accomplish the exact same thing but I can't get my python code right...I see your original attachment is no longer...I've followed the steps in the scrn shot of the calcutalor but I am so new to python...i'm probably missing an exclamation mark or something ridiculous....here's hoping you can help me as well. I've been googling python snippets all day and can't seem to find what works.
thanks as always
Lana
lana donaldson, post your code and we can help. Or, better yet, start a new question, since this one is answered.
The code given in the answer works great, but is there a way to return latitude, longitude instead of Y, X?
Try add @ DECIMALDEGREES ! at the end of line
<SPAN class="keyword token">return</SPAN> shape<SPAN class="punctuation token">.</SPAN>centroid<SPAN class="punctuation token">.</SPAN>Y@DECIMALDEGREES !<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Thanks for the suggestion, Abdullah. However, doing so in the Code Block returns a Python syntax error (000989):
Used the modifier in the Expression [yCentroid(!Shape@DECIMALDEGREES!] returned a different Python error (000539), indicating that there is an invalid field used, namely "the distance method is not a valid method of the geometry object".
I'm using NAD_1983_StatePlane_Colorado_South_FIPS_0503_Feet.
This calculation works fine using Calculate Geometry (from the attribute table):
Is there a way to view the log of the centroid calc process used by the Calculate Geometry tool?
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.