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".

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jun 30, 2016 at 21:21
1

2 Answers 2

1

I have no clear answer on how to reclassify vector data. For reclassifying raster data in ArcPy however, you can best use the "Slice" method. Here you can specify the classification method yourself. You can find documentation on it here: pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/...

answered Apr 22, 2021 at 14:53
5
  • Slice is one of the tools that can be used in ArcGIS Pro. You can find documentation on it here: pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/… Commented Apr 26, 2021 at 7:04
  • 2
    How does this help? The output of the slice tool is a raster grouped into the X number of specified zones using the natural breaks. It does not enable the person to discover the actual break values. It's clear from their sample code they want to apply natural breaks to a vector dataset. Commented Apr 26, 2021 at 10:27
  • 1
    Sorry, I missed that part. I was looking for an answer myself how it could possibly work with raster data in QGIS (gis.stackexchange.com/questions/394891/…). As I am aware of the possibility in ArcPy, I thought I'd share it. I will edit the response! Commented Apr 26, 2021 at 12:30
  • 1
    May be you should delete this answer or as you suggest reword it? For the record I was looking at your question and voted that up! Commented Apr 26, 2021 at 13:20
  • I have just reworded it directly after I sent the previous comment! And thanks for upvoting, I hope it can be solved anytime soon! Commented Apr 26, 2021 at 13:40
1

If you want to classify your data using natural breaks, a way of doing it in python is to import a module that does this for you. A simple google search threw up the jenkspy module. I've not used it so can't comment on its ease of use/stability but it appears to do what you need.

Also have a look at this Q&A using a pysal module approach.

answered Apr 26, 2021 at 10:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.