I would like to create a text field in the first shape that would concatenate the ID fields of all the small polygones of the second shape that are included (at least partially) in the polygone of the first shape.
import arcpy arcpy.env.overwriteOutput = True bigPolygonLayer = r"C:\tmp\Test.gdb\BigPolygons" smallPolygonLayer = r"C:\tmp\Test.gdb\SmallPolygons" idField = "YourIDField" #add new field to target feature class if not exists: fieldList = arcpy.ListFields(bigPolygonLayer) fieldNameList = [] for field in fieldList: fieldNameList.append(field.name) if not idField in fieldNameList: arcpy.AddField_management(bigPolygonLayer, idField, "TEXT","","",1023) #you can adjust field length #loop throug big polygons bigPolyUC = arcpy.UpdateCursor(bigPolygonLayer) for bigPolyRow in bigPolyUC: bigPolyGeom = bigPolyRow.Shape concatIDLst =[] #loop through all small polygons, take ID values if small polygon OVERLAPS the big ... #and add to concat string; (You can change relation to CONTAINS to restrict results) smallPolySC = arcpy.SearchCursor(smallPolygonLayer) for smallPolyRow in smallPolySC: smallPolyGeom = smallPolyRow.Shape if bigPolyGeom.overlaps(smallPolyGeom): concatIDLst.append(str(smallPolyRow.getValue(idField))) concatID = "".join(concatIDLst) #between "" you can add any ID separator: space, comma, etc. bigPolyRow.setValue(idField, concatID) bigPolyUC.updateRow(bigPolyRow) del smallPolySC, smallPolyRow, bigPolyUC, bigPolyRow, bigPolyGeom
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.