Select to view content in your preferred language

compare two geometries in same feature class

2670
11
01-20-2020 03:59 PM
QuangTruong
Emerging Contributor

Hi, I need to compare two features in the same feature class. I'd like to test to see if they intersect. Specifically, I have a feature set composed of lines, and I'd like to know if any given two are intersecting. What is a quick and easy way to do this? 

0 Kudos
11 Replies
JoshuaBixby
MVP Esteemed Contributor

As nice as it is to not have to create another feature class, often times it can be much more straightforward to just create one (possibly just in memory).  Have you looked at the Pairwise Intersect—Help | ArcGIS Desktop :

 Pairwise intersection refers to selecting one feature from the first input and intersecting it with all those features in the second input that it overlaps.

The Pairwise Intersect tool is similar to the Intersect tool in that geometric intersections are computed, but it is significantly different in that intersections are computed on pairs of features rather than all combinations of features. You may find this tool useful in situations where the Intersect tool results in an output with many more features than were input 

0 Kudos
DanPatterson_Retired
MVP Emeritus

Take a polygon/polyline with 5 points, the first and last are repeated, since it is a closed loop, if the points are sequential and not made up of individual segments.  You can't tell this by visual inspection.

Four points, made into 4 segments, hence duplication in points.

Arrange the points as either 4 sequential numbers or pairs of two numbers.

As the question? 

Which segments does a particular point (eg (1.5, 1.5) in the lower left) belong to?  A little query magic (details depend on how you want to implement this) and it is visually obvious and the query supports that the point belongs to the first and last segment.

Now... There is no `tool` that does this, but you can get at the numbers if you can dissociate the lines to segments if they already aren't segments.... then get the points of the segments.  From there it is a `query`.

I did all of this in python and numpy, but it can be done with featureclasses and tables and arcpy if needed.

Original points : clockwise from lower-left 
In [1]: s00
Out[1]: 
array([[ 1.50,  1.50],
       [ 0.00,  10.00],
       [ 10.00,  10.00],
       [ 10.00,  0.00],
       [ 1.50,  1.50]])‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

From-to points for the 4 segments

In [2]: fr_to
Out[2]: 
array([[ 1.50,  1.50,  0.00,  10.00],
       [ 0.00,  10.00,  10.00,  10.00],
       [ 10.00,  10.00,  10.00,  0.00],
       [ 10.00,  0.00,  1.50,  1.50]])‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
In [3]: fr_to.reshape(-1, 2, 2)
Out[3]: 
array([[[ 1.50, 1.50],
        [ 0.00, 10.00]],
       [[ 0.00, 10.00],
        [ 10.00, 10.00]],
       [[ 10.00, 10.00],
        [ 10.00, 0.00]],
       [[ 10.00, 0.00],
        [ 1.50, 1.50]]])‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

# ---- case 1...
# Is the first point (s00[0] = [1.5, 1.5]) in the fr_to list???
# This is a `boolean` question, so 1 indicates True and 0, False

array([[1, 1, 0, 0],  yes, it is the first point of the first segment
       [0, 0, 0, 0],
       [0, 0, 0, 0],
       [0, 0, 1, 1]]) and the last point of the last segment

# ---- case 2
# Same question but shown as a structure that organizes by point pairs 
array([[[1, 1],     first point first segment
        [0, 0]],
       [[0, 0],
        [0, 0]],
       [[0, 0],
        [0, 0]],
       [[0, 0],
        [1, 1]]])  last point last segment‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

0 Kudos