public StochasticTimeRaster CreateOutputRaster(RasterDataType dataType) { StochasticTimeRaster rast = new StochasticTimeRaster( "output", dataType, 1, this.m_Width, this.m_Height, this.m_XllCorner, this.m_YllCorner, this.m_cellSize, this.m_cellSizeUnits, this.m_Projection, this.m_PrimaryStratumRaster.GeoTransform, this.m_NoDataValue, false, Spatial.UndefinedRasterBand); if (dataType == RasterDataType.DTInteger) { rast.InitIntCells(); } else { rast.InitDblCells(); } return(rast); }
/// <summary> /// Reads a binary header to determine the appropriate data type /// </summary> public static RasterDataType GetDataType(string fileName) { BinaryReader br = new BinaryReader(new FileStream(fileName, FileMode.Open)); br.ReadInt32(); // NumColumns br.ReadInt32(); // NumRows br.ReadDouble(); // CellWidth br.ReadDouble(); // CellHeight br.ReadDouble(); // xllcenter br.ReadDouble(); // yllcenter RasterDataType result = (RasterDataType)br.ReadInt32(); br.Close(); return(result); }
/// <summary> /// This open method is only called if this plugin has been given priority for one /// of the file extensions supported in the DialogReadFilter property supplied by /// this control. Failing to provide a DialogReadFilter will result in this plugin /// being added to the list of DataProviders being supplied under the Add Other Data /// option in the file menu. /// </summary> /// <param name="fileName">A string specifying the complete path and extension of the file to open.</param> /// <returns>An IDataSet to be added to the Map. These can also be groups of datasets.</returns> public virtual IRaster Open(string fileName) { RasterDataType fileDataType = GetDataType(fileName); switch (fileDataType) { case RasterDataType.SINGLE: BgdRaster <float> fRast = new BgdRaster <float> { ProgressHandler = _progressHandler, Filename = fileName }; fRast.Open(); return(fRast); case RasterDataType.DOUBLE: BgdRaster <double> dRast = new BgdRaster <double> { ProgressHandler = _progressHandler, Filename = fileName }; dRast.Open(); return(dRast); case RasterDataType.SHORT: BgdRaster <short> sRast = new BgdRaster <short> { ProgressHandler = _progressHandler, Filename = fileName }; sRast.Open(); return(sRast); case RasterDataType.INTEGER: BgdRaster <int> iRast = new BgdRaster <int> { ProgressHandler = _progressHandler, Filename = fileName }; iRast.Open(); return(iRast); case RasterDataType.BYTE: BgdRaster <byte> bRast = new BgdRaster <byte> { ProgressHandler = _progressHandler, Filename = fileName }; bRast.Open(); return(bRast); default: return(null); } }
/// <summary> /// Writes the header, regardless of which subtype of binary raster this is written for /// </summary> /// <param name="fileName">The string fileName specifying what file to load</param> public void ReadHeader(string fileName) { BinaryReader br = new BinaryReader(new FileStream(fileName, FileMode.Open)); StartColumn = 0; NumColumns = br.ReadInt32(); NumColumnsInFile = NumColumns; EndColumn = NumColumns - 1; StartRow = 0; NumRows = br.ReadInt32(); NumRowsInFile = NumRows; EndRow = NumRows - 1; Bounds = new RasterBounds(NumRows, NumColumns, new[] { 0.0, 1.0, 0.0, NumRows, 0.0, -1.0 }); CellWidth = br.ReadDouble(); Bounds.AffineCoefficients[5] = -br.ReadDouble(); // dy Xllcenter = br.ReadDouble(); Yllcenter = br.ReadDouble(); RasterDataType dataType = (RasterDataType)br.ReadInt32(); if (dataType != RasterDataType.INTEGER) { throw new ArgumentException( DataStrings.ArgumentOfWrongType_S1_S2.Replace("%S1", fileName).Replace("%S2", "BinaryShortRaster")); } NoDataValue = br.ReadInt32(); string proj = Encoding.ASCII.GetString(br.ReadBytes(255)).Replace('\0', ' ').Trim(); Projection = ProjectionInfo.FromProj4String(proj); Notes = Encoding.ASCII.GetString(br.ReadBytes(255)).Replace('\0', ' ').Trim(); if (Notes.Length == 0) { Notes = null; } br.Close(); }
/// <summary> /// This open method is only called if this plugin has been given priority for one /// of the file extensions supported in the DialogReadFilter property supplied by /// this control. Failing to provide a DialogReadFilter will result in this plugin /// being added to the list of DataProviders being supplied under the Add Other Data /// option in the file menu. /// </summary> /// <param name="fileName">A string specifying the complete path and extension of the file to open.</param> /// <returns>An IDataSet to be added to the Map. These can also be groups of datasets.</returns> public virtual IRaster Open(string fileName) { RasterDataType fileDataType = GetDataType(fileName); Raster raster = null; switch (fileDataType) { case RasterDataType.BYTE: raster = new BgdRaster <byte> { ProgressHandler = ProgressHandler, Filename = fileName }; break; case RasterDataType.SHORT: raster = new BgdRaster <short> { ProgressHandler = ProgressHandler, Filename = fileName }; break; case RasterDataType.INTEGER: raster = new BgdRaster <int> { ProgressHandler = ProgressHandler, Filename = fileName }; break; case RasterDataType.LONG: raster = new BgdRaster <long> { ProgressHandler = ProgressHandler, Filename = fileName }; break; case RasterDataType.SINGLE: raster = new BgdRaster <float> { ProgressHandler = ProgressHandler, Filename = fileName }; break; case RasterDataType.DOUBLE: raster = new BgdRaster <double> { ProgressHandler = ProgressHandler, Filename = fileName }; break; case RasterDataType.SBYTE: raster = new BgdRaster <sbyte> { ProgressHandler = ProgressHandler, Filename = fileName }; break; case RasterDataType.USHORT: raster = new BgdRaster <ushort> { ProgressHandler = ProgressHandler, Filename = fileName }; break; case RasterDataType.UINTEGER: raster = new BgdRaster <uint> { ProgressHandler = ProgressHandler, Filename = fileName }; break; case RasterDataType.ULONG: raster = new BgdRaster <ulong> { ProgressHandler = ProgressHandler, Filename = fileName }; break; case RasterDataType.BOOL: raster = new BgdRaster <bool> { ProgressHandler = ProgressHandler, Filename = fileName }; break; } raster?.Open(); return(raster); }