How to get raster system-optimized pixel block size programmatically

340
4
08-18-2019 10:55 PM
ThanHtetAung_EsriAu
Esri Regular Contributor

Hi Guys,

In ArcObject we can get system-optimized pixel block size like this below code.

ArcObjects 10 .NET SDK Help 

         //Create a raster.         IRaster2 raster2 = rasterDs.CreateFullRaster()as IRaster2;         //Create a raster cursor with a system-optimized pixel block size by passing a null.        IRasterCursor rasterCursor = raster2.CreateCursorEx(null);

In ArcGIS pro sdk how shall we create cursor like this?, it seem width, height are mandatory.

ArcGIS Pro 2.4 API Reference Guide 

Is that different way in ArcGIS pro sdk?

Tags (1)
0 Kudos
4 Replies
GintautasKmieliauskas
Regular Contributor

Hi Than,

Have you tried to look at snippets page?

https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-Raster

There are few snippets with RasterCursor and PixelBlock

0 Kudos
ThanHtetAung_EsriAu
Esri Regular Contributor

Hi  Gintautas Kmieliauskas,

Yes, I did read through.

All sample are hardcoded with max size. 1000 or 128 only like below, to create curstor you must define width and height in advance.

int pixelBlockHeight = raster.GetHeight() > 1000 ? 1000 : raster.GetHeight();   
int pixelBlockWidth = raster.GetWidth() > 1000 ? 1000 : raster.GetWidth();    
// Create the raster cursor using the height and width calculated.  
RasterCursor rasterCursor = raster.CreateCursor(pixelBlockWidth, pixelBlockHeight);    
// Use a do while loop to iterate through the pixel blocks of the raster using the raster cursor.  
do  {     
// Get the current pixel block from the cursor.    
PixelBlock currentPixelBlock = rasterCursor.Current;     
// Do something with the pixel block...     
// Once you are done, move to the next pixel block.  
}   while (rasterCursor.MoveNext());

Where as In ArcObject like below code, we don't need to define pixelbockwidth or height.

//Create a raster.         
IRaster2 raster2 = rasterDs.CreateFullRaster()as IRaster2;         
//Create a raster cursor with a system-optimized pixel block size by passing a null.        
IRasterCursor rasterCursor = raster2.CreateCursorEx(null);

Is there any method to generate width and height? 

As you know, based on the raster size, pixel block size should be different.

If, there is a formula for me to generate width and height for better performance, that would be great.

0 Kudos
GintautasKmieliauskas
Regular Contributor

Hi Than,

I think pixel block size depends on your task.

If you need specific area which coordinates you know, you can convert them to raster pixels ant then calculate width and height.

If you need all raster try to read all raster at ones. In 64 bits there are no memory limitations so it could work. I am not sure that it is totally rewritten in ArcGIS Pro

Sometimes I take width as all raster width and height as the best performance value. 

0 Kudos
ThanHtetAung_EsriAu
Esri Regular Contributor

Thank Gintautas Kmieliauskas‌,

My addin task is to read all the pixels from raster under 64bits.

It look like no defined rules in it so far I chopped into 1000 pixel block and looking good and still quick.

Best Regards,

Than

0 Kudos