I have a dataset of thousands of points, made by the intersection of flowlines with waterbody polygons. Each polygon has two (or sometimes more, if the waterbody has multiple tributaries) points made by these intersections. I would like to select the point with the lowest elevation, for each polygon. If there an automated way to do this?

  • Sort points by z, remove duplicates by lake id. – FelixIP Aug 2 '18 at 18:54

One way is to use arcpy. Script will select point with lowest z value per name. Execute the code in the python window after modifying names and with the point layer added to the map:

import arcpy
layer = 'Points' #Modify to match the point layer name in table of contents
fields = ['Namefield','SHAPE@Z','OID@'] #Modify first field name 

all_rows = [i for i in arcpy.da.SearchCursor(layer,fields)] #List all rows
all_rows_sorted = sorted(all_rows, key=lambda x: x[1],reverse=True) #Sort by z
d = {r[0]:r[2] for r in all_rows_sorted} #Use a dictionary to keep oid of lowest z per name
oids_to_select = [k for k in d.values()]

sql = """{0} IN({1})""".format(arcpy.AddFieldDelimiters(layer,arcpy.Describe(layer).OIDFieldname),
                               ','.join([str(o) for o in oids_to_select]))
arcpy.SelectLayerByAttribute_management(in_layer_or_view=layer, where_clause=sql)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.