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".
-
Have you looked at using numpy? This might be related: gis.stackexchange.com/q/115202/7424 and this too: stats.stackexchange.com/q/143974Fezter– Fezter2016年06月30日 22:01:04 +00:00Commented Jun 30, 2016 at 22:01
2 Answers 2
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/...
-
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/…Bram– Bram2021年04月26日 07:04:34 +00:00Commented Apr 26, 2021 at 7:04
-
2How 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.Hornbydd– Hornbydd2021年04月26日 10:27:32 +00:00Commented Apr 26, 2021 at 10:27
-
1Sorry, 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!Bram– Bram2021年04月26日 12:30:15 +00:00Commented Apr 26, 2021 at 12:30
-
1May 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!Hornbydd– Hornbydd2021年04月26日 13:20:33 +00:00Commented 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!Bram– Bram2021年04月26日 13:40:34 +00:00Commented Apr 26, 2021 at 13:40
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.
Explore related questions
See similar questions with these tags.