Identify lines starting from the same point and select the one with the shortest length.

813
2
Jump to solution
05-18-2019 12:58 PM
FidelTedla
New Contributor III

I have multiple polylines in a layer. I want to do the following:

  • I want to identify those lines that have the same starting point (I have x and y coordinates in the attribute table),
  • Then check another attribute (say length) for each line and select the line that has the shortest length
  • I want to do this for all the lines in the layer and add to the selection each time the above criteria is met until all lines in the layer are completed.

Please see attached attribute table.

Thanks

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

In your case, you can use 

Summary Statistics—Help | ArcGIS Desktop  with the 'FROM_X' field as the case field and the 'Length' field as the statistics field with Minimum as the statistics.

The reason I say this is that your coordinates for the FROM_X field have a fixed precision and there is no minor variations within a group.

Alternately, if you have large datasets and want to do this with multiple "Case" fields or combinations of them, then you can use python/numpy.

The example below just replicates Summary Statistics as an example.  So go with the above if you just need the answer for this situation, but keep the following in mind for more complex questions

----------------------------------------------

Option 2

-----------

You need ArcGIS Pro

I used the attached script, which is compilation of numpy functions that I use.

The excel spreadsheet was converted to a numpy array

The data were "split_sorted_sliced" then the minimum value ... I hope.... was extracted from each unique grouping.

array([(   1, 'Polyline', 4177356.51, 2815988.01, 4173411.99, 2814113.01, 12.65),
       (   2, 'Polyline', 4177356.51, 2815988.01, 4174411.99, 2812613.01, 13.28),
       (   3, 'Polyline', 4214933.63, 2815989.74, 4217586.99, 2813163.01, 17.79),
       (   4, 'Polyline', 4214933.63, 2815989.74, 4210935.83, 2814898.57, 24.08),
       (   5, 'Polyline', 4214933.63, 2815989.74, 4218211.99, 2813288.01, 19.05),
       ...,
       (3625, 'Polyline', 4166440.23, 2727503.75, 4163711.99, 2726938.01,  5.2 ),
       (3626, 'Polyline', 4166440.23, 2727503.75, 4165011.99, 2730038.01,  6.85),
       (3627, 'Polyline', 4166440.23, 2727503.75, 4165536.99, 2730613.01,  8.06),
       (3628, 'Polyline', 4166440.23, 2727503.75, 4166013.03, 2731025.21,  9.76),
       (3629, 'Polyline', 4166440.23, 2727503.75, 4162886.99, 2726938.01,  6.73)],
      dtype=[('OID__', '<i4'), ('Shape__', '<U8'), ('FROM_X', '<f8'), ('FROM_Y', '<f8'),
             ('TO_X', '<f8'), ('TO_Y', '<f8'), ('Length', '<f8')])‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The results were then saved to a *.csv file (also attached) which you can do with as you want.

OID__    Shape__     FROM_X        FROM_Y        TO_X          TO_Y          Length  
------------------------------------------------------------------------------------------
 000    2547  Polyline      4141898.41    2745970.71    4141698.92    2746600.77      6.19
 001    1079  Polyline      4142006.51    2780288.01    4141767.70    2781554.52     11.23
 002    2167  Polyline      4142330.62    2757361.91    4141746.65    2757429.66     45.22
 003     759  Polyline      4142820.83    2784738.96    4142436.99    2783063.01     18.13
 004    1554  Polyline      4143499.65    2758207.61    4141746.65    2757429.66    166.09
 005    1471  Polyline      4143648.58    2773185.44    4142248.58    2773994.69     17.74
 006    1582  Polyline      4143680.35    2772573.57    4142248.58    2773994.69     32.43
 007    1420  Polyline      4143931.51    2774613.01    4142457.08    2775366.21      9.30
 008    1084  Polyline      4143956.51    2781813.01    4144294.72    2783430.35     15.09
 009    1525  Polyline      4144906.51    2773738.01    4142457.08    2775366.21     19.08
 010    1132  Polyline      4144977.50    2780405.03    4141767.70    2781554.52     22.86‍‍‍‍‍‍‍‍‍‍‍‍‍

