/// <summary> /// /// </summary> public IInputRaster <T> OpenRaster <T>(string path) where T : IPixel, new() { // open image file for reading ErdasImageFile image = new ErdasImageFile(path, RWFlag.Read); // construct an InputRaster using that return(new ErdasInputRaster <T>(image, path)); }
private T pixel; // a pixel: used for xfering data /// <summary> /// Constructor - takes an already constructed ERDAS image file /// </summary> public ErdasInputRaster(ErdasImageFile image, string path) : base(path) { this.disposed = false; this.image = image; this.pixel = new T(); // make sure we've got valid input if (this.image == null) { throw new System.ApplicationException("InputRaster constructor passed null image"); } // check if trying to read a WriteOnly file if (this.image.Mode == RWFlag.Write) { throw new System.ApplicationException("InputRaster can't be created for WriteOnly image"); } // pixel vs. image bandcount mismatch? int pixelBandCount = this.pixel.BandCount; if (pixelBandCount != image.BandCount) { throw new System.ApplicationException("InputRaster band count mismatch"); } // check bandtype compatibilities for (int i = 0; i < pixelBandCount; i++) { IPixelBand band = this.pixel[i]; if (image.BandType == System.TypeCode.Byte) { if (band.TypeCode != System.TypeCode.Byte) { throw new System.ApplicationException("InputRaster band type mismatch"); } } else if (image.BandType == System.TypeCode.UInt16) { if (band.TypeCode != System.TypeCode.UInt16) { throw new System.ApplicationException("InputRaster band type mismatch"); } } else { throw new System.ApplicationException("InputRaster - Unsupported band type"); } // shouldn't really ever get to this exception // ErdasImageFile construction code should have // thrown an exception earlier } }
private bool disposed = false; // track whether resources have been released /// <summary> /// Constructor - takes an already constructed ERDAS image file /// </summary> public ErdasOutputRaster(ErdasImageFile image, string path, Dimensions dimensions, IMetadata metadata) : base(path, dimensions, metadata) { this.image = image; // make sure we got valid image if (this.image == null) { throw new System.ApplicationException("OutputRaster constructor passed null image"); } // make sure image is not readonly if (this.image.Mode == RWFlag.Read) { throw new System.ApplicationException("OutputRaster cannot be constructed on ReadOnly image"); } // Begin test bandtype compatibilities T desiredLayout = new T(); int bandCount = desiredLayout.BandCount; System.TypeCode bandType = desiredLayout[0].TypeCode; // check band 0 if (bandType != image.BandType) { throw new System.ApplicationException("OutputRaster band type mismatch"); } // check bands 1 to n-1 for (int i = 1; i < bandCount; i++) { IPixelBand band = desiredLayout[i]; if (band.TypeCode != bandType) { throw new System.ApplicationException("OutputRasters with mixed band types not supported"); } } }
/// <summary> /// /// </summary> public IOutputRaster <T> CreateRaster <T>(string path, Dimensions dimensions, IMetadata metadata) where T : IPixel, new() { // extract necessary parameters from pixel for image creation T desiredLayout = new T(); int bandCount = desiredLayout.BandCount; System.TypeCode bandType = desiredLayout[0].TypeCode; // open image file for writing ErdasImageFile image = new ErdasImageFile(path, dimensions, bandCount, bandType, metadata); // construct an OutputRaster from that return(new ErdasOutputRaster <T>(image, path, dimensions, metadata)); }