Esempio n. 1
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Sets the pixel's bands.
        /// </summary>
        /// <param name="band0">
        /// The first band.
        /// </param>
        /// <param name="otherBands">
        /// Other optional bands.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// One or more of the bands is null.
        /// </exception>
        protected void SetBands(IPixelBand band0,
                                params IPixelBand[] otherBands)
        {
            if (band0 == null)
            {
                throw new ArgumentNullException("band 0 is null");
            }
            if (otherBands == null)
            {
                //  The method was called as SetBands(band0, null)
                throw new ArgumentNullException("band 1 is null");
            }
            int bandIndex = 0;

            foreach (IPixelBand band in otherBands)
            {
                bandIndex++;
                if (band == null)
                {
                    throw new ArgumentNullException(string.Format("band {0} is null",
                                                                  bandIndex));
                }
            }

            bands    = new IPixelBand[1 + otherBands.Length];
            bands[0] = band0;
            otherBands.CopyTo(bands, 1);
        }
Esempio n. 2
0
        /// <summary>
        /// Write a pixel to the file. Assumes pixels will be written
        /// by the caller consecutively from upper left to bottom
        /// right a row at a time
        /// </summary>
        public void WritePixel(IPixel pixel)
        {
            try
            {
                if ((fileWriter == null) || (!this.open))
                {
                    throw new System.ApplicationException("Raster not open for writing");
                }

                if (currPixel >= totalPixels)
                {
                    throw new System.ApplicationException("Writing beyond end of pixel data");
                }

                int bandCount = pixel.BandCount;
                for (int bandNum = 0; bandNum < bandCount; bandNum++)
                {
                    IPixelBand band = pixel[bandNum];

                    // calc this pixelband's location in file
                    int location = PixelBandLocation(currPixel, bandNum);

                    this.fileWriter.Seek(location, SeekOrigin.Begin);

                    this.fileWriter.Write(band.GetBytes());
                }

                currPixel++;
            }
            catch (System.Exception)
            {
                Close();
                throw;
            }
        }
Esempio n. 3
0
        private bool disposed = false; // track whether resources have been released

        /// <summary>
        /// Constructor - takes an already constructed ERDAS image file
        /// </summary>
        public OutputRaster(WritableImage image)
        {
            this.image = image;

            // make sure we got valid image
            if (this.image == null)
            {
                throw new System.ApplicationException("OutputRaster constructor passed null 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");
                }
            }
        }
        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
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Write a pixel to the file. Assumes pixels will be written
        /// by the caller consecutively from upper left to bottom
        /// right a row at a time
        /// </summary>
        public void WritePixel(IPixel pixel)
        {
            int bandCount = pixel.BandCount;

            for (int bandNum = 0; bandNum < bandCount; bandNum++)
            {
                IPixelBand band = pixel[bandNum];

                // calc this pixelband's location in file
                int location =
                    PixelBandLocation(this.pixelsWritten, bandNum);

                this.fileWriter.Seek(location, SeekOrigin.Begin);

                this.fileWriter.Write(band.GetBytes());
            }

            this.pixelsWritten++;
        }
        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");
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Read a pixel from the file. Assumes pixels will be read
        /// by the caller consecutively from upper left to bottom
        /// right a row at a time
        /// </summary>
        public void ReadPixel(IPixel pixel)
        {
            int bandCount = pixel.BandCount;

            for (int bandNum = 0; bandNum < bandCount; bandNum++)
            {
                IPixelBand band = pixel[bandNum];

                // calc this pixelband's location in file
                int location = PixelBandLocation(pixelsRead, bandNum);

                // seek to correct pixel spot
                this.fileReader.BaseStream.Seek(location, SeekOrigin.Begin);

                byte[] bytes = this.fileReader.ReadBytes(this.BandSize);

                band.SetBytes(bytes, 0);
            }

            pixelsRead++;
        }
Esempio n. 8
0
        /// <summary>
        /// Read a pixel from the file. Assumes pixels will be read
        /// by the caller consecutively from upper left to bottom
        /// right a row at a time
        /// </summary>
        public void ReadPixel(IPixel pixel)
        {
            try
            {
                if ((fileReader == null) || (!this.open))
                {
                    throw new System.ApplicationException("Raster not open for reading");
                }

                if (currPixel >= totalPixels)
                {
                    throw new System.ApplicationException("Reading beyond end of pixel data");
                }

                int bandCount = pixel.BandCount;
                for (int bandNum = 0; bandNum < bandCount; bandNum++)
                {
                    IPixelBand band = pixel[bandNum];

                    // calc this pixelband's location in file
                    int location = PixelBandLocation(currPixel, bandNum);

                    // seek to correct pixel spot
                    this.fileReader.BaseStream.Seek(location, SeekOrigin.Begin);

                    byte[] bytes = this.fileReader.ReadBytes(bandSize);

                    band.SetBytes(bytes, 0);
                }

                currPixel++;
            }
            catch (System.Exception)
            {
                Close();
                throw;
            }
        }
Esempio n. 9
0
 public void BandIndex_TooBig()
 {
     MyPixel    pixel = new MyPixel();
     IPixelBand band  = pixel[pixel.BandCount];
 }
Esempio n. 10
0
 public void BandIndex_Negative()
 {
     MyPixel    pixel = new MyPixel();
     IPixelBand band  = pixel[-1];
 }
Esempio n. 11
0
 public FakePixel(IPixelBand band0,
                  params IPixelBand[] otherBands)
 {
     SetBands(band0, otherBands);
 }
Esempio n. 12
0
			public FakePixel(IPixelBand          band0,
			                 params IPixelBand[] otherBands)
			{
				SetBands(band0, otherBands);
			}
Esempio n. 13
0
		//---------------------------------------------------------------------

		/// <summary>
		/// Sets the pixel's bands.
		/// </summary>
		/// <param name="band0">
		/// The first band.
		/// </param>
		/// <param name="otherBands">
		/// Other optional bands.
		/// </param>
		/// <exception cref="ArgumentNullException">
		/// One or more of the bands is null.
		/// </exception>
		protected void SetBands(IPixelBand          band0,
		                        params IPixelBand[] otherBands)
		{
			if (band0 == null)
				throw new ArgumentNullException("band 0 is null");
			if (otherBands == null)
				//  The method was called as SetBands(band0, null)
				throw new ArgumentNullException("band 1 is null");
			int bandIndex = 0;
			foreach (IPixelBand band in otherBands) {
				bandIndex++;
				if (band == null)
					throw new ArgumentNullException(string.Format("band {0} is null",
					                                              bandIndex));
			}

			bands = new IPixelBand[1 + otherBands.Length];
			bands[0] = band0;
			otherBands.CopyTo(bands, 1);
		}