2

Is there any chance I can create a simple python script to classify my data as Natural Breaks?

I have only created a script for quantile classification, but it is not enough for my work.

arrp = arcpy.da.FeatureClassToNumPyArray(in_features, field)
arr = np.array(arrp,np.float)

p1 = np.percentile(arr, 20)  
p2 = np.percentile(arr, 40)  
p3 = np.percentile(arr, 60)  
p4 = np.percentile(arr, 80)
p5 = np.percentile(arr, 100)

if Method[0] == "5":
    with arcpy.da.UpdateCursor(in_features , [field,'Class']) as cursor:
        for row in cursor:
            if row[0] < p1:
                row[1] = 1  #rank 0
            elif p1 <= row[0] and row[0] < p2:
                 row[1] = 2
            elif p2 <= row[0] and row[0] < p3:
                 row[1] = 3
            elif p3 <= row[0] and row[0] < p4:
                 row[1] = 4
            else:
                 row[1] = 5
            cursor.updateRow(row)
    print Method

I need to process values in the field "Class" that are classified from the "field".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.