<?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 analysis fails in Python Snippets Questions</title>
    <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852069#M557</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan,&lt;/P&gt;&lt;P&gt;I really appreciate your advice!&amp;nbsp;The mdb is because, further on in the script, I export the tables from the altered ACN_Select to this mdb. I removed that from the script above, because it would make it confusing. But forgot to remove it as workspace.&lt;/P&gt;&lt;P&gt;However, I changed it to gdb for the results of the near_analysis, but the problem with the NEAR_FID and NEAR_DIST remain the same... So strange: it works fine in the Python window in ArcMap.&lt;/P&gt;&lt;P&gt;By the way, ACN_Select contains points and Derden contains lines. I try to get the distance from each point to the nearest line feature, being restricted to points within 150 meters froma line feature.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 20 Jul 2017 10:23:22 GMT</pubDate>
    <dc:creator>TinaOosterom1</dc:creator>
    <dc:date>2017-07-20T10:23:22Z</dc:date>
    <item>
      <title>arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852065#M553</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When I run &amp;gt;&amp;gt;&amp;gt;arcpy.Near_analysis("ACN_Select","Derden","150 Meters", "NO_LOCATION", "NO_ANGLE","PLANAR") in the python window in ArcMap 10.4, it returns the correct numbers in the field NEAR_DIST.&lt;IMG alt="Results in ArcMap10.4" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/363376_NearInMap.JPG" style="width: 620px; height: 64px;" /&gt;&lt;/P&gt;&lt;P&gt;However, if I run the same in PyScripter:&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;arcpy.env.workspace = "C:\\Geoplay\\GLO\\Output.mdb"&lt;BR /&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if arcpy.CheckExtension("Spatial") == "Available":&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Checking out Spatial")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CheckOutExtension("Spatial")&lt;BR /&gt;else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError("Unable to get spatial analyst extension")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(arcpy.GetMessages(0))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sys.exit(0)&lt;/P&gt;&lt;P&gt;ACN_Select = "C:\\Geoplay\\GLO\\GLO.gdb\\ACN_Select"&lt;BR /&gt;Derden = "C:\\Geoplay\\GLO\\GLO.gdb\\Derden"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#Near Analysis&lt;BR /&gt;arcpy.Near_analysis(ACN_Select,Derden,"150 Meters","NO_LOCATION","NO_ANGLE","PLANAR")&lt;/P&gt;&lt;P&gt;print "Ready!"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All the NEAR_FID and NEAR_DIST are -1.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Results from PyScripter" class="image-2 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/363398_NearInScripter.JPG" style="width: 620px; height: 41px;" /&gt;&lt;/P&gt;&lt;P&gt;I tried creating layers and using those, but it didn't work. Also I tried setting the spatial ref with&lt;/P&gt;&lt;P&gt;spatRef = arcpy.Describe(ACN_in).spatialReference&lt;/P&gt;&lt;P&gt;but it did not change anything.&lt;/P&gt;&lt;P&gt;What am I missing?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jul 2017 13:48:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852065#M553</guid>
      <dc:creator>TinaOosterom1</dc:creator>
      <dc:date>2017-07-19T13:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852066#M554</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Confirm the coordinate systems of both files.&amp;nbsp; Projection on the fly doesn't occur in standalone scripts since the data are not in a data frame&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jul 2017 14:28:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852066#M554</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-07-19T14:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852067#M555</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan, thanks for your suggestion. I did and they are both RD New (Dutch system) in the gdb. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2017 05:34:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852067#M555</guid>
      <dc:creator>TinaOosterom1</dc:creator>
      <dc:date>2017-07-20T05:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852068#M556</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;C:\\Geoplay\\GLO\\Output.mdb&amp;nbsp; **** mdb&amp;nbsp; should this be gdb???&lt;/P&gt;&lt;P&gt;if that isn't the issue don't specify any of the other optional parameters in the script since -1 means nothing was found.&lt;/P&gt;&lt;P&gt;This again assumes all files are within the extent and any selections are within the distance specified, so try not to limit the distance or increase it until you know it works&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2017 07:53:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852068#M556</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-07-20T07:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852069#M557</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan,&lt;/P&gt;&lt;P&gt;I really appreciate your advice!&amp;nbsp;The mdb is because, further on in the script, I export the tables from the altered ACN_Select to this mdb. I removed that from the script above, because it would make it confusing. But forgot to remove it as workspace.&lt;/P&gt;&lt;P&gt;However, I changed it to gdb for the results of the near_analysis, but the problem with the NEAR_FID and NEAR_DIST remain the same... So strange: it works fine in the Python window in ArcMap.&lt;/P&gt;&lt;P&gt;By the way, ACN_Select contains points and Derden contains lines. I try to get the distance from each point to the nearest line feature, being restricted to points within 150 meters froma line feature.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2017 10:23:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852069#M557</guid>
      <dc:creator>TinaOosterom1</dc:creator>
      <dc:date>2017-07-20T10:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852070#M558</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is why I wanted to see if it worked without the distance restriction.&amp;nbsp; If it still doesn't, then the problem lies elsewhere&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Jul 2017 15:02:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852070#M558</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-07-20T15:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852071#M559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What if you strip the script way down and run it directly from the Python interpreter, not through PyScripter?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy

ACN_Select &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"C:\\Geoplay\\GLO\\GLO.gdb\\ACN_Select"&lt;/SPAN&gt;
Derden &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"C:\\Geoplay\\GLO\\GLO.gdb\\Derden"&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;#Near Analysis&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Near_analysis&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;ACN_Select&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;Derden&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"150 Meters"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"NO_LOCATION"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"NO_ANGLE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"PLANAR"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 10:29:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852071#M559</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-12T10:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852072#M560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joshua,&lt;/P&gt;&lt;P&gt;Thanks for responding. It took me a while to find Python command line and how to copy the text, but I did. It ran very quickly indeed, but with the same results. It does makes the fields NEAR_FID and NEAR_DIST, but fills them both with "-1". &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jul 2017 06:40:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852072#M560</guid>
      <dc:creator>TinaOosterom1</dc:creator>
      <dc:date>2017-07-21T06:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852073#M561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan, I removed the "150 Meters" and ran it through the Python command line and... the fields were filled. However, the numbers within the NEAR_DIST make no sense. Like the first row in my example is 149 meters, in the new table this comes down to 3145. I tried to find which unit would translate from this figure to the other, but çan't find it.&lt;/P&gt;&lt;P&gt;So it seems that in the map view the distance limiter works, because the distance unit of the map and the feature classes is meters, as it should be with RD New. But somehow, when the script is ran outside the map, it starts using different distance units (different projection ?). So perhaps I should look into setting the projection right in the script?&lt;/P&gt;&lt;P&gt;Also the NEAR_FiD is different. Which is strange, because, no matter which coordinate system one would use, the line closest to my point should remain the same. Shouldn't it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jul 2017 07:18:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852073#M561</guid>
      <dc:creator>TinaOosterom1</dc:creator>
      <dc:date>2017-07-21T07:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852074#M562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the point closest to feature will not necessarily remain the same... if one is in decimal degrees and the other is in meters since the planar distance between two locations in decimal degrees is not constant but decrease as you head poleward.&lt;/P&gt;&lt;P&gt;At this stage, perhaps one of the files has been 'defined' wrong.&amp;nbsp; The only way that you can confirm this is to examine the layer extents.&amp;nbsp; I confirm visually by inserting a new data frame then add one file to it and examine its properties through the properties dialog and visually on the map.&amp;nbsp; delete that data frame and repeat with a new dataframe and layer.&amp;nbsp; If the extent indicates that the layer is in decimal degrees (-180 to 180 and -90 to 90 for X and Y ranges at most) but the file has been defined wrong, then you have to correct the definition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On the other side, what if one file's coordinates were in meters and the other in feet? The numbers look like they are projected, but their values will be scaled by the conversion from feet to meters.&amp;nbsp; How to resolve? same process and see where it lands up on a map.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Subtle differences in projection can cause issues.&amp;nbsp; In my area, UTM and MTM are commonly used and it is not uncommon for them to be defined wrong or read wrong... To solve? same process and examine where they fall on the earth relative to where they should be.. Oh yes, there are imperial and metric versions for both.&amp;nbsp; A simple drop of a few bits of information when defining the coordinate system makes a huge difference.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In short, just because the definition of a file says it IS something, it doesn't mean that IT IS what it purports to be.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jul 2017 09:38:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852074#M562</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-07-21T09:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852075#M563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I found out about the differences in distances. I am working with a map document that is stored on a share. One of my colleagues has been working with it too and imported the old &amp;nbsp;Derden FC in the gdb. The layer in the map, however, was the latest one. So everytime I used the layer, the distances were smaller, because this layer is more complete than the FC in the gdb and in this layer there are lines closer to ACN_Select. Sorry for wasting your time on this. I learned a lot, though. &lt;/P&gt;&lt;P&gt;I guess we must conclude that the distance limiter in the Near_analysis does not work for me, but I can live with that. I can filter the ones within 150 meters afterwards.&lt;/P&gt;&lt;P&gt;Thank you so much for your input. I would never have found all this without your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jul 2017 12:12:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852075#M563</guid>
      <dc:creator>TinaOosterom1</dc:creator>
      <dc:date>2017-07-21T12:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852076#M564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No problem Tina... glad a solution was found in the end&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jul 2017 12:25:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852076#M564</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-07-21T12:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy near analysis fails</title>
      <link>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852077#M565</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And because the more recent FC has lines near ACN_Select, even the distance limiter now works. Thanks so much, Dan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Jul 2017 12:30:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/arcpy-near-analysis-fails/m-p/852077#M565</guid>
      <dc:creator>TinaOosterom1</dc:creator>
      <dc:date>2017-07-21T12:30:28Z</dc:date>
    </item>
  </channel>
</rss>