.... snip ....‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

At least this will give you an idea of one approach

View solution in original post

2 Replies
DanPatterson_Retired
MVP Esteemed Contributor

In your case, you can use 

Summary Statistics—Help | ArcGIS Desktop  with the 'FROM_X' field as the case field and the 'Length' field as the statistics field with Minimum as the statistics.

The reason I say this is that your coordinates for the FROM_X field have a fixed precision and there is no minor variations within a group.

Alternately, if you have large datasets and want to do this with multiple "Case" fields or combinations of them, then you can use python/numpy.

The example below just replicates Summary Statistics as an example.  So go with the above if you just need the answer for this situation, but keep the following in mind for more complex questions

----------------------------------------------

Option 2

-----------

You need ArcGIS Pro

I used the attached script, which is compilation of numpy functions that I use.

The excel spreadsheet was converted to a numpy array

The data were "split_sorted_sliced" then the minimum value ... I hope.... was extracted from each unique grouping.

array([(   1, 'Polyline', 4177356.51, 2815988.01, 4173411.99, 2814113.01, 12.65),
       (   2, 'Polyline', 4177356.51, 2815988.01, 4174411.99, 2812613.01, 13.28),
       (   3, 'Polyline', 4214933.63, 2815989.74, 4217586.99, 2813163.01, 17.79),
       (   4, 'Polyline', 4214933.63, 2815989.74, 4210935.83, 2814898.57, 24.08),
       (   5, 'Polyline', 4214933.63, 2815989.74, 4218211.99, 2813288.01, 19.05),
       ...,
       (3625, 'Polyline', 4166440.23, 2727503.75, 4163711.99, 2726938.01,  5.2 ),
       (3626, 'Polyline', 4166440.23, 2727503.75, 4165011.99, 2730038.01,  6.85),
       (3627, 'Polyline', 4166440.23, 2727503.75, 4165536.99, 2730613.01,  8.06),
       (3628, 'Polyline', 4166440.23, 2727503.75, 4166013.03, 2731025.21,  9.76),
       (3629, 'Polyline', 4166440.23, 2727503.75, 4162886.99, 2726938.01,  6.73)],
      dtype=[('OID__', '<i4'), ('Shape__', '<U8'), ('FROM_X', '<f8'), ('FROM_Y', '<f8'),
             ('TO_X', '<f8'), ('TO_Y', '<f8'), ('Length', '<f8')])‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The results were then saved to a *.csv file (also attached) which you can do with as you want.

OID__    Shape__     FROM_X        FROM_Y        TO_X          TO_Y          Length  
------------------------------------------------------------------------------------------
 000    2547  Polyline      4141898.41    2745970.71    4141698.92    2746600.77      6.19
 001    1079  Polyline      4142006.51    2780288.01    4141767.70    2781554.52     11.23
 002    2167  Polyline      4142330.62    2757361.91    4141746.65    2757429.66     45.22
 003     759  Polyline      4142820.83    2784738.96    4142436.99    2783063.01     18.13
 004    1554  Polyline      4143499.65    2758207.61    4141746.65    2757429.66    166.09
 005    1471  Polyline      4143648.58    2773185.44    4142248.58    2773994.69     17.74
 006    1582  Polyline      4143680.35    2772573.57    4142248.58    2773994.69     32.43
 007    1420  Polyline      4143931.51    2774613.01    4142457.08    2775366.21      9.30
 008    1084  Polyline      4143956.51    2781813.01    4144294.72    2783430.35     15.09
 009    1525  Polyline      4144906.51    2773738.01    4142457.08    2775366.21     19.08
 010    1132  Polyline      4144977.50    2780405.03    4141767.70    2781554.52     22.86‍‍‍‍‍‍‍‍‍‍‍‍‍

.... snip ....‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

At least this will give you an idea of one approach

FidelTedla
New Contributor III

Thanks Dan. The first method did what I needed to do.

0 Kudos