TransWikia.com

Attributes selection using ArcMap

Geographic Information Systems Asked by Kareem Hafez on August 18, 2020

I have attribute table with duplicate ID numbers, it is "1,1,2,2,3,3,….."
and there is a unique number value in another field and I want to select the smaller number for each ID.

below is an image of my attribute table

enter image description here

2 Answers

A non program solution is to run table through summary stats tool case would be page number and stats in minimum of measure. That could create a table of the rows you want to select. In that table add a string field and concatenate the page number and measure to create an Id field, do the same with your table above. Then you can use the relate tools in arcmap to pass a selection. Total time < 3 mins.

Correct answer by Hornbydd on August 18, 2020

I agree with @Hornbydd. But if you want to use Python you can use the fact a dictionary can't have multiple keys and sort by value field. Last record in each group/(dictionary key) will be kept.

import arcpy

#Change to match your data
layer = "ak_riks"
group = "LANSNAMN"
value = "Area"

fields = [group, value, "OID@"]

records = [row for row in arcpy.da.SearchCursor(layer,fields)]
records.sort(key=lambda x: x[1], reverse=True)

d = {r[0]:r[2] for r in records}
to_select = d.values()

arcpy.SelectLayerByAttribute_management(in_layer_or_view=layer, where_clause="""{0} IN {1}""".format(arcpy.AddFieldDelimiters(datasource=layer, field=arcpy.Describe(layer).OidFieldName), tuple(to_select)))

enter image description here

Answered by BERA on August 18, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP