<?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 Problem adding ID to Generate Near Table (or next nearest) in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/problem-adding-id-to-generate-near-table-or-next/m-p/215665#M7387</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello, I don't know if anyone can help me, but I'm running out of ideas as to how I can solve a problem:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In modelbuilder (version 10)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Using the 'Generate Near Table' tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I can successfully find the nearest three 'sites' to a set of features, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;however, the resulting table does not have a field that specifies this is the nearest (1) this is the second nearest (2) this is the third nearest (3).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I require this because I want to seperate out the nearest and second/third nearest into seperate tables. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So my question:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone know if there is a way to either:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; - add an id to the generate near table (1 for nearest 2 for next nearest feature etc.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; - or is there a tool where I can calculate the second (or third) nearest feature, but not the first&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have searched far and wide for a solution, but have had no luck so far,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;so any suggestions would be greatly appreciated......&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course this would all be easy if the 'generate near tool' could add an ID for second nearest etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Which I really expected it to do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, Richard&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 08 Apr 2011 10:09:43 GMT</pubDate>
    <dc:creator>RichardGreaney</dc:creator>
    <dc:date>2011-04-08T10:09:43Z</dc:date>
    <item>
      <title>Problem adding ID to Generate Near Table (or next nearest)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/problem-adding-id-to-generate-near-table-or-next/m-p/215665#M7387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello, I don't know if anyone can help me, but I'm running out of ideas as to how I can solve a problem:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In modelbuilder (version 10)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Using the 'Generate Near Table' tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I can successfully find the nearest three 'sites' to a set of features, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;however, the resulting table does not have a field that specifies this is the nearest (1) this is the second nearest (2) this is the third nearest (3).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I require this because I want to seperate out the nearest and second/third nearest into seperate tables. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So my question:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone know if there is a way to either:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; - add an id to the generate near table (1 for nearest 2 for next nearest feature etc.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; - or is there a tool where I can calculate the second (or third) nearest feature, but not the first&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have searched far and wide for a solution, but have had no luck so far,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;so any suggestions would be greatly appreciated......&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course this would all be easy if the 'generate near tool' could add an ID for second nearest etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Which I really expected it to do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, Richard&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Apr 2011 10:09:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/problem-adding-id-to-generate-near-table-or-next/m-p/215665#M7387</guid>
      <dc:creator>RichardGreaney</dc:creator>
      <dc:date>2011-04-08T10:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Problem adding ID to Generate Near Table (or next nearest)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/problem-adding-id-to-generate-near-table-or-next/m-p/215666#M7388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have figured a quick fix using a calculate field (python) with the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Reclass (!OBJECTID!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def Reclass(OBJECTID):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; if OBJECTID % 3 == 1:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; elif (OBJECTID + 1) % 3 == 1:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this is using a MOD on the ObjectID&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd still like a slightly more elegant solution if anyone can suggest one?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Richard&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Apr 2011 12:30:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/problem-adding-id-to-generate-near-table-or-next/m-p/215666#M7388</guid>
      <dc:creator>RichardGreaney</dc:creator>
      <dc:date>2011-04-08T12:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: Problem adding ID to Generate Near Table (or next nearest)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/problem-adding-id-to-generate-near-table-or-next/m-p/215667#M7389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This started off as being elegant...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import arcpy module
import arcpy

# Parameters
input = "C:\\some feature class"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #input feature class
near = "C:\\some other feature class"&amp;nbsp;&amp;nbsp;&amp;nbsp; #near feature class
nearcount = "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;&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; #number of nearest features
output = "C:\\output table"&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; #output table

# Fun stuff
# Process: Generate Near Table
arcpy.GenerateNearTable_analysis(input, near, output, "", "NO_LOCATION", "NO_ANGLE", "ALL", nearcount)

# Process: Add Field
arcpy.AddField_management(output, "rank", "SHORT", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")

rows = arcpy.UpdateCursor(output,"","","","IN_FID A; NEAR_DIST A")

count = 0

for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if count == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curID = row.IN_FID
&amp;nbsp;&amp;nbsp;&amp;nbsp; count = count + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.IN_FID != curID:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curID = row.IN_FID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.RANK = count
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
del row
del rows&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:34:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/problem-adding-id-to-generate-near-table-or-next/m-p/215667#M7389</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T10:34:06Z</dc:date>
    </item>
  </channel>
</rss>

