Hi,
I have a folder of single band GeoTiffs and I'm trying to use C# and the SDK for Pro to iterate each raster and get an array of distinct values for each raster.
Here is an simplified example of my code:
// conn is a connection path defineded up here...
// item.Value is the name of a tif file...
foreach (var item in downloadedMasks)
{
await QueuedTask.Run(() =>
{
FileSystemDatastore dstore = new FileSystemDatastore(conn);
RasterDataset rasterDataset = dstore.OpenDataset<RasterDataset>(item.Value);
Raster raster = rasterDataset.CreateFullRaster();
int width = raster.GetWidth();
int height = raster.GetHeight();
var block = raster.CreatePixelBlock(width, height);
raster.Read(0, 0, block);
Array array = block.GetPixelData(0, true);
int validCount = 0;
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
int pixelValue = Convert.ToInt16(block.GetValue(0, i, j));
// check unique value and store in a list...
}
}
});
};This process is really slow - I get much quicker results using GDAL.Open() and Numpy.Unique in Python.
Does anyone have any advice on how I could speed this up? Any advice on how to effieciently extract pixel values from a raster in C# would be appreciated.