0
for i in range (1,7):
layer="s"+str(i)
arcpy.Near_analysis(layer,"Wall")

I have 6 layers labelled s1 to s6 representing 6 points. I'm using Near_analysis to calculate shortest distance of the points to a line. The first iteration returns a correct value for Near_dist. However, the second iteration changes the Near_dist value of previous layer to -1. Finally, only the last layer has the correct value and the others have -1

1
  • Can you provide more details of your inputs and expected outputs, perhaps including a picture, please?
    – PolyGeo
    Commented Oct 14, 2016 at 11:11

1 Answer 1

2

I think you need to indent the lines after the for loop:

for i in range (1,7):
    layer="s"+str(i)
    arcpy.Near_analysis(layer,"Wall")
2
  • The indentation was fine. The loop executed for all the values. For some reason, it is changing the previous value during each iteration. I can even see the change from correct value to -1 as it progresses.
    – K_D
    Commented Oct 14, 2016 at 9:32
  • 2
    It seems when you paste your code in your question, it was not pasted correctly. You should use the code block {} to avoid any trouble in displaying the code. You can edit your question any time to reflect the problem with the correct code that you have.
    – ahmadhanb
    Commented Oct 14, 2016 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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