Model Builder - Calculate the centroid of a polygon

6684
12
Jump to solution
05-01-2013 01:13 AM
MaryMulholland
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
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
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

View solution in original post

12 Replies
JakeSkinner
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
lanadonaldson1
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

0 Kudos
DarrenWiens2
MVP Honored Contributor

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

0 Kudos
RobertBorchert
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
0 Kudos
MaryMulholland
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?
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Can you post a screen shot of your model?
0 Kudos
MaryMulholland
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.

Thanks again for your help.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Good to hear this is working.  You can mark a thread as answered by clicking the green check mark next to the response that answered your question.
0 Kudos
lanadonaldson1
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

0 Kudos