/// <summary> /// Be sure to install the GDAL extension if you want to view different types of files. /// /// How to Support Extensions in DotSpatial: /// https://justinwebdesign.wordpress.com/2015/03/26/how-to-support-extensions-in-dotspatial/ /// /// Otherwise the only accepted format seems to be .bgd /// /// `FileTypeNotSupported` error in the source code: /// https://github.com/DotSpatial/DotSpatial/blob/master/Source/DotSpatial.Data/DataManager.cs#L505 /// </summary> public static void OpenRasterAndGetValues(string rasterFilePath) { IRaster r = DotSpatial.Data.Raster.Open(rasterFilePath); r.GetStatistics(); double value = r.Maximum; }
public override void SaveAs(string fileName, string driverCode, string[] options) { // Create a new raster file IRaster newRaster = DataManager.DefaultDataManager.CreateRaster(fileName, driverCode, NumColumns, NumRows, NumBands, DataType, options); // Copy the file based values // newRaster.Copy(Filename, true); newRaster.Projection = Projection; newRaster.Extent = Extent; // Copy the in memory value newRaster.SetData(this); newRaster.ProgressHandler = ProgressHandler; newRaster.NoDataValue = NoDataValue; newRaster.GetStatistics(); newRaster.Bounds = Bounds; // Save the in-memory values. if (newRaster is GdalRaster <T> ) { int count = 1024; int xSize, ySize; for (int i = 0; i < Bands.Count; i++) { var newBand = newRaster.Bands[i]; for (int row = 0; row < NumRows; row += count) { ySize = Math.Min(count, NumRows - row); for (int col = 0; col < NumColumns; col += count) { xSize = Math.Min(count, NumColumns - col); IRaster raster = Bands[i].ReadBlock(col, row, xSize, ySize); newBand.WriteBlock(raster, col, row, xSize, ySize); } } } newRaster.Save(); } else { newRaster.Save(); } newRaster.Close(); }
/// <summary> /// Saves the current raster to the specified file. /// </summary> /// <param name="fileName">The string fileName to save the current raster to.</param> /// <param name="driverCode">The driver code to use.</param> /// <param name="options">the string array of options that depend on the format.</param> public virtual void SaveAs(string fileName, string driverCode, string[] options) { // Create a new raster file IRaster newRaster = DataManager.DefaultDataManager.CreateRaster(fileName, driverCode, NumColumns, NumRows, NumBands, DataType, options); // Copy the file based values // newRaster.Copy(Filename, true); newRaster.Projection = Projection; newRaster.Extent = Extent; // Copy the in memory value newRaster.SetData(this); newRaster.ProgressHandler = ProgressHandler; newRaster.NoDataValue = NoDataValue; newRaster.GetStatistics(); newRaster.Bounds = Bounds; // Save the in-memory values. newRaster.Save(); newRaster.Close(); }