import arcpy from arcpy import env env.overwriteOutput =1 env.workspace = r"C:\temp\python\test.gdb" #create a one-to-many spatial join arcpy.SpatialJoin_analysis("lakes", "rivers", "lakes_join", "JOIN_ONE_TO_MANY", "KEEP_ALL", "", "INTERSECT") #create empty dictionary to store target_fid and shape length dict = {} #sort by river's shape length, iterate through each row, and populate dictionary with largest river length rows = arcpy.SearchCursor("lakes_join", "", "", "", "SHAPE_LENGTH_1 A") for row in rows: length = '%.14f' % row.SHAPE_LENGTH_1 dict[row.TARGET_FID] = length del row, rows #delete all values that are not the larget river for key in dict: print key, dict[key] arcpy.MakeFeatureLayer_management("lakes_join", "lakes_join_lyr", "TARGET_FID = " + str(key) + " AND NOT SHAPE_Length_1 = " + str(dict[key])) arcpy.DeleteFeatures_management("lakes_join_lyr") print "finished"
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.