Esempio n. 1
0
def get_classification(raster_filename,
                       num_of_classes=10,
                       class_type=1,
                       band_num=1):
    """
    gets the classification for the automatic classification routine
    inputs:
    1)raster path string
    2)number of classes
    3)classification type, Choices of classifiers are between:
        CLASSIFY_DISCRETE = 0
        CLASSIFY_EQUAL_INTERVAL = 1
        CLASSIFY_QUANTILE = 2
        CLASSIFY_NORM_SD = 3
    4)band number to process
    outputs: list of classes
    interacts with:automatic_classification
    """

    ds = gdal.Open(raster_filename)

    # Get the single band
    # band = ds.GetRasterBand(band_num)

    # Create a gview raster object from band
    raster = gview.GvRaster(None, ds)

    # Define gview layer from raster
    # Needed to pass to GvClassification
    layer = gview.GvRasterLayer(raster)

    classification = GvClassification(layer)
    # classification.set_classify_property(layer,str(class_type))
    classification.set_type(class_type)

    # use default classification with number of classes
    # defined at input
    classification.prepare_default(num_of_classes)

    # list for holding the classes
    cls = []

    # cycle through the classes and add them to the cls list
    for cls_in in range(num_of_classes):
        cls.append(classification.get_range(cls_in))

    return cls