arcpy near analysis fails

2667
12
Jump to solution
07-19-2017 06:48 AM
TinaOosterom1
New Contributor II

When I run >>>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.Results in ArcMap10.4

However, if I run the same in PyScripter:

import arcpy
arcpy.env.workspace = "C:\\Geoplay\\GLO\\Output.mdb"
arcpy.env.overwriteOutput = True


if arcpy.CheckExtension("Spatial") == "Available":
    arcpy.AddMessage("Checking out Spatial")
    arcpy.CheckOutExtension("Spatial")
else:
    arcpy.AddError("Unable to get spatial analyst extension")
    arcpy.AddMessage(arcpy.GetMessages(0))
    sys.exit(0)

ACN_Select = "C:\\Geoplay\\GLO\\GLO.gdb\\ACN_Select"
Derden = "C:\\Geoplay\\GLO\\GLO.gdb\\Derden"


#Near Analysis
arcpy.Near_analysis(ACN_Select,Derden,"150 Meters","NO_LOCATION","NO_ANGLE","PLANAR")

print "Ready!"

All the NEAR_FID and NEAR_DIST are -1.

Results from PyScripter

I tried creating layers and using those, but it didn't work. Also I tried setting the spatial ref with

spatRef = arcpy.Describe(ACN_in).spatialReference

but it did not change anything.

What am I missing?

Tags (2)
0 Kudos
12 Replies
TinaOosterom1
New Contributor II

And because the more recent FC has lines near ACN_Select, even the distance limiter now works. Thanks so much, Dan.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

What if you strip the script way down and run it directly from the Python interpreter, not through PyScripter?

import arcpy

ACN_Select = "C:\\Geoplay\\GLO\\GLO.gdb\\ACN_Select"
Derden = "C:\\Geoplay\\GLO\\GLO.gdb\\Derden"

#Near Analysis
arcpy.Near_analysis(ACN_Select,Derden,"150 Meters","NO_LOCATION","NO_ANGLE","PLANAR")
0 Kudos
TinaOosterom1
New Contributor II

Hi Joshua,

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".

0 Kudos