<?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 How to create centroid of points within a certain radius? in Spatial Statistics Questions</title>
    <link>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192899#M600</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;We have ~30k points and points close to each other (for example 50 meters or less) should be grouped together as one point (centroid), as shown in attached screenshot (green dots are points we have and blue dots are centroids we want). ET Geowizards can do it but we the demo version has limit of 100 features. Is there any other free tool or method can do it? Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Bin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Nov 2010 15:51:27 GMT</pubDate>
    <dc:creator>BinCai</dc:creator>
    <dc:date>2010-11-16T15:51:27Z</dc:date>
    <item>
      <title>How to create centroid of points within a certain radius?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192899#M600</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;We have ~30k points and points close to each other (for example 50 meters or less) should be grouped together as one point (centroid), as shown in attached screenshot (green dots are points we have and blue dots are centroids we want). ET Geowizards can do it but we the demo version has limit of 100 features. Is there any other free tool or method can do it? Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Bin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Nov 2010 15:51:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192899#M600</guid>
      <dc:creator>BinCai</dc:creator>
      <dc:date>2010-11-16T15:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to create centroid of points within a certain radius?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192900#M601</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Bin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If ET Geowizard works for you, why don't you buy it and support it's continued development?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also have a look at the Measuring Geographic Distributions toolset in the Spatial Statistics toolbox.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Duncan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Nov 2010 15:26:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192900#M601</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2010-11-17T15:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to create centroid of points within a certain radius?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192901#M602</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, Duncan. My boss doesn't want to pay for it. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I will check the measuring toolset.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Nov 2010 16:55:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192901#M602</guid>
      <dc:creator>BinCai</dc:creator>
      <dc:date>2010-11-18T16:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to create centroid of points within a certain radius?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192902#M603</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How accurately do you need the centroid?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Are the clusters identified with a particular attribute?&amp;nbsp; If so, then a bounding container of some form (ie extent rectangle, min area bounding rectangle, convex hull), followed by a centroid or label point determination might be reasonable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If the clusters have no identified attribute which can separate the clusters, then perhaps a dissolved buffer of some reasonable distance to ensure polygons with no holes, followed by a similar centrality point determination might suffice.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;otherwise, you may have to resort to other clustering algorithms (k-means?) etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In any event, your 30k points may have to be batched into separate geographic regions followed by a merge.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If your example is not really representative of the actual patterning in your data, then all bets are off until further information can be provided&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Nov 2010 23:16:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192902#M603</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2010-11-18T23:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to create centroid of points within a certain radius?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192903#M604</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Bin, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another option for this type of grouping is to start with the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000002s000000.htm"&gt;Integrate tool&lt;/A&gt;&lt;SPAN&gt; (Data Management), which allows you to snap features together that are within a specified distance of each other.&amp;nbsp; The integrate tool will change the coordinates of all input features so that those features within a specified distance of each other will be coincident.&amp;nbsp; Please note that the Integrate tool will change your input feature class, so it is always a good idea to run Copy Features beforehand to ensure that you do not lose your original data.&amp;nbsp; Once you have run Integrate, you can use the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//005p0000003s000000.htm"&gt;Collect Events&lt;/A&gt;&lt;SPAN&gt; tool from the Spatial Statistics toolbox to create a count of the number of coincident points at each location.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This workflow is detailed in the &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=61616621-1422-2418-7F38-E95299E68799"&gt;Hot Spot Analysis Tutorial&lt;/A&gt;&lt;SPAN&gt; as a way to aggregate incident data for a hot spot analysis.&amp;nbsp; The tutorial provides step-by-step instructions on creating a model to Integrate and then Collect Events using point data.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Lauren Rosenshein&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Geoprocessing Product Engineer&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Check out the latest Spatial Statistics resources at &lt;/SPAN&gt;&lt;A href="http://bit.ly/spatialstats"&gt;http://bit.ly/spatialstats&lt;/A&gt;&lt;SPAN&gt;!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Nov 2010 15:02:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192903#M604</guid>
      <dc:creator>LaurenRosenshein</dc:creator>
      <dc:date>2010-11-22T15:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to create centroid of points within a certain radius?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192904#M605</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That is a great question, Bill!&amp;nbsp; So great, in fact, that I had to go ask a colleague down the hall.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; The response that I got is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;A given point can move up to 1.4 X the cluster tolerance, but it�??s an iterative process, so the movement of a point, could move it within the cluster tolerance of other points, and shift it further.&amp;nbsp; I think in this case, yes, all the points will shift, and will shift to the center of the grouping (2.5, 0).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My colleague also pointed me to the help topic, &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//006200000003000000.htm"&gt;Topology in ArcGIS&lt;/A&gt;&lt;SPAN&gt;, which I think you will find provides a lot of additional information on cluster tolerances.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Lauren&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Nov 2010 17:13:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192904#M605</guid>
      <dc:creator>LaurenRosenshein</dc:creator>
      <dc:date>2010-11-23T17:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to create centroid of points within a certain radius?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192905#M606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I wrote a Python script that would get you part way there: &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/17809-polygon-in-polygon-analysis-count-if?p=56528&amp;amp;viewfull=1#post56528"&gt;http://forums.arcgis.com/threads/17809-polygon-in-polygon-analysis-count-if?p=56528&amp;amp;viewfull=1#post56528&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The script basically does a recursive SelectByLocation (maybe specify 1 mile selction radius?). The FC then gets a CLUSTER_ID field (you can name it whatever you want) added and populated. So if there were three "clusters" of points that were &amp;gt; 1 mile appart (but the points in the cluster were all &amp;lt; 1 mile appart) you would end up with 3 different CLUSTER_ID values. Then all you need to do is add the X and Y coordinates to the table, run the Summary Statistics tool (using CLUSTER_ID as the case field, and getting the mean X and Y coordinate values). Build a new FC based on teh output of the summary stats table. Presto.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Nov 2010 23:09:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192905#M606</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-11-23T23:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to create centroid of points within a certain radius?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192906#M607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Given Bill's interesting example, what is returned...and what should be considered a cluster given such a circumstance?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Nov 2010 00:02:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192906#M607</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2010-11-24T00:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to create centroid of points within a certain radius?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192907#M608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I wrote a Python script that would get you part way there: &lt;A href="http://forums.arcgis.com/threads/17809-polygon-in-polygon-analysis-count-if?p=56528&amp;amp;viewfull=1#post56528"&gt;http://forums.arcgis.com/threads/17809-polygon-in-polygon-analysis-count-if?p=56528&amp;amp;viewfull=1#post56528&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;The script basically does a recursive SelectByLocation (maybe specify 1 mile selction radius?). The FC then gets a CLUSTER_ID field (you can name it whatever you want) added and populated. So if there were three "clusters" of points that were &amp;gt; 1 mile appart (but the points in the cluster were all &amp;lt; 1 mile appart) you would end up with 3 different CLUSTER_ID values. Then all you need to do is add the X and Y coordinates to the table, run the Summary Statistics tool (using CLUSTER_ID as the case field, and getting the mean X and Y coordinate values). Build a new FC based on teh output of the summary stats table. Presto.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi csny490&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've got a similar problem as it is&amp;nbsp; mentioned here in this Thread and I think, your python script would solve it perfectly! unfortunately, it's not available anymore under the link you pasted here. Could you upload it again? Or could you sent it to me personally?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a lot!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rinadr&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Jan 2011 12:00:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192907#M608</guid>
      <dc:creator>AdrianRingenbach</dc:creator>
      <dc:date>2011-01-18T12:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to create centroid of points within a certain radius?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192908#M609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;&lt;BLOCKQUOTE&gt;csny490;57040 wrote:&lt;BR /&gt;The script basically does a recursive SelectByLocation [..]. The FC then gets a &lt;/BLOCKQUOTE&gt;&lt;/SPAN&gt;&lt;STRONG&gt;CLUSTER_ID&lt;/STRONG&gt;&lt;SPAN&gt; field (you can name it whatever you want) added and populated. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To be more precise: I dont nead a centroid Point as above mentioned, I need a function or a script, that populates a new field in the Attribute table with a ID which is different for every cluster. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a lot!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jan 2011 14:05:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192908#M609</guid>
      <dc:creator>AdrianRingenbach</dc:creator>
      <dc:date>2011-01-20T14:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to create centroid of points within a certain radius?</title>
      <link>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192909#M610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here it is.... Like I indicated earlier, this is a pretty crude way to do this, and I'm sure there are better ways now in v10.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Description
