I did this some time ago, although my solution is using GDAL (so, this is not just for ArcGIS). I think you can get a NumPy array from a raster in ArcGIS 10, but I don't know for sure. NumPy supplies simple and powerful array indexing, like argsort
and others. This example doesn't handle NODATA or transform coordinates from projected to lat/long (but this isn't difficult to do with osgeo.osr, provided with GDAL)
import numpy as np
from osgeo import gdal
# Open raster file, and get GeoTransform
rast_src = gdal.Open(rast_fname)
rast_gt = rast_src.GetGeoTransform()
def get_xy(r, c):
'''Get (x, y) raster centre coordinate at row, column'''
x0, dx, rx, y0, ry, dy = rast_gt
return(x0 + r*dx + dx/2.0, y0 + c*dy + dy/2.0)
# Get first raster band
rast_band = rast_src.GetRasterBand(1)
# Retrieve as NumPy array to do the serious work
rast = rast_band.ReadAsArray()
# Sort raster pixels from highest to lowest
sorted_ind = rast.argsort(axis=None)[::-1]
# Show highest top 10 values
for ind in sorted_ind[:10]:
# Get row, column for index
r, c = np.unravel_index(ind, rast.shape)
# Get [projected] X and Y coordinates
x, y = get_xy(r, c)
print('[%3i, %3i] (%.3f, %.3f) = %.3f'%
(r, c, x, y, rast[r, c]))
Shows the following for my test raster file:
[467, 169] (2813700.000, 6353100.000) = 844.538
[467, 168] (2813700.000, 6353200.000) = 841.067
[469, 168] (2813900.000, 6353200.000) = 840.705
[468, 168] (2813800.000, 6353200.000) = 840.192
[470, 167] (2814000.000, 6353300.000) = 837.063
[468, 169] (2813800.000, 6353100.000) = 837.063
[482, 166] (2815200.000, 6353400.000) = 833.038
[469, 167] (2813900.000, 6353300.000) = 832.825
[451, 181] (2812100.000, 6351900.000) = 828.064
[469, 169] (2813900.000, 6353100.000) = 827.514