<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Generating a centroid for a polygon in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289568#M22447</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello Yousaf,&lt;BR /&gt;&lt;BR /&gt;My apologies: I had misread the thread!&lt;BR /&gt;ET Geowizards tools does in fact operate on all items of the shape or feature class.&lt;BR /&gt;&lt;BR /&gt;If you want to do it point by point, you could do one of two things:&lt;BR /&gt;- As described above, do an AddField followed by a CalculateField, but only on the active layer.&lt;BR /&gt;- Create your fields, select the points you're interested in and do the following: &lt;SPAN style="font-style:italic;"&gt;Attribute Table&lt;/SPAN&gt; - Right Click on X or Y Field - &lt;SPAN style="font-style:italic;"&gt;Calculate Geometry...&lt;/SPAN&gt; - &lt;SPAN style="font-style:italic;"&gt;X / Y Coordinate of Point&lt;/SPAN&gt;. 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.&lt;BR /&gt;&lt;BR /&gt;I hope this helps! Write back if anything's unclear.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 14 Oct 2011 16:10:41 GMT</pubDate>
    <dc:creator>HemingZhu</dc:creator>
    <dc:date>2011-10-14T16:10:41Z</dc:date>
    <item>
      <title>Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289558#M22437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I posted this question in a generic thread earlier, but was wondering if it can be done in python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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&amp;amp;pasteable X and Y. He wants this automation as he wants X and Y to be generated for all polygons using the same algorithm.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am looking at the CalculateField example: Calculate centroids on this link:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be extremely appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 15:28:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289558#M22437</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2011-10-13T15:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289559#M22438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It seems like the simplest solution is to add X and Y fields to the polygon feature class and calculate the X and &amp;amp; values as you mention.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;9.3 code would look something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Process: Add Field
