1

I'd like to us the arcpy.GANeighborhoodSelection_ga in a loop where the point coords would come from a different source. What I tried already: If I define the coords, it works:

pointcoord = "689383.6885 3973775.2178"
arcpy.GANeighborhoodSelection_ga(inFile2, "neighbor", pointcoord, "1", "1","20", "20", "0", "One sector")
Result 'neighbor'

When I try to use variable for the coords I got error:

pointcoord = x, y
print pointcoord
(689383.6885, 3973775.2178)
arcpy.GANeighborhoodSelection_ga(inFile2, "neighbor",  pointcoord , "1", "1","20", "20", "0", "One sector")
Runtime error 
Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\ga.py", line 1075, in GANeighborhoodSelection
        raise e
    RuntimeError: Object: Error in executing tool



pointcoord = "\"" + x + ' ' + y + "\""
Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'float' objects



pointcoord = "\"" + str(x) + ' ' + str(y) + "\""
print pointcoord
"689383.6885 3973775.2178"
arcpy.GANeighborhoodSelection_ga(inFile2, "neighbor", pointcoord, "1", "1","20", "20", "0", "One sector")
Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module>   File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\ga.py", line 1075, in GANeighborhoodSelection     raise e ExecuteError: ERROR 000622: Failed to execute (Neighborhood Selection). Parameters are not valid. ERROR 000628: Cannot set input into parameter point_coord. 
  • Depending on how you are getting your point coordinates, it might be more straightforward to pass a Point object instead of a string representation. – Paul Oct 14 '15 at 22:56
3

In Python, pointcoord = x, y creates a tuple while the Neighborhood tool calls for a string of two numbers seperated by one space. "689383.6885 3973775.2178" which worked does not equal the tuple (689383.6885, 3973775.2178) which is unacceptable.

What you need it to concat the coordinates and add a space between them, and for that to work you need to cast them as strings first. You almost had it in the third one, this one will work though:

pointcoord = str(x) + " " + str(y)
  • Alternatively, "{} {}".format(x,y). – Paul Oct 14 '15 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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