# Model Builder - Calculate the centroid of a polygon

6798
12
05-01-2013 01:13 AM
New Contributor
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
Tags (3)
1 Solution

Accepted Solutions
Esri Esteemed Contributor
Hi Mary,

You can do this using the Calculate Field tool.  Here is an example how to set it up.

[ATTACH=CONFIG]23900[/ATTACH]

To do the Y centroid, simply change the line:

`return shape.centroid.X`

to:

`return shape.centroid.Y`
12 Replies
Esri Esteemed Contributor
Hi Mary,

You can do this using the Calculate Field tool.  Here is an example how to set it up.

[ATTACH=CONFIG]23900[/ATTACH]

To do the Y centroid, simply change the line:

`return shape.centroid.X`

to:

`return shape.centroid.Y`
New Contributor III

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

MVP Honored Contributor

lana donaldson, post your code and we can help. Or, better yet, start a new question, since this one is answered.

Frequent Contributor III
If you create two new fields in your feature table make the double precision fields.  One for X one for Y.

In an edit session right click on the X field and choose calculate geometry.  From the drop down menu choose X coordinate of centroid.  Then do the same for 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
New Contributor
Hi Jake

Thanks for your reply.  I added the code and it calculates the x and y fields.  However the model seems to be stuck in a loop, how do I get it to stop after it calculates the x and y fields?
Esri Esteemed Contributor
Can you post a screen shot of your model?
New Contributor
Jake

I got it to work, I had to add the process 'make xy event layer' which stopped the loop.  I am not sure how to mark this thread as answered.