gp.AddField_management(parcels_shp, "X_COORD", "DOUBLE", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
# Process: Add Field
gp.AddField_management(parcels_shp, "Y_COORD", "DOUBLE", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field
gp.CalculateField_management(parcels_shp, "X_COORD", "!shape.centroid.x!", "PYTHON_9.3", "")
# Process: Calculate Field
gp.CalculateField_management(parcels_shp, "Y_COORD", "!shape.centroid.y!", "PYTHON_9.3", "")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Once you have those added to the polys as attributes, why not simply use the identify tool?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You can copy and paste the X and Y values from the tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you don't want to see all of the other attributes when you use the identify tool you can "hide" the other attributes from the identify tool by simply unchecking the other attributes in the Field tab of the layer properties.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:58:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289559#M22438</guid>
      <dc:creator>JoelCalhoun</dc:creator>
      <dc:date>2021-12-11T13:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289560#M22439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;ArcGIS already has a tool that does this:&lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Feature_To_Point/00170000003m000000/"&gt; Feature to Point&lt;/A&gt;&lt;SPAN&gt; (requires ArcInfo). Like most tools, it will honor your selection (ie. make points only for those selected polygons). It doesn't automatically pop up the coordinates, however, so you'd have to code that.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Oct 2011 20:22:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289560#M22439</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2011-10-13T20:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289561#M22440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;ETGeowizard's unregistered version can do this as well, through arcpy, ArcCatalog or ArcMap, and it's free.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The function is called Polygon To Point, i think.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 02:08:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289561#M22440</guid>
      <dc:creator>MarcNakleh</dc:creator>
      <dc:date>2011-10-14T02:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289562#M22441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It seems like the simplest solution is to add X and Y fields to the polygon feature class and calculate the X and &amp;amp; values as you mention.&lt;BR /&gt;&lt;BR /&gt;9.3 code would look something like:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Process: Add Field
gp.AddField_management(parcels_shp, "X_COORD", "DOUBLE", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")
# Process: Add Field
gp.AddField_management(parcels_shp, "Y_COORD", "DOUBLE", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field
gp.CalculateField_management(parcels_shp, "X_COORD", "!shape.centroid.x!", "PYTHON_9.3", "")
# Process: Calculate Field
gp.CalculateField_management(parcels_shp, "Y_COORD", "!shape.centroid.y!", "PYTHON_9.3", "")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Once you have those added to the polys as attributes, why not simply use the identify tool?&lt;BR /&gt;You can copy and paste the X and Y values from the tool.&lt;BR /&gt;&lt;BR /&gt;If you don't want to see all of the other attributes when you use the identify tool you can "hide" the other attributes from the identify tool by simply unchecking the other attributes in the Field tab of the layer properties.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for this. However, the guy I am trying to help is not very good with ArcMap and I come from a programming background with two years experience of basic GIS work in ArcMap. So it's a case of blind leading the blind here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The first thing is where I run this code? I was thinking of creating a custom tool box and creating a tool for the rest of the team. I also know a bit about Models. So how can a model take a selected feature as an input parameter? Also, the displaying X and Y would be very useful so any link to a code for the pop-up would be very helpful.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:58:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289562#M22441</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2021-12-11T13:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289563#M22442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;ArcGIS already has a tool that does this:&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Feature_To_Point/00170000003m000000/"&gt; Feature to Point&lt;/A&gt; (requires ArcInfo). Like most tools, it will honor your selection (ie. make points only for those selected polygons). It doesn't automatically pop up the coordinates, however, so you'd have to code that.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for this. However, we don't have access to ArcInfo. I am on a lowly ArcView licence. But the code examples are really good on the Feature to Point link. I wonder if it is possible to use the code behind Feature to Point and create a custom tool!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 10:11:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289563#M22442</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2011-10-14T10:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289564#M22443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;ETGeowizard's unregistered version can do this as well, through arcpy, ArcCatalog or ArcMap, and it's free.&lt;BR /&gt;The function is called Polygon To Point, i think.&lt;BR /&gt;&lt;BR /&gt;Hope this helps!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Great! I'll download this and try it now.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 10:15:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289564#M22443</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2011-10-14T10:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289565#M22444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;ETGeowizard's unregistered version can do this as well, through arcpy, ArcCatalog or ArcMap, and it's free.&lt;BR /&gt;The function is called Polygon To Point, i think.&lt;BR /&gt;&lt;BR /&gt;Hope this helps!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, I tried this but it takes all the records in a layer. I just want to select one feature polygon directly on SDE and generate a centroid. Ideally, get the X and Y in a pop-up.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 13:02:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289565#M22444</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2011-10-14T13:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289566#M22445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello Yousaf,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My apologies: I had misread the thread!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ET Geowizards tools does in fact operate on all items of the shape or feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to do it point by point, you could do one of two things:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- As described above, do an AddField followed by a CalculateField, but only on the active layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Create your fields, select the points you're interested in and do the following: &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Attribute Table&lt;/SPAN&gt;&lt;SPAN&gt; - Right Click on X or Y Field - &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Calculate Geometry...&lt;/SPAN&gt;&lt;SPAN&gt; - &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;X / Y Coordinate of Point&lt;/SPAN&gt;&lt;SPAN&gt;. 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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps! Write back if anything's unclear.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 13:53:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289566#M22445</guid>
      <dc:creator>MarcNakleh</dc:creator>
      <dc:date>2011-10-14T13:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289567#M22446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello Yousaf,&lt;BR /&gt;&lt;BR /&gt;My apologies: I had misread the thread!&lt;BR /&gt;ET Geowizards tools does in fact operate on all items of the shape or feature class.&lt;BR /&gt;&lt;BR /&gt;If you want to do it point by point, you could do one of two things:&lt;BR /&gt;- As described above, do an AddField followed by a CalculateField, but only on the active layer.&lt;BR /&gt;- Create your fields, select the points you're interested in and do the following: &lt;SPAN style="font-style:italic;"&gt;Attribute Table&lt;/SPAN&gt; - Right Click on X or Y Field - &lt;SPAN style="font-style:italic;"&gt;Calculate Geometry...&lt;/SPAN&gt; - &lt;SPAN style="font-style:italic;"&gt;X / Y Coordinate of Point&lt;/SPAN&gt;. 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.&lt;BR /&gt;&lt;BR /&gt;I hope this helps! Write back if anything's unclear.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for this. I'll try to create a custom tool using model builder. I am reading about model building in ArcGIS Resource Centre at the moment. I want to automate this as much as possible as my colleages are not willing to do any of it manually.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 15:48:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289567#M22446</guid>
      <dc:creator>YousafHassan</dc:creator>
      <dc:date>2011-10-14T15:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a centroid for a polygon</title>
      <link>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289568#M22447</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello Yousaf,&lt;BR /&gt;&lt;BR /&gt;My apologies: I had misread the thread!&lt;BR /&gt;ET Geowizards tools does in fact operate on all items of the shape or feature class.&lt;BR /&gt;&lt;BR /&gt;If you want to do it point by point, you could do one of two things:&lt;BR /&gt;- As described above, do an AddField followed by a CalculateField, but only on the active layer.&lt;BR /&gt;- Create your fields, select the points you're interested in and do the following: &lt;SPAN style="font-style:italic;"&gt;Attribute Table&lt;/SPAN&gt; - Right Click on X or Y Field - &lt;SPAN style="font-style:italic;"&gt;Calculate Geometry...&lt;/SPAN&gt; - &lt;SPAN style="font-style:italic;"&gt;X / Y Coordinate of Point&lt;/SPAN&gt;. 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.&lt;BR /&gt;&lt;BR /&gt;I hope this helps! Write back if anything's unclear.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Oct 2011 16:10:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/generating-a-centroid-for-a-polygon/m-p/289568#M22447</guid>
      <dc:creator>HemingZhu</dc:creator>
      <dc:date>2011-10-14T16:10:41Z</dc:date>
    </item>
  </channel>
</rss>

