Jenks Classification in a script

2174
6
Jump to solution
03-18-2014 01:06 PM
NoahHuntington
Occasional Contributor
This is a portion of a stand alone script in which the user supplies the dem for the slope analysis.  The reclassify tool would otherwise allow me to choose a jenks classification and set the number classes to 10.  I need to supply the reclassify tool the necessary parameters to accomplish the same thing without the benefit of the arcgis tool dialogue.  How can I set this up programmatically using the output slope raster to supply the necessary parameters to the reclassify tool?


# Check out the ArcGIS Spatial Analyst extension license arcpy.CheckOutExtension("Spatial")  # Execute Slope try:     outSlope = Slope(raster_clip, "DEGREE", 3.2808333)     dem_Slope = outSlope.save("dem_Slope")     arcpy.AddMessage("Slope complete.") except:      arcpy.AddError("Was not able to complete slope...")   # Reclassify the slope raster remapTable = Reclassify (dem_Slope, Value, ...
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
NeilAyres
MVP Alum
The Jenks classification is a reasonably complex calculation.
I found this on the web some time ago.
Unfortunately I cannot remember where it came from, so cannot attribute the author.
Havn't tried to implement this code either, so cannot say if it actually works.
Good luck,
Neil

View solution in original post

0 Kudos
6 Replies
NeilAyres
MVP Alum
The Jenks classification is a reasonably complex calculation.
I found this on the web some time ago.
Unfortunately I cannot remember where it came from, so cannot attribute the author.
Havn't tried to implement this code either, so cannot say if it actually works.
Good luck,
Neil
0 Kudos
NoahHuntington
Occasional Contributor
The Jenks classification is a reasonably complex calculation.
I found this on the web some time ago.
Unfortunately I cannot remember where it came from, so cannot attribute the author.
Havn't tried to implement this code either, so cannot say if it actually works.
Good luck,
Neil


Thanks Neil!

I am glad you chimed in.  I imagined it would be fairly complicated. I will work with this and see if I can't make it happen!

-Noah
0 Kudos
NoahHuntington
Occasional Contributor
Neil... If I can pick your mind a bit further?


I believe this will work perfectly with the standalone script I am working on. I am admittedly somewhat novice with python but can generally follow the usage and flow of a script. With that said I have a question regarding obtaining �??datalist�?� variable. I am working witha slope raster where I am interested in classifying the �??Value�?� from the cells. Any suggestions on obtaining the datalist? Cursor or otherwise?
0 Kudos
NeilAyres
MVP Alum
Noah,

after I posted the pdf, I did indeed type up this piece of code as a python script. And tested it on a set of random numbers generated by python.
The code worked fine. Havn't tested it again to see if it returns the same split values as ArcMap symbol editor though.
However, I overlooked your original intention, classify an "image", and get those values into a reclassify routine.
I found that the script worked well with, say, several 100's of records. But it doesn't scale very well. All those mat1, mat2 lists which it has to shuffle through. Once these get large, it gets very large.

So what you might have to consider is to resample your slope raster using 1000 random points then use those values as an input into the Jenks classifier routine. Obviously converting the entire image (via raster to point or something), you will end up with too much data.

Cheers,
Neil
0 Kudos
NeilAyres
MVP Alum
Another idea and probably more practical.
Why not let ArcGIS do the classification and then access the value of the split values via the arcpy.mapping module.
Check the RasterClassifiedSymbology class here :
http://resources.arcgis.com/en/help/main/10.2/#/RasterClassifiedSymbology/00s30000005p000000/
That could work.
Cheers,
Neil
0 Kudos
NoahHuntington
Occasional Contributor
Neil  I've read thru the resources and am not finding many examples on implementing this approach.  I think you may be onto something.  Is there anyway you can elaborate or assist me in implementing this with my data?
0 Kudos