Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

bldg=r"C:\0_prg_dvp\SpatialJoin\Bldg.shp"
Pts=r"C:\0_prg_dvp\SpatialJoin\pts.shp"
Output=r"C:\0_prg_dvp\SpatialJoin\Test"
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)
 #Output="C:/0_prg_dvp/SpatialJoin/"+OutputShp

 bldg=r"C:\0_prg_dvp\SpatialJoin\Bldg.shp"
 Pts=r"C:\0_prg_dvp\SpatialJoin\pts.shp"
 Output=r"C:\0_prg_dvp\SpatialJoin\Test3"


 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

1 Answer 1

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

 
discard

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.