[gdal-dev] Getting unique values from a raster band

Frank Warmerdam warmerdam at pobox.com
Mon Mar 21 09:24:44 EDT 2011


On 11-03-21 08:28 AM, Tom Jeffery wrote:
> What is the proper way to extract all the unique values contained in a raster
> Band object?  I had initially assumed that if a RasterAttributeTable object
> existed, it would contain a "Value" column, but I have come across instances
> where the only column in the table is a "Histogram" field containing the counts
> of each pixel value, but not the value itself.
>
> Currently, I check for the existence of the table, check to see if it has a
> Value column, and if not, inspect each pixel value to get the unique set.  The
> pixel scanning fallback method is quite slow, however, and when I view the same
> rasters in ArcCatalog and bring up the "Table" view, it is able to instantly
> display the typical Value / Count table.  Is there some trick I'm missing here
> on how to get these values?

Tom,

I believe that ArcGIS is using the GetHistogram() method on the band which
can also find the histogram stored in other ways than a RasterAttributeTable.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list