2

Created a script for Near Analysis, but my distance field, whenever calculated produces values from the Geographic Coordinate System that my features were produced through. I read that if you set the method to geodesic, it will instead let you do miles which is what I want. However, when I try doing that, I get an error. Is there something wrong with the way I wrote my code?

This is it:

import arcpy
import sys

inFc = sys.argv[1]
nearFc = sys.argv[2]
distance = sys.argv[3]

arcpy.Near_analysis(inFc, nearFc, distance, "Geodesic")
2

Geodesic takes into account the curvature of the Earth based on a spheroid, as opposed to Planar which uses Pythagorean theorem to calculate distance based solely on XY position differences. What you want to do is specify units with your "distance" variable.

The reason for the error is that there are two optional parameters before "GEODESIC" that are skipped in your code, so "Geodesic" is actually being set in the position for the "LOCATION" input parameter.

Try this:

import arcpy
import sys

inFc = sys.argv[1]
nearFc = sys.argv[2]
distance = sys.argv[3]
distance_input = str(distance) + ' Miles'

arcpy.Near_analysis(inFc, nearFc, distance_input, "NO_LOCATION", "NO_ANGLE", "GEODESIC")

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.