Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        public IInputRaster <T> Open <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 InputRaster <T>(image));
        }
        private T pixel;              // a pixel: used for xfering data

        /// <summary>
        /// Constructor - takes an already constructed ERDAS image file
        /// </summary>
        public InputRaster(ErdasImageFile image)
        {
            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
            }
        }
 public void ConstructNewGis()
 {
     ErdasImageFile
     image = new ErdasImageFile(outputGisImagePath,
                                  new Dimensions(60,40),
                                  1,
                                  System.TypeCode.Byte,
                                  null);
     Assert.AreEqual(60, image.Dimensions.Rows);
     Assert.AreEqual(40, image.Dimensions.Columns);
     Assert.AreEqual(1, image.BandCount);
     Assert.AreEqual(System.TypeCode.Byte, image.BandType);
     Assert.AreEqual(null, image.Metadata);
     
     image.Close();  // needed or file stays locked after run of tests. why?
 }
 public void ConstructNewLan()
 {
     ErdasImageFile
     image =
         new ErdasImageFile(outputLanImagePath,
                             new Dimensions(100,50),
                             2,
                             System.TypeCode.UInt16,
                             null);
     Assert.AreEqual(100, image.Dimensions.Rows);
     Assert.AreEqual(50, image.Dimensions.Columns);
     Assert.AreEqual(2, image.BandCount);
     Assert.AreEqual(System.TypeCode.UInt16, image.BandType);
     Assert.AreEqual(null, image.Metadata);
     
     image.Close();  // needed or file stays locked after run of tests. why?
 }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        public IOutputRaster <T> Create <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 OutputRaster <T>(image));
        }
Exemple #6
0
        private bool disposed = false; // track whether resources have been released

        /// <summary>
        /// Constructor - takes an already constructed ERDAS image file
        /// </summary>
        public OutputRaster(ErdasImageFile image)
        {
            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");
                }
            }
        }
 private void TryCtor(string filename,
                      Dimensions dimensions,
                      int bandCount,
                      System.TypeCode bandType,
                      IMetadata metadata)
 {
     try {
         ErdasImageFile image = new ErdasImageFile(filename, dimensions,
                                                   bandCount, bandType,
                                                   metadata);
     }
     catch (System.Exception exc) {
         Data.Output.WriteLine(exc.Message);
         throw;
     }
 }
 public void WriteToReadable()
 {
     ErdasImageFile image = null;
     try {
         image = new ErdasImageFile(Data.MakeOutputPath("junk.gis"),
                                    RWFlag.Read);
         
         Erdas74Pixel8 pixel = new Erdas74Pixel8();
         
         // write after opening for Read
         image.WritePixel(pixel);
     }
     catch (System.Exception exc) {
         Data.Output.WriteLine(exc.Message);
         throw;
     }
     finally {
         if (image != null)
             image.Close();
     }
 }
     public void ReadFromWritable1()
     {
         ErdasImageFile image = null;
         try {
             image = new ErdasImageFile(Data.MakeOutputPath("junk.gis"),
                                          new Dimensions(10,10),
                                          1,
                                          System.TypeCode.Byte,
                                          null);
 
             Erdas74Pixel8 pixel = new Erdas74Pixel8();
 
             // read after opening for Write
             image.ReadPixel(pixel);
         }
         catch (System.Exception exc) {
             Data.Output.WriteLine(exc.Message);
             throw;
         }
         finally {
             if (image != null)
                 image.Close();
         }
     }
     public void WriteTooManyPixels()
     {
         ErdasImageFile image = null;
         try {
             Erdas74Pixel8 pixel = new Erdas74Pixel8();
             
             image = new ErdasImageFile(outputGisImagePath,
                                        new Dimensions(10,10),
                                        1,
                                        System.TypeCode.Byte,
                                        null);
 
             byte[] bytes = new byte[1];
             bytes[0] = 1;
             
             pixel[0].SetBytes(bytes,0);
             
             int pixCount = image.Dimensions.Rows * image.Dimensions.Columns;
 
             for (int i = 0; i < pixCount; i++)
             {
                 image.WritePixel(pixel);
             }
             
             // one too many
             image.WritePixel(pixel);
         }
         catch (System.Exception exc) {
             Data.Output.WriteLine(exc.Message);
             throw;
         }
         finally {
             if (image != null)
                 image.Close();
         }
         
     }
        public void WritePixels()
        {
            Erdas74Pixel8 pixel = new Erdas74Pixel8();
            
            ErdasImageFile
            image = new ErdasImageFile(outputGisImagePath,
                                       new Dimensions(10,10),
                                       1,
                                       System.TypeCode.Byte,
                                       null);

            byte[] bytes = new byte[1];
            bytes[0] = 1;
            
            pixel[0].SetBytes(bytes,0);
            
            int pixCount = image.Dimensions.Rows * image.Dimensions.Columns;
            
            for (int i = 0; i < pixCount; i++)
            {
                image.WritePixel(pixel);
            }
            
            image.Close();
            
        }
     public void ReadTooManyPixels()
     {
         ErdasImageFile image = null;
         try {
             image = new ErdasImageFile(inputLanImagePath, RWFlag.Read);
             
             FredLanPixel pixel = new FredLanPixel();
 
             int pixCount = image.Dimensions.Rows * image.Dimensions.Columns;
             
             for (int i = 0; i < pixCount; i++)
             {
                 image.ReadPixel(pixel);
             }
         
             // one too many
             image.ReadPixel(pixel);
         }
         catch (System.Exception exc) {
             Data.Output.WriteLine(exc.Message);
             throw;
         }
         finally {
             if (image != null)
                 image.Close();
         }
     }
 public void ReadPixels()
 {
     ErdasImageFile
     image = new ErdasImageFile(inputLanImagePath, RWFlag.Read);
     
     FredLanPixel pixel = new FredLanPixel();
     
     int pixCount = image.Dimensions.Rows * image.Dimensions.Columns;
     
     for (int i = 0; i < pixCount; i++)
     {
         image.ReadPixel(pixel);
     }
     
     image.Close();
 }
 private void TryOpen(string filename,
                      RWFlag rwFlag)
 {
     try {
         ErdasImageFile image = new ErdasImageFile(filename, rwFlag);
     }
     catch (System.Exception exc) {
         Data.Output.WriteLine(exc.Message);
         throw;
     }
 }
 public void OpenExistingWritable()
 {
     ErdasImageFile
     image = new ErdasImageFile(outputGisImagePath, RWFlag.Write);
     image.Close();
 }
 public void OpenExistingReadOnly()
 {
     ErdasImageFile
     image = new ErdasImageFile(inputGisImagePath, RWFlag.Read);
     image.Close();
 }