Thursday, 23 November 2017

Iterate Through All Combinations of Features by Selection in ArcGIS Python Script


I have question about ArcGIS and python script. There are following sample code, So I would like to change Another Field , not OIDFieldName. Please let me know how to change Another Field.



import arcpy
import itertools

arcpy.env.workspace = r"C:\path\to\workspace"

base_shapefile = "some_shapefile.shp"

oid_field = arcpy.Describe(base_shapefile).OIDFieldName
feature_count = int(arcpy.GetCount_management(base_shapefile).getOutput(0))


for (i, j) in itertools.combinations(range(feature_count), 2):
arcpy.Select_analysis(base_shapefile , "combination_%i_%i.shp" % (i, j), '"%s" in (%i, %i)' % (oid_field, i, j))

These sample code is combination for 5C2. I want to create all combiantions 5C3 , 5C4 , 5C5.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...