<?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 does not run in stand alone script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/near-analysis-does-not-run-in-stand-alone-script/m-p/598725#M46843</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think its because you have two if statements that write to the same object, so with the second if you are overwriting the result of the first if.&amp;nbsp;&amp;nbsp; That second statement should be an else or an elif (else if), maybe like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for fc in pDF:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fc.name == "Candidates":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nearFeatures = fc
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif fc.name == "tmp":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inFeatures = fc&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 01:42:32 GMT</pubDate>
    <dc:creator>ChristopherThompson</dc:creator>
    <dc:date>2021-12-12T01:42:32Z</dc:date>
    <item>
      <title>Near analysis does not run in stand alone script</title>
      <link>https://community.esri.com/t5/python-questions/near-analysis-does-not-run-in-stand-alone-script/m-p/598724#M46842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm using a bunch of tools in a stand alone script, and the near analysis tool does not work. Behavior is erratic, it runs from within ArcGIS only if the candidates are supplied as a string, not as a feature layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy

pMXD = arcpy.mapping.MapDocument("C:\\Proj\\BBerry.mxd")
pDF = arcpy.mapping.ListDataFrames(pMXD, "Layers")[0]

## Candidates are point feature class
for fc in pDF:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fc.name == "Candidates":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nearFeatures = fc
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fc.name == "tmp":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inFeatures = fc

## arcpy.Near_analysis(inFeatures, nearFeatures, "", "NO_LOCATION", "NO_ANGLE") ## Does not work!
arcpy.Near_analysis(inFeatures, "Candidates", "", "NO_LOCATION", "NO_ANGLE") ## Works &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The goal is to add this function to a stand alone script, but it does not work as such no matter what. Stand alone script error message is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000732: Near Features: Dataset Candidates does not exist or is not supported&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Near).[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions are welcome.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2012 16:48:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/near-analysis-does-not-run-in-stand-alone-script/m-p/598724#M46842</guid>
      <dc:creator>JuanOrozco</dc:creator>
      <dc:date>2012-09-21T16:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: Near analysis does not run in stand alone script</title>
      <link>https://community.esri.com/t5/python-questions/near-analysis-does-not-run-in-stand-alone-script/m-p/598725#M46843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think its because you have two if statements that write to the same object, so with the second if you are overwriting the result of the first if.&amp;nbsp;&amp;nbsp; That second statement should be an else or an elif (else if), maybe like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for fc in pDF:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fc.name == "Candidates":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nearFeatures = fc
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif fc.name == "tmp":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inFeatures = fc&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:42:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/near-analysis-does-not-run-in-stand-alone-script/m-p/598725#M46843</guid>
      <dc:creator>ChristopherThompson</dc:creator>
      <dc:date>2021-12-12T01:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Near analysis does not run in stand alone script</title>
      <link>https://community.esri.com/t5/python-questions/near-analysis-does-not-run-in-stand-alone-script/m-p/598726#M46844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think its because you have two if statements that write to the same object, so with the second if you are overwriting the result of the first if.&amp;nbsp;&amp;nbsp; That second statement should be an else or an elif (else if), maybe like this:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for fc in pDF:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fc.name == "Candidates":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nearFeatures = fc
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif fc.name == "tmp":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inFeatures = fc&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the response. It did not make a difference since the loop checks all feature layers names and sets variables depending on the layer's name anyway.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The error message when passing &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;feature layers &lt;/SPAN&gt;&lt;SPAN&gt;instead of &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;string&lt;/SPAN&gt;&lt;SPAN&gt; like I did in my first posting is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]&amp;nbsp; File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\analysis.py", line 794, in Near&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;raise e&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcgisscripting.ExecuteError: ERROR 999999: Error executing function.[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Someone mentioned the possibility of near analysis and at least other tool being buggy. I think I'll write my own near function and stop wasting time.&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>Sun, 12 Dec 2021 01:42:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/near-analysis-does-not-run-in-stand-alone-script/m-p/598726#M46844</guid>
      <dc:creator>JuanOrozco</dc:creator>
      <dc:date>2021-12-12T01:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Near analysis does not run in stand alone script</title>
      <link>https://community.esri.com/t5/python-questions/near-analysis-does-not-run-in-stand-alone-script/m-p/598727#M46845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Solved, the near features must be passed in a list (Tool's documentation and tool examples suck). Now that the near features are inside brackets it runs as stand-alone script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

pMXD = arcpy.mapping.MapDocument("C:\\Proj\\BBerry.mxd")
pDF = arcpy.mapping.ListDataFrames(pMXD, "Layers")[0]

## Candidates are point feature class
for fc in pDF:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fc.name == "Candidates":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nearFeatures = fc
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fc.name == "tmp":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; inFeatures = fc

arcpy.Near_analysis(inFeatures, [nearFeatures], "", "NO_LOCATION", "ANGLE")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rule of thumb, if a tool takes multiple inputs for a given parameter pass them in a list even if you have just one item.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:42:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/near-analysis-does-not-run-in-stand-alone-script/m-p/598727#M46845</guid>
      <dc:creator>JuanOrozco</dc:creator>
      <dc:date>2021-12-12T01:42:38Z</dc:date>
    </item>
  </channel>
</rss>

