kubacech

Incorrect values in a raster

Discussion created by kubacech on Dec 7, 2017
Latest reply on Dec 7, 2017 by temge-esristaff

Hello, I'm trying to save data as a raster. Right before editing a raster I save the result to CSV and plot it with python to compare results, see python_result.PNG. Since I cannot create raster dataset from scratch I save the orginal source raster and insert the values in. Then I save it again. The problem is the raster doesn't look anything like they should. First and second saved raster are not even identical. (See images.)

 

Any idea where the problem could be?

 

Thank you

 

Code:

RasterStorageDef rasterStorageDef = new RasterStorageDef();
rasterStorageDef.SetPyramidLevel(0);
RasterDataset finalRaster = raster.SaveAs("FirstRaster.tiff", outputDataStore, rasterFormat, rasterStorageDef);

Raster resultRaster = finalRaster.CreateRaster(new int[1] { 0 });
resultRaster.SetNoDataValue(0);
resultRaster.SetPixelType(RasterPixelType.DOUBLE);
if (resultRaster.CanEdit()) {
   MessageBox.Show("Cannot edit raster");
   return;
}

currentPixelBlock.Clear(0);
resultRaster.Write(0, 0, currentPixelBlock);

PixelBlock newPixelBlock = resultRaster.CreatePixelBlock(resultRaster.GetWidth(), resultRaster.GetHeight());
newPixelBlock.SetPixelData(0, result.Transpose());
resultRaster.Write(0, 0, newPixelBlock);
resultRaster.Refresh();

resultRaster.SaveAs("SecondRaster.tiff", outputDataStore, rasterFormat, rasterStorageDef);

Outcomes