<?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: ArcPy: Near tool fails second iteration in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370769#M16282</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interesting.&amp;nbsp; The selection &lt;STRONG&gt;is&lt;/STRONG&gt; working just fine.&amp;nbsp; &lt;/P&gt;&lt;P&gt;I can only guess that the underscore is being treated as a wildcard.&amp;nbsp; The table has fields integer "park_" and string "park", but no other fields with the word "park...".&amp;nbsp; Could it be it is selecting from the intended field and not getting confused only because there is no alternative?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 25 Apr 2016 17:03:35 GMT</pubDate>
    <dc:creator>DavidTreering</dc:creator>
    <dc:date>2016-04-25T17:03:35Z</dc:date>
    <item>
      <title>ArcPy: Near tool fails second iteration</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370765#M16278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using ArcPy in ArcGIS Pro 1.2, I have a da.SearchCursor for loop that selects a single city park feature per iteration, and runs the Near tool for points within a specified radius.&lt;/P&gt;&lt;P&gt;In the first iteration, the Near tool completes successfully, but it fails on the second iteration.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;map = aprx.listMaps("Layers")[0]
lyrs = map.listLayers()
lyr_Park = [lyrs[0]]
fcs_Crime = [lyrs[1],lyrs[2],lyrs[3],lyrs[4],lyrs[5],lyrs[6]]


for lyr_Crime in fcs_Crime:
&amp;nbsp; crime_type = lyr_Crime.name

&amp;nbsp; pCursor = arcpy.da.SearchCursor(lyr_Park[0], ['park_'])

&amp;nbsp; for park in pCursor:
&amp;nbsp; park_name = str(park[0])
&amp;nbsp; expression1 = "park_="+ park_name

&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr_Park[0], "NEW_SELECTION", expression1)
&amp;nbsp; arcpy.SelectLayerByLocation_management (lyr_Crime, "WITHIN_A_DISTANCE", lyr_Park[0], '1320 feet', 'NEW_SELECTION' )

&amp;nbsp; arcpy.FeatureClassToFeatureClass_conversion (lyr_Crime,"C:\\Users\\dgoldb2\\Documents\\ArcGIS\\Projects\\Crime_Parks_Relationship\\Crime_Parks_Relationship.gdb", "p" + park_name + "_" + crime_type)
&amp;nbsp; park_crimes = arcpy.ListFeatureClasses("p" + park_name + "_" + crime_type, "Point")

&amp;nbsp; print (("p" + park_name + "_" + crime_type))


&amp;nbsp; arcpy.Near_analysis(park_crimes[0], lyr_Park[0], "492 Meters", "LOCATION", "NO_ANGLE")


print ("Finished")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the error:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Runtime error 
Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;string&amp;gt;", line 44, in &amp;lt;module&amp;gt;
&amp;nbsp; File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\analysis.py", line 1162, in Near
&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e
&amp;nbsp; File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\analysis.py", line 1159, in Near
&amp;nbsp;&amp;nbsp;&amp;nbsp; retval = convertArcObjectToPythonObject(gp.Near_analysis(*gp_fixargs((in_features, near_features, search_radius, location, angle, method), True)))
&amp;nbsp; File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 500, in &amp;lt;lambda&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 999999: Error executing function.
Failed to execute (Near).&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have looked carefully at the &lt;STRONG&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;in_features&lt;/SPAN&gt; &lt;/STRONG&gt;and &lt;STRONG&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;near_features&lt;/SPAN&gt; &lt;/STRONG&gt;to be sure they are both of type "Layer".&amp;nbsp; Near runs the first iteration, which tells me the types are fine, but fails the second iteration, which tells me something is not progressing in the loop.&amp;nbsp; Any ideas are welcome.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:10:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370765#M16278</guid>
      <dc:creator>DavidTreering</dc:creator>
      <dc:date>2021-12-11T17:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy: Near tool fails second iteration</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370766#M16279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried restarting ArcGIS since your problem started? My understanding of cursor syntax is that you should use 'with...' notation because it automatically cleans up your cursor, even if it errors out. Without it, if you make a run that ends in an error, your cursor can get stuck in memory until you delete it with a 'del' statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try restating ArcGIS and change your cursor to something like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;with arcpy.da.SearchCursor(lyr_Park[&lt;SPAN class="number" style="font-weight: inherit; font-style: inherit; color: green; font-size: 9pt !important; background-color: inherit;"&gt;0&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;], [&lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;'park_'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;]) as pCursor:&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; park &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; pCursor:&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, certainly just a copy/paste/formatting error, but everything after 'for park in pCursor' should be indented.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:10:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370766#M16279</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T17:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy: Near tool fails second iteration</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370767#M16280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Forgoing the SearchCursor discussion for a minute, something seems off with Line 14, i.e., I am surprised your Select Layer by Attribute in Line 16 works because you need to escape strings in WHERE clauses and I don't see that being done in Line 14.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Apr 2016 15:28:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370767#M16280</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2016-04-23T15:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy: Near tool fails second iteration</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370768#M16281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is definitely good to know.&amp;nbsp; I've switch the cursor syntax and also run "del pCursor" after every run.&lt;/P&gt;&lt;P&gt;The indentation was just a pasting error, as you assumed.&lt;/P&gt;&lt;P&gt;The issue with the Near tool is unresolved.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Apr 2016 16:59:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370768#M16281</guid>
      <dc:creator>DavidTreering</dc:creator>
      <dc:date>2016-04-25T16:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy: Near tool fails second iteration</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370769#M16282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interesting.&amp;nbsp; The selection &lt;STRONG&gt;is&lt;/STRONG&gt; working just fine.&amp;nbsp; &lt;/P&gt;&lt;P&gt;I can only guess that the underscore is being treated as a wildcard.&amp;nbsp; The table has fields integer "park_" and string "park", but no other fields with the word "park...".&amp;nbsp; Could it be it is selecting from the intended field and not getting confused only because there is no alternative?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Apr 2016 17:03:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370769#M16282</guid>
      <dc:creator>DavidTreering</dc:creator>
      <dc:date>2016-04-25T17:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy: Near tool fails second iteration</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370770#M16283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;did you change your query to exclude _ and then append it to the output name later if you need it.&amp;nbsp; The underscore in the query is a wildcard and I haven't got a file to check to see if "park" versus "park_" will only return 4 or 5 character cases&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/arcmap/latest/map/working-with-layers/building-a-query-expression.htm" title="http://desktop.arcgis.com/en/arcmap/latest/map/working-with-layers/building-a-query-expression.htm"&gt;Building a query expression—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Apr 2016 20:20:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-near-tool-fails-second-iteration/m-p/370770#M16283</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-04-25T20:20:52Z</dc:date>
    </item>
  </channel>
</rss>

