Python: Add Spatial Query Support for Graph Nodes and Segments

269
0
08-15-2017 06:00 AM
Status: Open
deleted-user-F36TjxlqdCoV
New Contributor II

If there was a way to quickly determine what are the graph nodes and graph segments withing a given distance, irrespective of connectivity.

Proposed Workflow

1) Create a Spatial Query Object

spatialQuery = ce.createSpatialQuery()

2) Add Objects to Spatial Query

spatialQuery.addItems( list_of_graph_nodes    )
spatialQuery.addItems( list_of_graph_segments )
spatialQuery.addItems( list_of_graph_layers   )

3) Parameterize Spatial Query

spatialQuery.setDistance( float )
spatialQuery.setExtents( minx = None , # determine by distance
                         miny = -10  ,
                         minz = None , # determine by distance
                         maxx = None , # determine by distance
                         maxy = 10   ,
                         maxz = None ) # determine by distance

spatialQuery.setFilters( ce.isGraphNode, ce.isGraphSegment )
spatialQuery.setMaxItems( 10 )

4) Execute Query

resultList = spatialQuery.execute( x, y, z )
or
resultList = spatialQuery.execute( aGraphNodeInstance )
or
resultList = spatialQuery.execute( aGraphNodeSegment )

print len( [ ce.isGraphNode( x )    for x in resultList ] ), 'Graph Nodes'
print len( [ ce.isGraphSegment( x ) for x in resultList ] ), 'Graph Segments'
> 40 Graph Nodes
> 34 Graph Segments

# the output is sorted by distance, closest to farest

# closest to queried coord/element
print resultList[0]

# farest to queried coord/element
print resultList[-1]

5) if a graphSegment is passed as query location, we could potentially have a mode where it uses its associat. ed graph nodes as query location, or use its centroid, where this decision could be controlled by a spatial query execution argument

6) if a list of elements is passed ( graph nodes, graph segments or tuple[3] ), the centroid position of all elements would be considered.