# Is there a way to calculate closest distances to a point without using Near Analysis?

I frequently get asked to calculate distances from a specific point (A drilling well in the middle of the sea for example) to a number of Environmental layers (Protected Areas, Pipelines, Other wells etc, so would include points, lines and polygons). I currently do it manually which takes time so I thought there could be a way to automate this using python. It seems the best way to do this is use Near Analysis, which I do not have licence for.

I was just wondering is there anyway to use python to still generate some sort of table that would give me the closest distances from my input feature to my numerous environmental features, the names of said closest features, and the distance (and also direction if possible, but thats not essential).

Any ideas?

-
Take a look at Vincenty's formulae for some useful information – Lijo Aug 19 '14 at 18:43

Do a spatial join!

First, set up your data frame in a projected coordinate system of your choice (whatever units you want your distances to show up in). So, say you're working in State Plane Feet, make sure all your layers are in State Plane Feet, so if they're not project them into it. From there, Right click on the points layer and click Joins & Relates > Joins.... Make sure to select "Join Layer from another layer based on spatial location." In there, select your layers that you're spatially joining together in the drop down list.

Then, after selected your layer, #2 asks "You are Joining: Points to _" (Points, Lines, Polygons, whatever).

It then gives you two options, the first to give a summary of numeric attributes, and the second option says all the points will be given the attributes of the layer being joined to it, plus it will calculate a distance field. Bingo!

From there, once you run the spatial join your new shapefile will have the distances in the attribute table. Keep in mind if you don't project your shapefiles the distances might show up in decimal degrees though. I hope this helps!

-
Good one, haven't thought of this! – Alex Tereshenkov Aug 19 '14 at 13:00
Simple, yet genius! Didn't know a spatial join could do that. Thanks very much! – Ian Aug 19 '14 at 13:26
Is it possible to Join more than one at a time? the Tool isn't allowing me to select multiple ones. I'm guessing that might require a swift python modification though? – Ian Aug 19 '14 at 14:02

You could do this with arcpy. You would need to use the `distanceTo` method of the geometry class. You would need to iterate with arcpy.da.searchcursor each feature within a feature class and apply this method to each feature within another feature class. The value received as a distance is supposed to be written into an output table along with the source and destination feature IDs. An example of this is here.

Should you need to find the features located closest to a certain source feature, you can evaluate the distance values received and report the values as required.

-
It also require and advanced license. – wittich Nov 12 '15 at 11:12