AnsweredAssumed Answered

arcpy near analysis fails

Question asked by TinaEsri on Jul 19, 2017
Latest reply on Jul 21, 2017 by TinaEsri

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?

Outcomes