Select to view content in your preferred language

Generating a centroid for a polygon

2339
10
10-13-2011 08:28 AM
YousafHassan
Emerging Contributor
Hi
I posted this question in a generic thread earlier, but was wondering if it can be done in python.

I am trying to help my colleague who wants to select a polygon and then click a button (or a custom tool), which would generate a centroid for that polygon. Ideally, he wants a pop-up to appear which would display a copy&pasteable X and Y. He wants this automation as he wants X and Y to be generated for all polygons using the same algorithm.

I was thinking of building a custom tool for him using a model. Could anyone please point me to the tools I need in order to achieve this? If you have already written a tool, would you like share it with me? I am quite comfortable in python and VBA but am not so familiar with Arc tools. I would actually prefer to do this in python as the support for VBA won't be there in future.

I am looking at the CalculateField example: Calculate centroids on this link:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000

I was wondering how I can adapt this python script in to doing the above, i.e. the input is the selected polygon and the output is a pop-up displaying X and Y.

Any help would be extremely appreciated.
Thanks.
Tags (2)
10 Replies
HemingZhu
Frequent Contributor
Hello Yousaf,

My apologies: I had misread the thread!
ET Geowizards tools does in fact operate on all items of the shape or feature class.

If you want to do it point by point, you could do one of two things:
- As described above, do an AddField followed by a CalculateField, but only on the active layer.
- Create your fields, select the points you're interested in and do the following: Attribute Table - Right Click on X or Y Field - Calculate Geometry... - X / Y Coordinate of Point. The overhead of manually clicking on each point, then activating the tool you had in mind seems comparable in my books to using this built-in function of ArcMap.

I hope this helps! Write back if anything's unclear.


In Arcpy, the geometry and polygon classes have a property called centroid (geometry.centroid or polygon.centroid). It will return centroid as a point. It might help you.
0 Kudos