Edit raster pixel by pixel

757
4
06-09-2019 07:04 AM
MaxMax2
Occasional Contributor II

I'm trying to edit raster of GDB raster dataset added to map as RasterLayer. I need to set new extent, height, width and cells values. My code is:

var raster = layer.GetRaster();

raster.SetExtent(extent);
raster.SetHeight(rowsCount);
raster.SetWidth(columnsCount);

var pixelBlockHeight = Math.Min(raster.GetHeight(), rowsCount);
var pixelBlockWidth = Math.Min(raster.GetWidth(), columnsCount);
var pixelBlock = raster.CreatePixelBlock(pixelBlockWidth, pixelBlockHeight);

raster.Read(0, 0, pixelBlock);
var sourcePixels = pixelBlock.GetPixelData(0, false);

for (var i = 0; i < pixelBlockHeight; i++)
{
    for (var j = 0; j < pixelBlockWidth; j++)
    {
        sourcePixels.SetValue(Convert.ToUInt32(1000), j, i);
    }
}

pixelBlock.SetPixelData(0, sourcePixels);

raster.Write(0, 0, pixelBlock);
raster.Refresh();

But nothing happens. No values are applied. If I get pixel block again, all values are zero. Statistics is empty.

What am I doing wrong?

0 Kudos
4 Replies
MaxMax2
Occasional Contributor II

Any news on this issue?

0 Kudos
Prashant_MukeshMangtani
Esri Contributor

Max,

Did you check to see if the raster can be edited using raster.CanEdit()? If you know where the raster dataset is you don't need a layer. You can just open the raster dataset, create a full raster and make your edits on it.

https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Raster#opening-raster-datasets

-Prashant

0 Kudos
MaxMax2
Occasional Contributor II

Hi Prashant,

I need layer since I want to show raster on map. CanEdit returns true. So have RasterLayer in which I need to modify pixels. But my edits are not applied.

Max

0 Kudos
MaxMax2
Occasional Contributor II

It seems it's impossible to edit pixels of raster layer's raster. Am I right?

0 Kudos