AnsweredAssumed Answered

List related points through a RelationshipClass object using python?

Question asked by epsimpson on Jul 5, 2012
Latest reply on Jul 13, 2012 by epsimpson
Is there a way to retrieve a list of related points through a RelationshipClass object using python? 

I am using python in ArcMap 10.0 with an ArcInfo license.

What follows is a description of what I am trying to do, and how I tried to do it, in case anyone knows a better method.

I have a line of points - think of a moving vehicle collecting a data point every 2 seconds with lat, lon, time, and z value.  Sometimes the vehicle will travel a path and then return back along the same path.  I need to examine the points around each point to determine whether or not the points are sequential by examining the time stamps, and then apply rules to decide how to treat the points (average, max, drop, ignore, etc). 

I tried to set it up using CreateNearTable, joined the point data to the NearTable using the IN_FID, and then related the point data to the joined table using the NEAR_FID. 
import arcpy import os import string import sys import traceback from arcpy.sa import *       # Process: Make Near Table     search_radius = 100. # feet     outpath = Output_GDB     arcpy.env.workspace = outpath     arcpy.env.scratchWorkspace = outpath     arcpy.GenerateNearTable_analysis (v_Output_Name_route, v_Output_Name_route, route_Near_Table, search_radius, 'LOCATION', 'NO_ANGLE' , 'ALL')       # Process: AddJoin     out_view = Output_Name + "_NT_view"     arcpy.MakeTableView_management (route_Near_Table, out_view)     arcpy.AddJoin_management (out_view, 'IN_FID', v_Output_Name_route, 'OBJECTID', 'KEEP_ALL')      # Process: Relate     outpath = Output_GDB     relat_class = Output_Name + "_rel"     arcpy.CreateRelationshipClass_management (v_Output_Name_route, route_Near_Table, relat_class,                                         'SIMPLE', 'relate_to_neartable', 'relate_from_neartable', 'NONE',                                         'MANY_TO_MANY', 'NONE', 'OBJECTID', 'NEAR_FID')

I haven't actually gotten the MANY_TO_MANY relationship table set up yet - I got ONE_TO_MANY working and discovered I couldn't find a GetRelatedPoints kind of method in arcpy.

My hope was for each starting point, iterate through it's related points, find the nearest point with an appropriate time stamp, then iterate THAT point's related points to make sure there is no point closer to IT than the starting point, continuing recursively in this manner until 2 points that are mutually closest to each other are found (or other trigger conditions are found).  I would then back track through the points to the original starting point assigning point pairs accordingly.  (The closest nonsequential point to A is B, the closest nonsequential point to B is C, the closest nonsequential point to C is D, the closest nonsequential point to D is E, and the closest nonsequential point to E is D - match D-E, match B-C, Point A remains unmatched.)

Is there a way to retrieve a list of related points through a RelationshipClass object using python?  If there were a way to gain random access to data in ArcGIS Tables rather than that silly FIFO cursor business then I could do it that way as well :).

Outcomes