Python is all about combining many operations into one. In the script below, I iterate through feature classes in a workspace. For each, I iterate through a list of other feature classes to perform a near analysis on. I perform the near analysis, and with a little help of a dictionary as well as field calculate, I transfer the results into new fields. Finally, after performing the multiple near analyses I copy the feature class with feature class to feature class.
Try something like this:
import arcpy # Import arcpy module
import os
#features to which distance will be calculated
RoadnearFeature_shp = r'C:\GIS route network\road.shp'
TrainnearFeature_shp = r'C:\GIS route network\train.shp'
restnearFeature_shp = r'C:\GIS route network\restaurant.shp'
outLocation = r"C:\GISStuff"
#Dictionary for field name assignment
di = {}
di [RoadnearFeature_shp] = "ROAD"
di [TrainnearFeature_shp] = "TRAIN"
di [restnearFeature_shp] = "REST"
addedfields = []
# path where all my point shp files are kept
arcpy.env.workspace = r'C:\ArcGIS sample data'
# looping through all the files
for file in arcpy.ListFeatureClasses ():
for NearFC in [RoadnearFeature_shp, TrainnearFeature_shp, restnearFeature_shp]:
#Perform analysis
arcpy.Near_analysis(file, NearFC, "30 Meters", "LOCATION", "ANGLE")
#Add fields to store near analysis results
arcpy.AddField_management (file, di[NearFC] + "_ID", "LONG")
arcpy.AddField_management (file, di[NearFC] + "_DIST", "DOUBLE")
#Calculate fields
arcpy.CalculateField_management (file, di[NearFC] + "_ID", "!NEAR_FID!", "PYTHON_9.3")
arcpy.CalculateField_management (file, di[NearFC] + "_DIST", "!NEAR_DIST!", "PYTHON_9.3")
#Delete fields from analysis
arcpy.DeleteField_management (NearFC, "NEAR_FID")
arcpy.DeleteField_management (NearFC, "NEAR_DIST")
#Track fields that have been added
addedfields.append (di[NearFC] + "_ID")
addedfields.append (di[NearFC] + "_DIST")
#Analysis done. Copy feature class
filepath = os.path.join (r'C:\ArcGIS sample data', file)
NewName = file[:-4] + "_Near.shp"
arcpy.FeatureClassToFeatureClass_conversion (filepath, outLocation, NewName)
#Optional
#Delete analysis fields from original feature class
for field in addedfields:
arcpy.DeleteField_management (filepath, field)
Best Answer
With the spatial join, you will get the distance between each point and the closest line.
If you also need the coordinates of the points on the line with the "basic" tools, you can then draw a buffer with a radius equal to the point/line distance, then intersect the buffer and the line with point output. To complete your task, the field calculator can be used to get the points coordinates, and you can finally join the attribute tables of the original and the new points.
As a remark, the exact tangent could be missed due to precision error. in this case, take a slightly larger buffer radius than the point/line distance and compute the average of the X and Y coordinates of the two resulting points.