# -----------
# This script assigns a unique identifier to features that are connected/close to each other.
# This may be useful for identifying interconnected networks of polygons or lines such as a road
# or stream networks. It is particularly useful when trying to do large single part dissolves...
# just dissolve by the unique identifier field (or in addition to other fields as well).
#
# Written By: Chris Snyder, WA DNR, 7/27/2007, chris.snyder(at)wadnr.gov
#
# Written For: Python 2.4.1 and ArcGIS v9.2 SP2
#
#Notes on input parameters:
#VARIABLE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PAREMETER_INDEX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PARAMETER_DATA_TYPE
#-------------------------------------------------------------------
#inLayer&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Feature Layer
#networkIdField&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Text (for example, "NET_ID") #new long int field that will be added
#selectionMethod&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Text (for example, "INTERSECT") - this needs to be one of the selection keywords used in the SelectByLocation tool
#distThreshold&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Linear Unit (for example, "1 METER") only used if selectionMethod = "WITHIN_A_DISTANCE"

# Import system modules and creates the Geoprocessor object
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Import system modules and creates the Geoprocessor object (the v9.2 way)
&amp;nbsp;&amp;nbsp;&amp;nbsp; import sys, string, os, glob, shutil, time, traceback, arcgisscripting
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp = arcgisscripting.create()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Defines some functions used for getting messages from the gp and python
&amp;nbsp;&amp;nbsp;&amp;nbsp; def showGpMessage():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage(gp.GetMessages())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;gt;&amp;gt; open(logFile, 'a'), gp.GetMessages()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print gp.GetMessages()
&amp;nbsp;&amp;nbsp;&amp;nbsp; def showGpWarning():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddWarning(gp.GetMessages())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;gt;&amp;gt; open(logFile, 'a'), gp.GetMessages()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print gp.GetMessages()
&amp;nbsp;&amp;nbsp;&amp;nbsp; def showGpError():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError(gp.GetMessages())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;gt;&amp;gt; open(logFile, 'a'), gp.GetMessages()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print gp.GetMessages()
&amp;nbsp;&amp;nbsp;&amp;nbsp; def showPyMessage():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddMessage(str(time.ctime()) + " - " + message)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;gt;&amp;gt; open(logFile, 'a'), str(time.ctime()) + " - " + message
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(time.ctime()) + " - " + message
&amp;nbsp;&amp;nbsp;&amp;nbsp; def showPyWarning():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddWarning(str(time.ctime()) + " - " + message)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;gt;&amp;gt; open(logFile, 'a'), str(time.ctime()) + " - " + message
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(time.ctime()) + " - " + message
&amp;nbsp;&amp;nbsp;&amp;nbsp; def showPyError():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddError(str(time.ctime()) + " - " + message)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;gt;&amp;gt; open(logFile, 'a'), str(time.ctime()) + " - " + message
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(time.ctime()) + " - " + message

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Sets a date/time stamp variable in the format yyyymmddhhmmss (example: 20060711132345)
&amp;nbsp;&amp;nbsp;&amp;nbsp; dateTimeStamp = time.strftime('%Y%m%d%H%M%S')

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Specifies the root directory variable, defines the logFile variable, and does some minor error checking...
&amp;nbsp;&amp;nbsp;&amp;nbsp; dateTimeString = str(time.strftime('%Y%m%d%H%M%S'))
&amp;nbsp;&amp;nbsp;&amp;nbsp; scriptName = os.path.split(sys.argv[0])[-1].split(".")[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; userName = string.lower(os.environ.get("USERNAME")).replace(" ","_").replace(".","_")
&amp;nbsp;&amp;nbsp;&amp;nbsp; tempPathDir = os.environ["TEMP"]
&amp;nbsp;&amp;nbsp;&amp;nbsp; logFileDirectory = r"\\snarf\am\div_lm\ds\gis\tools\log_files"
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.exists(logFileDirectory) == True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logFile = os.path.join(logFileDirectory, scriptName + "_" + userName + "_" + dateTimeString + ".txt")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print &amp;gt;&amp;gt; open(logFile, 'a'), "Write test successfull!"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logFile = os.path.join(tempPathDir, scriptName + "_" + userName + "_" + dateTimeString + ".txt")&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logFile = os.path.join(tempPathDir, scriptName + "_" + userName + "_" + dateTimeString + ".txt")
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.exists(logFile)== True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.remove(logFile)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "Created log file " + logFile; showPyMessage()
&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "Running " + sys.argv[0]; showPyMessage()
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Attempts to check out the lowest grade license available...
&amp;nbsp;&amp;nbsp;&amp;nbsp; if gp.CheckProduct("ArcView") == "Available":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SetProduct("ArcView")
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif gp.CheckProduct("ArcEditor") == "Available":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SetProduct("ArcEditor")
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif gp.CheckProduct("ArcInfo") == "Available":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SetProduct("ArcInfo")
&amp;nbsp;&amp;nbsp;&amp;nbsp; message =&amp;nbsp; "Selected an " + gp.ProductInfo() + " license"; showPyMessage()
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "Starting geoprocessing routine..."; showPyMessage()
&amp;nbsp;&amp;nbsp;&amp;nbsp; #*****************GEOPROCESSING STUFF GOES HERE******************************

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Process: Sets some gp settings
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.overwriteoutput = 1

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Defines the input feature layer&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; inLayer = gp.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; networkIdField = gp.GetParameterAsText(1)
&amp;nbsp;&amp;nbsp;&amp;nbsp; selectionMethod = gp.GetParameterAsText(2)
&amp;nbsp;&amp;nbsp;&amp;nbsp; distThreshold = gp.GetParameterAsText(3)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Process: Tests for the existance of networkIdField - if it doesn't exists, add it
&amp;nbsp;&amp;nbsp;&amp;nbsp; if gp.listfields(inLayer, networkIdField).next() == None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddField_management(inLayer, networkIdField, "LONG"); showGpMessage()
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "Specified existing field type is: " + str(gp.listfields(inLayer, networkIdField).next().type); showPyMessage() 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if gp.listfields(inLayer, networkIdField).next().type not in ["SmallInteger","Double","Integer"]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "ERROR: Existing specified network id field type must be Long Integer, Short Integer or Double! Exiting script..."; showPyError(); sys.exit()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management(inLayer, networkIdField, "0", "VB"); showGpMessage() #makes sure the field is nulled

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Process: Figures out how many features are in the input feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; featureCount = int(gp.getcount(gp.describe(inLayer).catalogpath))

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Process: Figures out what the oidValue field is called
&amp;nbsp;&amp;nbsp;&amp;nbsp; oidFieldName = gp.describe(inLayer).oidfieldname

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Process: Does a recursive select by location
&amp;nbsp;&amp;nbsp;&amp;nbsp; featureLayer1 = "feature_layer_1"&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; featureLayer2 = "feature_layer_2"
&amp;nbsp;&amp;nbsp;&amp;nbsp; identifiedFeatures = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; networkId = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer_management(inLayer, featureLayer1, "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; while identifiedFeatures &amp;lt; featureCount:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Process: Assign a counter
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; networkId =&amp;nbsp; networkId + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Process: Establishes a cursor in order to return a single OID of a non-identified feature
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try: #this is in a try loop cause' it will fail on the last loop since networkIdField will be (hopefully) 100% populated
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oidValue = gp.searchcursor(inLayer, networkIdField + " = 0 OR " + networkIdField + " IS NULL").next().getvalue(oidFieldName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "Breaking selection loop..."; showPyMessage()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break #break out of the loop
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SelectLayerByAttribute_management(featureLayer1, "NEW_SELECTION", oidFieldName + " = " + str(oidValue))

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Process: Keep selecting features until there are no more to select
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count1 = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count2 = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count3 = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while count2 &amp;gt; count1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count3 = count3 + 1 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count1 = int(gp.getcount(featureLayer1))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if selectionMethod == "WITHIN_A_DISTANCE":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SelectLayerByLocation_management(featureLayer1, "WITHIN_A_DISTANCE", featureLayer1, distThreshold, "NEW_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SelectLayerByLocation_management(featureLayer1, selectionMethod, featureLayer1, "", "NEW_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count2 = int(gp.getcount(featureLayer1))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if divmod(count3, 10)[1] == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "Processed the " + str(count3) + "th loop of connected feature ID #" + str(networkId) + "..."; showPyMessage()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management(featureLayer1, networkIdField, networkId, "VB")

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Process: Every 25th loop, spit out a status message (too many status messages makes the script run slow) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if divmod(networkId, 25)[1] == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer_management(inLayer, featureLayer2, networkIdField + " &amp;gt; 0")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; identifiedFeatures = int(gp.getcount(featureLayer2))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "Assigned identifier to " + str(float(identifiedFeatures) / float(featureCount) * 100) + " percent of the features"; showPyMessage()&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Process: Gives a final report
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer_management(inLayer, featureLayer2, networkIdField + " &amp;gt; 0")
&amp;nbsp;&amp;nbsp;&amp;nbsp; identifiedFeatures = int(gp.getcount(featureLayer2))
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.MakeFeatureLayer_management(inLayer, featureLayer2, networkIdField + " = 0 OR " + networkIdField + " IS NULL")
&amp;nbsp;&amp;nbsp;&amp;nbsp; nonIdentifiedFeatures = int(gp.getcount(featureLayer2))
&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "CONNECTED FEATURES REPORT:"; showPyWarning()
&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "--------------------------"; showPyWarning()
&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "Assigned " + str(networkId -1) + " unique network identifiers to " + str(identifiedFeatures) + " features!"; showPyWarning()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #*****************GEOPROCESSING STUFF ENDS HERE******************************
&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "Ending geoprocessing routine..."; showPyMessage()

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Indicates that the script is complete - both a visual and physical indicator...
&amp;nbsp;&amp;nbsp;&amp;nbsp; message = sys.argv[0] + " is all done!"; showPyMessage()
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "\n*** LAST GEOPROCESSOR MESSAGE (may not be source of the error)***"; showPyError()
&amp;nbsp;&amp;nbsp;&amp;nbsp; showGpMessage()
&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "PYTHON TRACEBACK INFO: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyError()
&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "PYTHON ERROR INFO: " +&amp;nbsp; str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"; showPyError()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:41:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-statistics-questions/how-to-create-centroid-of-points-within-a-certain/m-p/192909#M610</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T09:41:09Z</dc:date>
    </item>
  </channel>
</rss>

