<?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: near analysis tool with more parameters in Spatial Data Science Questions</title>
    <link>https://community.esri.com/t5/spatial-data-science-questions/near-analysis-tool-with-more-parameters/m-p/522018#M1182</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Small addition on what it actually does:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;line 15: it gets the start point (true centroid of the county, based on the FIPS) and the corresponding population of that county.&lt;/LI&gt;&lt;LI&gt;line 18: it creates a dictionary containing the oid as key and a list of distance, population and fips of the counties as values&lt;/LI&gt;&lt;LI&gt;line 21: the dictionary is ordered based on the distance from each centroid to the start county&lt;/LI&gt;&lt;LI&gt;line 24: a loop is started to accumulate the population until the desired population is reached&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The result is printed as where clause that can be copied into the layer properties to see the result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 05 Jan 2015 01:35:11 GMT</pubDate>
    <dc:creator>XanderBakker</dc:creator>
    <dc:date>2015-01-05T01:35:11Z</dc:date>
    <item>
      <title>near analysis tool with more parameters</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/near-analysis-tool-with-more-parameters/m-p/522016#M1180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to find a geoprocessing tool like a beefed-up near analysis that will search outwards from a point (or polygon) of origin until a specified value (not distance or count) is reached.&amp;nbsp; Let's say I'm using a counties feature class and specify a parameter of max 1,000,000 in the population field.&amp;nbsp; The tool would begin with a user-specified county and travel outward in a radius tallying up each county's population until the parameter is met.&amp;nbsp; Any ideas, either for existing tools or model-builder?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Oct 2014 00:35:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/near-analysis-tool-with-more-parameters/m-p/522016#M1180</guid>
      <dc:creator>TimOpelt</dc:creator>
      <dc:date>2014-10-31T00:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: near analysis tool with more parameters</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/near-analysis-tool-with-more-parameters/m-p/522017#M1181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just because it is fun...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="near.png" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/47119_near.png" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;...using this code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import math

def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; from collections import OrderedDict
&amp;nbsp;&amp;nbsp;&amp;nbsp; # create ordered list of distance vs id + pop
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = r"C:\Forum\NearEnhanced\gdb\pop_counties.gdb\counties"
&amp;nbsp;&amp;nbsp;&amp;nbsp; fld_pop = "PST025181D"
&amp;nbsp;&amp;nbsp;&amp;nbsp; fld_fips = "FIPS"

&amp;nbsp;&amp;nbsp;&amp;nbsp; fips_start = "29189" # "05021"
&amp;nbsp;&amp;nbsp;&amp;nbsp; max_pop = 5000000 # 1000000

&amp;nbsp;&amp;nbsp;&amp;nbsp; # get start pnt and pop
&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt_start, pop_start = getPointStart(fc, fld_fips, fld_pop, fips_start)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # create ordered dict with distance, fips and pop
&amp;nbsp;&amp;nbsp;&amp;nbsp; dct_data = createDictDistancesAndData(fc, fld_fips, fld_pop, pnt_start, fips_start)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # let's sort on distance to true centroid
&amp;nbsp;&amp;nbsp;&amp;nbsp; dct_sorted = OrderedDict(sorted(dct_data.items(), key=lambda x: x[1][0]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; lst_fips = [fips_start]
&amp;nbsp;&amp;nbsp;&amp;nbsp; pop_tot = pop_start
&amp;nbsp;&amp;nbsp;&amp;nbsp; for oid, lst in dct_sorted.items():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pop = lst[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pop_tot += pop
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if pop_tot &amp;gt; max_pop:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print pop_tot
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
&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; lst_fips.append(lst[2])

&amp;nbsp;&amp;nbsp;&amp;nbsp; print "{0} in ('{1}')".format(arcpy.AddFieldDelimiters(fc, fld_fips), "','".join(lst_fips))


def getPointStart(fc, fld_fips, fld_pop, fips_start):
&amp;nbsp;&amp;nbsp;&amp;nbsp; where = "{0} = '{1}'".format(arcpy.AddFieldDelimiters(fc, fld_fips), fips_start)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = arcpy.da.SearchCursor(fc, ("SHAPE@TRUECENTROID",fld_pop), where_clause=where).next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; return row[0], row[1]

def createDictDistancesAndData(fc, fld_fips, fld_pop, pnt_start, fips_start):
&amp;nbsp;&amp;nbsp;&amp;nbsp; sr = arcpy.Describe(fc).spatialReference
&amp;nbsp;&amp;nbsp;&amp;nbsp; dct_data = {}
&amp;nbsp;&amp;nbsp;&amp;nbsp; where = "{0} &amp;lt;&amp;gt; '{1}'".format(arcpy.AddFieldDelimiters(fc, fld_fips), fips_start)
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(fc, ("SHAPE@TRUECENTROID",fld_pop, fld_fips, "OID@"), where_clause=where) as curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pop = row[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fips = row[2]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oid = row[3]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dist = getDistanceArcpy(pnt_start, pnt, sr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct_data[oid] = [dist, pop, fips]
&amp;nbsp;&amp;nbsp;&amp;nbsp; return dct_data

def getDistance(pnt_start, pnt):
&amp;nbsp;&amp;nbsp;&amp;nbsp; return math.hypot(pnt[0] - pnt_start[0], pnt[1] - pnt_start[1])

def getDistanceArcpy(pnt1, pnt2, sr):
&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt_geo1 = arcpy.PointGeometry(arcpy.Point(pnt1[0], pnt1[1]), sr)
&amp;nbsp;&amp;nbsp;&amp;nbsp; pnt_geo2 = arcpy.PointGeometry(arcpy.Point(pnt2[0], pnt2[1]), sr)
&amp;nbsp;&amp;nbsp;&amp;nbsp; return pnt_geo1.distanceTo(pnt_geo2)

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The example is using county with fips 29189 and a max population of 5 million. Change lines 7 to 9 to indicate the featureclass with the counties and the names of the fips and populations fields. Change the settings on line 11 and 12 to indicate the fips to start and the maximum populations. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The result is a print of the where clause you can apply to show the counties included in the selection. The code can be adapted to create a feature class with the counties. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code stops with the value before it passes the maximum population. This happens on line 27 to 29. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:46:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/near-analysis-tool-with-more-parameters/m-p/522017#M1181</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T22:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: near analysis tool with more parameters</title>
      <link>https://community.esri.com/t5/spatial-data-science-questions/near-analysis-tool-with-more-parameters/m-p/522018#M1182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Small addition on what it actually does:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;line 15: it gets the start point (true centroid of the county, based on the FIPS) and the corresponding population of that county.&lt;/LI&gt;&lt;LI&gt;line 18: it creates a dictionary containing the oid as key and a list of distance, population and fips of the counties as values&lt;/LI&gt;&lt;LI&gt;line 21: the dictionary is ordered based on the distance from each centroid to the start county&lt;/LI&gt;&lt;LI&gt;line 24: a loop is started to accumulate the population until the desired population is reached&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The result is printed as where clause that can be copied into the layer properties to see the result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jan 2015 01:35:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/spatial-data-science-questions/near-analysis-tool-with-more-parameters/m-p/522018#M1182</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-01-05T01:35:11Z</dc:date>
    </item>
  </channel>
</rss>

