I need help with some python in selecting correct input and near feature classes in Near Table analysis.
The project aim is to run Near Table Analysis (distance) on point locations collected at time 1[day] and time2[night].
I have managed to group the files I want to input into each iteration of the model based on filename and Year using groupby with the first 0:26 characters in the file name (all files are in the same directory).
My problem is I need to separate the inputs for the GenerateNearTable Tool into in_features (Day) and near_features (Night). So split each group again into Day and Night files.
Here is my code.
import arcpy, itertools, os
# Define the input and output workspaces
arcpy.env.workspace = r"C:\Users\Jenny\roos"
outws = r"C:\Users\Jenny\roos\gmehome.gdb"
# List the fcs in your workspace
my_pts = arcpy.ListFeatureClasses()
# Group the items based on first 26 characters
grouped = [list(g) for _, g in itertools.groupby(sorted(my_pts), lambda x: x[0:26])]
# Loop over the groups and perform the NearTable operation
for group in grouped:
groupedDay = ?
groupedNight = ?
outname = group[0][:26] + "_DayNightDist"
arcpy.GenerateNearTable_analysis(in_features=groupedDay, near_features=groupedNight, out_table= outname, search_radius="", location="NO_LOCATION", angle="NO_ANGLE", closest="ALL", closest_count="0", method="PLANAR")
Other useful information is the file names
[[Jenxxx_Annual_HR_Poly_Yr1Day_SCV, Jenxxx_Annual_HR_Poly_Yr1Night_SCV] [Jenxxx_Annual_HR_Poly_Yr2Day_SCV, Jenxxx_Annual_HR_Poly_Yr2Night_SCV], [Barry_Annual_HR_Poly_Yr1Day_SCV, Barry_Annual_HR_Poly_Yr1Night_SCV]] (and so on)