0

I'm making a Python script using ArcPy for ArcGIS Pro and I have joined a Feature Class and a Table View to create a new feature class. All of the fields and rows I need are present, however there are rows that contain duplicate values for the foreign key of the Table View.

I realize that the issue that I'm having is that I am performing a 1:M join when I really want something more along the lines of a 1:first matching record join. I believe using the Group By SQL clause would resolve this issue in a normal database situation, but I'm not sure how to duplicate this functionality in ArcPy.

This is the working code that I have so far:

table_view = arcpy.management.MakeTableView(joinFeatures, "tableview", joinExpr)
arcpy.CopyRows_management(table_view, "tableview_temp")
FL = arcpy.management.AddJoin(targetFeatures, "segmentid", "tableview_temp", "segmentidfkey", "KEEP_COMMON")
arcpy.CopyFeatures_management(FL, out_layer)

The targetFeatures feature class contains a single instance of each segmentid that I'm joining on, and the "tableview_temp" has multiple records containing the matching segmentidfkey.

I need the output feature class to only contain one record for segmentid even if multiple segmentidfkey matches.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Dakota
  • 1
  • Don't know if this will work for you. Use your current logic to create the table you describe, then run that table through a summary stats tool where statistics is FIRST and case field would be your segmentid? – Hornbydd Jun 10 '22 at 20:49
  • Use this https://gis.stackexchange.com/questions/200150/auto-incrementing-field-based-on-groups-within-feature-class#200154 inside script, adding oids to list where function returns 1. SeSelection to this list and add join. – FelixIP Jun 11 '22 at 00:24

0 Answers0