Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following problem. I want to create a toolbox to obtain the distance between a polygon (Bldg.shp) and a point (pts.shp). I have started with a simple following python script:

import arcpy

arcpy.SpatialJoin_analysis(bldg, Pts, Output+".shp", "JOIN_ONE_TO_ONE", "#", "#", "CLOSEST", "#", "HorzD")

All works fine. If I try to modify it to work in a toolbox as follow:

 import arcpy

 #bldg = arcpy.GetParameterAsText(0)
 #Pts = arcpy.GetParameterAsText(1)
 #OutputShp = arcpy.GetParameterAsText(2)


 arcpy.SpatialJoin_analysis(bldg, Pts, Output+".shp", "JOIN_ONE_TO_ONE", "#", "#", "CLOSEST", "#", "HorzD")
 #arcpy.SpatialJoin_analysis(bldg, Pts, Output+".shp", "JOIN_ONE_TO_ONE", "#", "#")

Arcmap crashes without any error messages, the output file is created but is empty. If I remove the "Closest" option, the toolbox script works fine (but I don't have the distance I want)...

Does anyone experienced this and have a fix? Am I missing something?

Thanks for your help

share|improve this question

How about trying the Near tool? This will write the distance of the closest feature in a new attribute field.

share|improve this answer
Thanks for the reply, much appreciated, Near tool seems to work indeed but in my final version I also need to add few fields in pts.shp into Bldg.shp, therefore the use of SpatialJoin... Any other suggestions? – user16427 Mar 25 '13 at 13:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.