I have 2000+ point shape files. These are all GPS tracks. I want to calculate the distance from each point to the nearest feature (road, train line, restaurant etc) within a 30 meter radius. I am using Near feature from proximity analysis in ArcGIS. I am facing two problems.
- Using batch processing one can add as many input rows in Near feature tool box as s/he wants. But this requires selecting each file
one by one which is time consuming especially when there are thousands
of files. So I tried using a python scripting as follows. But after
processing the result is written in the same file. I want to write the
table separately. How can I do that?- In case I want to add different columns for each features say road, train network for each point record in a file using near feature
how can I do that?
Currently, I am using the following python code but all the output are generated on the current file. I want to write it separately (I mean I want to generate a new table/file after near_analysis)
import arcpy # Import arcpy module
# path where all my point shp files are kept
arcpy.env.workspace = r'C:\ArcGIS sample data\'
#feature to which distance will be calculated
nearFeature_shp = 'C:\\GIS route network\\road.shp'
# looping through all the files
for file in arcpy.ListFeatureClasses ():
# Process: Near
arcpy.Near_analysis(file, nearFeature_shp , "30 Meters", "LOCATION", "ANGLE")
Best Answer
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: