How to Extract Top Five Max Points

986
8
01-28-2019 01:24 PM
MitchellWade
New Contributor III

I have a polygon layer and a points layer, and I need to extact the top five max points where they intersect. How do I do this?

0 Kudos
8 Replies
DanPatterson_Retired
MVP Emeritus

What do you mean by 'top'?  those closest to the upper edge of the polygon?

MitchellWade
New Contributor III

I am calculating the height of each point using LiDAR, and I want to extract the top five maximum heights!

0 Kudos
DanPatterson_Retired
MVP Emeritus

If you have a sample of the intersect table, it should have a 'key' field identifying the polygon and a Z field identifying the elevation of the intersecting point.  If you can save/export/ a portion of the table, I can show you how to do it with python, arcpy and numpy. Conceptually, it just involves grouping your intersecting features on the polygon key field, then sorting by Z and slicing off the top five.  The results can be sent back as a table for use in Pro

MitchellWade
New Contributor III

Thanks for your help! That is the exact workflow that I intend to follow; however, I prefer to have everything done by ArcGIS Pro operators instead of writing custom scripts. Is there any that comes to mind for sorting on the polygon ID and heights, and also for slicing?

0 Kudos
DanPatterson_Retired
MVP Emeritus

give me 30 minutes.... I thought it was an interesting problem, so I am writing up a blog post, 

DanPatterson_Retired
MVP Emeritus

Mitchell, it may not be exactly what you want... but it will get you started thinking should you chose to follow the path or take an alternate route

/blogs/dan_patterson/2019/01/29/split-sort-slice-the-top-x-in-y 

MitchellWade
New Contributor III

Thank you! I am following the tutorial now, and I am trying to understand your code, but I am having trouble getting arcpy to work with jupyter notebooks. Do you have an example of what the numpy array will look like after arcpy.da.TableToNumPy()?

0 Kudos
DanPatterson_Retired
MVP Emeritus

I wouldn't use jupyter notebooks. 

/blogs/dan_patterson/2018/12/13/spyder 

would be much better.

A 'structured' array is an array which has named fields/columns.  Each field has to contain a unique data type, but a structured array need not contain data of the same type.  Think a really smart spreadsheet.  Or you will see why Pandas exists because of numpy.  So in short, it would look exactly like your table in Pro, except that there are no visible field names at the top.

array([(1885,  963,  1, 'A1', 300886., 5034392., 12.35, 99),
       (1904, 1036,  1, 'A1', 300575., 5034497., 11.83, 53),
          snip.... , ...,
       ( 519,  572, 80, 'J8', 309695., 5027720., 11.86,  5),
       ( 275,   49, 90, 'J9', 309371., 5026486., 12.46, 79),
       ( 295, 1683, 90, 'J9', 309226., 5026555., 11.16, 94)],
      dtype=[('OBJECTID', '<i4'), ('FID_pnts', '<i4'), ('FID_poly', '<i4'), 
             ('Grid_codes', '<U6'), ('Xs', '<f8'), ('Ys', '<f8'),
             ('Norm', '<f8'), ('rand_int', '<i4')])

In the above we have field names

('OBJECTID', 'FID_pnts', 'FID_poly', 'Grid_codes', 'Xs', 'Ys', 'Norm', 'rand_int')

and the 'i' s are integers and 'f' s are floats and 'U' is text/string (aka unicode).  Don't worry about the number ('i4' is a 32-bit, 4 byte integer, 'f8' 64-bit float, etc)

I can make it look like a 'table' if that would help...

 id  OBJECTID   FID_pnts   FID_poly   Grid_codes Xs         Ys          Norm    rand_int  
------------------------------------------------------------------------------------------
 000       1885        963          1 A1          300886.00  5034392.00   12.35         99
 001       1904       1036          1 A1          300575.00  5034497.00   11.83         53
 002         68        594         91 A10         300164.00  5025374.00   12.83         22
 003        147       1081         91 A10         300529.00  5025818.00   11.86         24

... snip ....