Search code examples
arcgisarcpy

Reclassify a feature class with arcpy using Natural Breaks (Jenks) method


I'm trying to reclassify a feature class using arcpy, but the Python functionality for the Reclassify tool doesn't appear to be the same as the Dialog functionality.  The tool dialog gives you the option to choose between Classify and Unique options to generate a map table:

enter image description here

If you click Classify, it then gives you the option to select a classification method and the number of classes:

enter image description here

I would like be able to use this functionality in arcpy to reclassify a feature class into 4 classes (with values of 1, 2, 3, 4) using the Natural Breaks (Jenks) method, so that the map table looks like this:

enter image description here

This script will be used with many different datasets, so I have no way of knowing what the data will look like.


Solution

  • Seems like both Reclassify tools (from Spatial Analyst and 3D Analyst) creates a remap table with a separate tool.

    You could use a third-party library such as Numpy to calculate the values (there is an old question on GIS StackExchange) and pass them along using a Remap object: RemapValue or RemapRange

    However, there is also arcpy.ddd.Slice (3D Analyst):

    Slices or reclassifies the range of values of the input cells into zones (classes). The available data classification methods are equal interval, equal area (quantile), natural breaks, standard deviation (mean-centered), standard deviation (mean as a break), defined interval, and geometric interval.

    import arcpy, arcpy.ddd
    
    RASTER = arcpy.Raster(r"d:\temp\bergen.tif")
    
    arcpy.ddd.Slice(RASTER, r"d:\temp\bergen_out.tif", 5, "NATURAL_BREAKS")
    

    There is also a Python library that calculate natural breaks: