Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new Pyramid image, and uses the raster bounds to specify the number or rows and columns.
 /// No data is written at this time.
 /// </summary>
 /// <param name="filename"></param>
 /// <param name="bounds"></param>
 public PyramidImage(string filename, RasterBounds bounds)
 {
     Filename = filename;
     Bounds = bounds;
     CreateHeaders(bounds.NumRows, bounds.NumColumns, bounds.AffineCoefficients);
     base.Width = _header.ImageHeaders[0].NumColumns;
     base.Height = _header.ImageHeaders[0].NumRows;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates the bitmap from the raw image specified.  The bounds should be set on this later.
 /// </summary>
 /// <param name="rawImage">The raw image.</param>
 public MWImageData(Image rawImage)
 {
     _myImage = new Bitmap(rawImage.Width, rawImage.Height);
     Graphics g = Graphics.FromImage(_myImage);
     g.DrawImageUnscaled(rawImage, 0, 0);
     g.Dispose();
     WorldFile = new WorldFile();
     double[] aff = new[] { 1.0, 0, 0, -1.0, 0, _myImage.Height };
     Bounds = new RasterBounds(_myImage.Height, _myImage.Width, aff);
     MemorySetup();
 }
        /// <summary>
        /// Finds the average slope in the given polygons.
        /// </summary>
        /// <param name="poly">The Polygon.</param>
        /// <param name="output">The Raster.</param>
        /// <param name="progress">The progress handler.</param>
        public bool Execute(IFeatureSet poly, int noOfRow, int noOfCol, int selectionIndex, IRaster output, ICancelProgressHandler cancelProgressHandler)
        {
            //Validates the input and output data
            if (poly == null || output == null)
            {
                return false;
            }
            if (poly.FeatureType != FeatureTypes.Polygon)
                return false;

            //double CellSize = poly.Envelope.Width / 255;
            //int noOfRow = Convert.ToInt32(poly.Envelope.Height / CellSize);
            //int noOfCol = Convert.ToInt32(poly.Envelope.Width / CellSize);
            output=Raster.Create(output.Filename,"",noOfCol,noOfRow,1,typeof(int),new string[] { "" });

            RasterBounds bound = new RasterBounds(noOfRow, noOfCol, poly.Envelope);

            output.Bounds=bound;

            output.NoDataValue = -1;
            int current, previous = 0;
            double area = 0.0, previousArea = 0.0;
            double hCellWidth = output.CellWidth / 2;
            double hCellHeight = output.CellHeight / 2;
            ICoordinate[] coordinateCell=new Coordinate[4];
            int polyIndex = -1;
            bool cover = false;
            //IEnvelope env=null;
            for (int i = 0; i < output.NumRows; i++)
            {
                current = Convert.ToInt32(i*100 / output.NumRows);
                //only update when increment in percentage
                if (current > previous+5)
                {
                    cancelProgressHandler.Progress("", current, current.ToString() + "% progress completed");
                    previous = current;
                }

                for (int j = 0; j < output.NumColumns; j++)
                {
                    polyIndex = -1;
                    area = 0.0;
                    previousArea = 0.0;
                    cover=false;
                    ICoordinate cordinate=null;
                    cordinate = output.CellToProj(i, j);
                    //make the center of cell as point geometry
                    IPoint pt=new Point(cordinate);

                    for(int f=0;f<poly.Features.Count;f++)
                    {
                        if (selectionIndex == 0)
                        {
                            if (poly.Features[f].Covers(pt))
                            {
                                output.Value[i, j] = f;
                                cover = true;
                                break;
                            }
                            if (cancelProgressHandler.Cancel == true)
                                return false;
                        }
                        else //process area based selection
                        {
                            ICoordinate tempCo = new Coordinate(cordinate.X - hCellWidth, cordinate.Y - hCellHeight);
                            coordinateCell[0] = tempCo;
                            tempCo = new Coordinate(cordinate.X + hCellWidth, cordinate.Y - hCellHeight);
                            coordinateCell[1] = tempCo;
                            tempCo = new Coordinate(cordinate.X + hCellWidth, cordinate.Y + hCellHeight);
                            coordinateCell[2] = tempCo;
                            tempCo = new Coordinate(cordinate.X - hCellWidth, cordinate.Y + hCellHeight);
                            coordinateCell[3] = tempCo;

                            List<ICoordinate> ListCellCordinate = new List<ICoordinate>();
                            ListCellCordinate = coordinateCell.ToList<ICoordinate>();
                            IFeature cell = new Feature(FeatureTypes.Polygon, ListCellCordinate);
                            IFeature commonFeature=poly.Features[f].Intersection(cell);
                            if (commonFeature == null)
                                continue;
                            area=commonFeature.Area();
                            if (area > previousArea)
                            {
                                polyIndex = f;
                                cover = true;
                                previousArea = area;
                            }

                            if (cancelProgressHandler.Cancel == true)
                                return false;
                        }

                        
                    }
                    if (cover == true)
                    {
                        if (selectionIndex == 1)
                            output.Value[i, j] = polyIndex;
                    }
                    else
                        output.Value[i, j] = output.NoDataValue;
                }

            }
            //output.SaveAs(output.Filename);
            output.Save();
            //output.SaveAs(output.Filename);
            return true;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructs a new imagedata of the specified width and height.
 /// </summary>
 /// <param name="width"></param>
 /// <param name="height"></param>
 public MWImageData(int width, int height)
 {
     WorldFile = new WorldFile();
     double[] aff = new[] { 1.0, 0, 0, -1.0, 0, height };
     Bounds = new RasterBounds(height, width, aff);
     _myImage = new Bitmap(width, height);
     MemorySetup();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Uses a bitmap and a geographic envelope in order to define a new imageData object.
 /// </summary>
 /// <param name="rawImage">The raw image</param>
 /// <param name="bounds">The envelope bounds</param>
 public MWImageData(Bitmap rawImage, IEnvelope bounds)
 {
     _myImage = rawImage;
     Bounds = new RasterBounds(_myImage.Height, _myImage.Width, bounds);
     MemorySetup();
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Opens the file, assuming that the filename has already been specified using a Dot Net Image object
 /// </summary>
 public override void Open()
 {
     if (_myImage != null) _myImage.Dispose();
     Image temp;
     try
     {
         temp = Image.FromFile(Filename);
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show("The Dot Net Image object threw the following exception: " + ex.Message);
         return;
     }
     _myImage = new Bitmap(temp.Width, temp.Height, PixelFormat.Format32bppArgb);
     Graphics g = Graphics.FromImage(_myImage);
     g.DrawImage(temp, new Rectangle(0, 0, temp.Width, temp.Height));
     g.Dispose();
     temp.Dispose();
     WorldFile = new WorldFile(Filename);
     if (WorldFile.Affine == null)
     {
         WorldFile.Affine = new[] { .5, 1.0, 0, _myImage.Height - .5, 0, -1.0 };
     }
   
     Bounds = new RasterBounds(_myImage.Height, _myImage.Width, WorldFile.Affine);
     NumBands = 4;
     BytesPerPixel = 4;
     ReadBytes();
 }
        /// <summary>
        /// Executes the Erase Opaeration tool programaticaly
        /// Ping Yang deleted static for external testing 01/2010
        /// </summary>
        /// <param name="input">The input raster</param>
        /// <param name="oldValue">The original double value representing no-data</param>
        /// <param name="newValue">The new double value representing no-data</param>
        /// <param name="output">The output raster</param>
        /// <param name="cancelProgressHandler">The progress handler</param>
        /// <returns></returns>
        public bool Execute(IRaster input, double oldValue, double newValue,  IRaster output, ICancelProgressHandler cancelProgressHandler)
        {
            //Validates the input and output data
            if (input == null || newValue==0 || output == null)
            {
                return false;
            }

            IEnvelope envelope = input.Bounds.Envelope;

            int noOfCol=input.NumColumns;
            int noOfRow=input.NumRows;
            int previous = 0;


            //create output raster
            output = Raster.Create(output.Filename, "", noOfCol, noOfRow, 1, typeof(int), new[] { "" });
            RasterBounds bound = new RasterBounds(noOfRow, noOfCol, envelope);
            output.Bounds = bound;

            output.NoDataValue = input.NoDataValue;

            //Loop throug every cell
            int max = (output.Bounds.NumRows + 1);
            for (int i = 0; i < output.Bounds.NumRows; i++)
            {
                for (int j = 0; j < output.Bounds.NumColumns; j++)
                {
                        if (input.Value[i, j] == oldValue)
                            output.Value[i, j] = newValue;
                        else
                            output.Value[i, j] = input.Value[i, j];
                    
                    if (cancelProgressHandler.Cancel)
                        return false;
                }
                int current = Convert.ToInt32(Math.Round(i * 100D / max));
                //only update when increment in persentage
                if (current > previous)
                    cancelProgressHandler.Progress("", current, current + TextStrings.progresscompleted);
                previous = current;
            }

           // output = Temp;
            output.Save();
            return true;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Executes the Erase Opaeration tool programaticaly.
        /// Ping deleted static for external testing 01/2010
        /// </summary>
        /// <param name="input1">The input raster.</param>
        /// <param name="input2">The input raster.</param>
        /// <param name="output">The output raster.</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns></returns>
        public bool Execute(IRaster input1, IFeatureSet input2, IRaster output, ICancelProgressHandler cancelProgressHandler)
        {
            //Validates the input and output data
            if (input1 == null || input2 == null || output == null)
            {
                return false;
            }
            double cellWidth = input1.CellWidth;
            double cellHeight = input1.CellHeight;
            

            //Calculate the Intersect Envelope
            IEnvelope envelope1 = input1.Bounds.Envelope;
            IEnvelope envelope2 = input2.Envelope;
            envelope1 = envelope1.Intersection(envelope2);

            int noOfCol = Convert.ToInt32(envelope1.Height / cellHeight);

            int noOfRow = Convert.ToInt32(envelope1.Width / cellWidth);

            //create output raster
            output = Raster.Create(output.Filename, "", noOfCol, noOfRow, 1, typeof(int), new[] { "" });
            RasterBounds bound = new RasterBounds(noOfRow, noOfCol, envelope1);
            output.Bounds = bound;

            output.NoDataValue = input1.NoDataValue;

            RcIndex v1;
         
           // MapWindow.Analysis.Topology.Algorithm.PointLocator pointLocator1 = new MapWindow.Analysis.Topology.Algorithm.PointLocator();

            int previous = 0;

            int max = (output.Bounds.NumRows + 1);
            for (int i = 0; i < output.Bounds.NumRows; i++)
            {
                for (int j = 0; j < output.Bounds.NumColumns; j++)
                {
                    Coordinate cellCenter = output.CellToProj(i, j);
                   
                   

                    //test if the coordinate is inside of the polygon
                    bool isInside = false;
                    IFeature pointFeat = new Feature(new Point(cellCenter));
                        foreach (IFeature f in input2.Features)
                        {
                            if (f.Contains(pointFeat))
                            {
                                //output.Value[i, j] = val1;
                                isInside = true;
                                break;
                            }
                        }

                        if (isInside)
                        {
                            v1 = input1.ProjToCell(cellCenter);

                            double val1;
                            if (v1.Row <= input1.EndRow && v1.Column <= input1.EndColumn && v1.Row > -1 && v1.Column > -1)
                                val1 = input1.Value[v1.Row, v1.Column];
                            else
                                val1 = output.NoDataValue;

                            output.Value[i, j] = val1;
                        }
                        else
                        {
                            output.Value[i, j] = output.NoDataValue;
                        }
                 
                                        
                    if (cancelProgressHandler.Cancel)
                        return false;
                }
                int current = Convert.ToInt32(Math.Round(i * 100D / max));
                //only update when increment in percentage
                if (current > previous)
                    cancelProgressHandler.Progress("", current, current + TextStrings.progresscompleted);
                previous = current;
            }

            //output = Temp;
            output.Save();
            return true;
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Reads the header only from the specified mwi file.  The header is in xml format.
 /// This is a test.  We may have to jurry rig the thing to ensure it ignores the actual
 /// image content.
 /// </summary>
 /// <param name="filename">Whether this is the mwi or mwh file, this reads the mwh file for the filename.</param>
 public void ReadHeader(string filename)
 {
     string header = Path.ChangeExtension(filename, "mwh");
     XmlSerializer s = new XmlSerializer(typeof(PyramidHeader));
     TextReader r = new StreamReader(header);
     _header = (PyramidHeader) s.Deserialize(r);
     PyramidImageHeader ph = _header.ImageHeaders[0];
     Bounds = new RasterBounds(ph.NumRows, ph.NumColumns, ph.Affine);
     base.Width = _header.ImageHeaders[0].NumColumns;
     base.Height = _header.ImageHeaders[0].NumRows;
     r.Close();
 }
Ejemplo n.º 10
0
 /// <summary>
 /// This takes an original image and calculates the header content for all the lower resolution tiles.
 /// This does not actually write the bytes for those images.
 /// </summary>
 /// <param name="originalImage">The raster bounds for the original image.</param>
 public void CreateHeaders(RasterBounds originalImage)
 {
     Bounds = originalImage;
     CreateHeaders(originalImage.NumRows, originalImage.NumColumns, originalImage.AffineCoefficients);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Gets the size of the whole image, but doesn't keep the image open unless it was already open.
 /// </summary>
 /// <returns></returns>
 private void ReadHeader()
 {
     EnsureDatasetOpen();
     _numBands = _dataset.RasterCount;
     double[] test = new double[6];
     _dataset.GetGeoTransform(test);
     Bounds = new RasterBounds(_dataset.RasterYSize, _dataset.RasterXSize, test);
     _red = _dataset.GetRasterBand(1);
     _numOverviews = _red.GetOverviewCount();
     Close();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Calls the basic setup for the raster
 /// </summary>
 protected void Initialize()
 {
     StartRow = 0;
     EndRow = NumRows-1;
     StartColumn = 0;
     EndColumn = NumColumns-1;
     NumColumnsInFile = NumColumns;
     NumRowsInFile = NumRows;
     
     // Just set the cell size to one
     Bounds = new RasterBounds(NumRows, NumColumns, new[] { 0.5, 1.0, 0.0, NumRows - .5, 0.0, -1.0 });
     NumValueCells = 0;
     NoDataValue = short.MinValue;// sets the no-data value to the minimum value for the specified type.
     if (IsInRam)
     {
         Data = new short[NumRows][];
         for (short row = 0; row < NumRows; row++)
         {
             Data[row] = new short[NumColumns];
         }
     }
     Value = new ShortValueGrid(this);
     _shortNoDataValue = short.MinValue; // Sets it to the appropriate minimum for the int datatype
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates a new instance of ImageData
 /// </summary>
 public ImageData()
 {
     TypeName = "Image";
     _bounds = new RasterBounds(0, 0, new double[] { 0, 1, 0, 0, 0, -1 });
     _worldFile = new WorldFile();
 }
        /// <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();
            RasterDataTypes dataType = (RasterDataTypes) br.ReadInt32();
            if (dataType != RasterDataTypes.DOUBLE)
            {
                throw new ArgumentException(
                    MessageStrings.ArgumentOfWrongType_S1_S2.Replace("%S1", filename).Replace("%S2",
                                                                                              "BinaryDoubleRaster"));
            }
            DoubleNoDataValue = br.ReadDouble();

            string prj = Encoding.ASCII.GetString(br.ReadBytes(255)).Replace('\0', ' ').Trim();
            if (prj != null)
            {
                if (prj.Length == 0) Projection = null;
            }
            else
            {
                Projection = new ProjectionInfo();
                Projection.ReadProj4String(prj);
            }
            Notes = Encoding.ASCII.GetString(br.ReadBytes(255)).Replace('\0', ' ').Trim();
            if (Notes != null)
                if (Notes.Length == 0) Notes = null;
            br.Close();
        }
Ejemplo n.º 15
0
        /// <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)
        {
            // Our older formats used ASCII encoding for the characters, not Unicode.  The difference is that in the old fashion method,
            // of ASCII, each character is a single byte.  In Unicode, it is two bytes.  if we write Future binary handlers, however, they should use unicode,
            // not ASCII, and strings should just use the converter which has a string length followed by the unicode strings.
            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();
            RasterDataTypes dataType = (RasterDataTypes) br.ReadInt32();
            if (dataType != RasterDataTypes.SINGLE)
            {
                throw new ArgumentException(
                    MessageStrings.ArgumentOfWrongType_S1_S2.Replace("%S1", filename).Replace("%S2", "BinaryFloatRaster"));
            }
            FloatNoDataValue = br.ReadSingle();

            string proj = Encoding.ASCII.GetString(br.ReadBytes(255)).Replace('\0', ' ').Trim();
            Projection = new ProjectionInfo();
            Projection.ReadProj4String(proj);
            Notes = Encoding.ASCII.GetString(br.ReadBytes(255)).Replace('\0', ' ').Trim();
            if (Notes.Length == 0) Notes = null;
            br.Close();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Executes the Erase Opaeration tool programaticaly
        /// Ping Yang deleted static for external testing 01/2010
        /// </summary>
        /// <param name="input1">The input raster</param>
        /// <param name="input2">The input raster</param>
        /// <param name="output">The output raster</param>
        /// <param name="cancelProgressHandler">The progress handler</param>
        /// <returns></returns>
        public bool Execute(IRaster input1, IRaster input2, IRaster output, ICancelProgressHandler cancelProgressHandler)
        {
            //Validates the input and output data
            if (input1 == null || input2 == null || output == null)
            {
                return false;
            }

            IEnvelope envelope = UnionEnvelope(input1, input2);

            //Figures out which raster has smaller cells
            IRaster smallestCellRaster;
            if (input1.CellWidth < input2.CellWidth) smallestCellRaster = input1;
            else smallestCellRaster = input2;

            //Given the envelope of the two rasters we calculate the number of columns / rows
            int noOfCol = Convert.ToInt32(Math.Abs(envelope.Width / smallestCellRaster.CellWidth));
            int noOfRow = Convert.ToInt32(Math.Abs(envelope.Height / smallestCellRaster.CellHeight));

            
            //create output raster
            output = Raster.Create(output.Filename, "", noOfCol, noOfRow, 1, typeof(int), new[] { "" });
            RasterBounds bound = new RasterBounds(noOfRow, noOfCol, envelope);
            output.Bounds = bound;

            output.NoDataValue = input1.NoDataValue;

            RcIndex v1;
            RcIndex v2;

            int previous=0;
            int max = (output.Bounds.NumRows + 1);
            for (int i = 0; i < output.Bounds.NumRows; i++)
            {
                for (int j = 0; j < output.Bounds.NumColumns; j++)
                {
                    Coordinate I1 = output.CellToProj(i, j);
                    v1 = input1.ProjToCell(I1);
                    double val1;
                    if (v1.Row <= input1.EndRow && v1.Column <= input1.EndColumn && v1.Row > -1 && v1.Column > -1)
                        val1 = input1.Value[v1.Row, v1.Column];
                    else
                        val1 = input1.NoDataValue;

                    v2 = input2.ProjToCell(I1);
                    double val2;
                    if (v2.Row <= input2.EndRow && v2.Column <= input2.EndColumn && v2.Row > -1 && v2.Column > -1)
                        val2 = input2.Value[v2.Row, v2.Column];
                    else
                        val2 = input2.NoDataValue;

                    if (val1 == input1.NoDataValue && val2 == input2.NoDataValue)
                    {
                        output.Value[i, j] = output.NoDataValue;
                    }
                    else if (val1 != input1.NoDataValue && val2 == input2.NoDataValue)
                    {
                        output.Value[i, j] = output.NoDataValue;
                    }
                    else if (val1 == input1.NoDataValue && val2 != input2.NoDataValue)
                    {
                        output.Value[i, j] = output.NoDataValue;
                    }
                    else
                    {
                        output.Value[i, j] = val1 - val2;
                    }

                    if (cancelProgressHandler.Cancel)
                        return false;
                }
                int current = Convert.ToInt32(Math.Round(i * 100D / max));
                //only update when increment in persentage
                if (current > previous)
                    cancelProgressHandler.Progress("", current, current + TextStrings.progresscompleted);
                previous = current;
            }

            //output = Temp;
            output.Save();
            return true;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Executes the ReSample Opaeration tool programaticaly
        /// Ping deleted the static property for external testing
        /// </summary>
        /// <param name="input1">The input raster</param>
        /// <param name="oldCellSize">The size of the cells Hight</param>
        /// <param name="newCellSize">The size of the cells Width</param>
        /// <param name="output">The output raster</param>
        /// <param name="cancelProgressHandler">The progress handler</param>
        /// <returns></returns>
        public bool Execute(IRaster input1, double newCellHeight, double newCellWidth, IRaster output, ICancelProgressHandler cancelProgressHandler)
        {
            //Validates the input and output data
            if (input1 == null || newCellWidth == 0 || output == null)
            {
                return false;
            }
            IEnvelope envelope = input1.Bounds.Envelope;

            //Calculate new number of columns and rows
            int noOfCol = Convert.ToInt32(Math.Abs(envelope.Width / newCellWidth));
            int noOfRow = Convert.ToInt32(Math.Abs(envelope.Height / newCellHeight));

            int previous = 0;

            //************OLD Method
            ////Create the new raster with the appropriate dimensions
            //Raster Temp = new Raster();
            ////Temp.CreateNew(output.Filename, noOfRow, noOfCol, input1.DataType);
            //Temp.CreateNew(output.Filename, "", noOfCol, noOfRow, 1, input1.DataType, new string[] { "" });
            //Temp.CellWidth = newCellSize;
            //Temp.CellHeight = oldCellSize;
            //Temp.Xllcenter = input1.Bounds.Envelope.Minimum.X + (Temp.CellWidth / 2);
            //Temp.Yllcenter = input1.Bounds.Envelope.Minimum.Y + (Temp.CellHeight / 2);
            //***************

            //create output raster
            output = Raster.Create(output.Filename, "", noOfCol, noOfRow, 1, input1.DataType, new[] { "" });
            RasterBounds bound = new RasterBounds(noOfRow, noOfCol, envelope);
            output.Bounds = bound;

            output.NoDataValue = input1.NoDataValue;

            RcIndex index1;

            //Loop throug every cell for new value
            int max = (output.Bounds.NumRows + 1);
            for (int i = 0; i < output.Bounds.NumRows; i++)
            {
                for (int j = 0; j < output.Bounds.NumColumns; j++)
                {
                    //Projet the cell position to Map
                    Coordinate cellCenter = output.CellToProj(i, j);
                    index1=input1.ProjToCell(cellCenter);

                    double val;
                    if (index1.Row <= input1.EndRow && index1.Column <= input1.EndColumn && index1.Row > -1 && index1.Column > -1)
                    {
                        if (input1.Value[index1.Row, index1.Column] == input1.NoDataValue)
                            val = output.NoDataValue;
                        else
                            val = input1.Value[index1.Row, index1.Column];
                    }
                    else
                        val = output.NoDataValue;

                    output.Value[i, j] = val;
                    
                    if (cancelProgressHandler.Cancel)
                        return false;
                }
                int current = Convert.ToInt32(Math.Round(i * 100D / max));
                //only update when increment in persentage
                if (current > previous)
                    cancelProgressHandler.Progress("", current, current + TextStrings.progresscompleted);
                previous = current;
            }

            //output = Temp;
            output.Save();
            return true;
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Creates a new image and world file, placing the default bounds at the origin, with one pixel per unit.
 /// </summary>
 /// <param name="filename">The string filename</param>
 /// <param name="width">The integer width</param>
 /// <param name="height">The integer height</param>
 public override void CreateNew(string filename, int width, int height)
 {
     Filename = filename;
     WorldFile = new WorldFile();
     double[] aff = new[] { 1.0, 0, 0, -1.0, 0, height };
     Bounds = new RasterBounds(height, width, aff);
     WorldFile.Filename = WorldFile.GenerateFilename(filename);
     _myImage = new Bitmap(width, height);
     string ext = System.IO.Path.GetExtension(filename);
     switch (ext)
     {
         case ".bmp": _myImage.Save(filename, ImageFormat.Bmp); break;
         case ".emf": _myImage.Save(filename, ImageFormat.Emf); break;
         case ".exf": _myImage.Save(filename, ImageFormat.Exif); break;
         case ".gif": _myImage.Save(filename, ImageFormat.Gif); break;
         case ".ico": _myImage.Save(filename, ImageFormat.Icon); break;
         case ".jpg": _myImage.Save(filename, ImageFormat.Jpeg); break;
         case ".mbp": _myImage.Save(filename, ImageFormat.MemoryBmp); break;
         case ".png": _myImage.Save(filename, ImageFormat.Png); break;
         case ".tif": _myImage.Save(filename, ImageFormat.Tiff); break;
         case ".wmf": _myImage.Save(filename, ImageFormat.Wmf); break;
     }
     NumBands = 4;
     BytesPerPixel = 4;
     ReadBytes();
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Gets the size of the whole image, but doesn't keep the image open unless it was already open.
 /// </summary>
 /// <returns></returns>
 private void ReadHeader()
 {
     try
     {
         _dataset = Gdal.Open(Filename, Access.GA_Update);
     }
     catch
     {
         try
         {
             _dataset = Gdal.Open(Filename, Access.GA_ReadOnly);
         }
         catch (Exception ex)
         {
             throw new GdalException(ex.ToString());
         }
     }
     Width = _dataset.RasterXSize;
     Height = _dataset.RasterYSize;
     NumBands = _dataset.RasterCount;
     double[] test = new double[6];
     _dataset.GetGeoTransform(test);
     Bounds = new RasterBounds(base.Height, base.Width, test);
     WorldFile.Affine = test;
     Close();
 }
Ejemplo n.º 20
0
        /// <summary>
        /// This will resample the cells.
        /// If the cell size is zero, this will default to the shorter of the width or height
        /// divided by 256.
        /// </summary>
        /// <param name="input1">Input Raster.</param>
        /// <param name="cellHeight">New Cell Height or Null.</param>
        /// <param name="cellWidth">New Cell Width or Null.</param>
        /// <param name="destFilename">Output Raster Name.</param>
        /// <param name="progressHandler">An interface for handling the progress messages.</param>
        /// <returns>Resampled raster.</returns>
        public static IRaster ReSample(IRaster input1,double cellHeight, double cellWidth, string destFilename, IProgressHandler progressHandler)
        {
            if (input1 == null)
                return null;

            IEnvelope envelope = input1.Bounds.Envelope;

            if (cellHeight == 0)
            {
                cellHeight = envelope.Height / 256;
            }
            if(cellWidth==0)
            {
                cellWidth = envelope.Width / 256;
            }
                
            //Calculate new number of columns and rows
            int noOfCol = Convert.ToInt32(Math.Abs(envelope.Width / cellWidth));
            int noOfRow = Convert.ToInt32(Math.Abs(envelope.Height / cellHeight));


            IRaster output = Raster.Create(destFilename, "", noOfCol, noOfRow, 1, input1.DataType, new[] { "" });
            RasterBounds bound = new RasterBounds(noOfRow, noOfCol, envelope);
            output.Bounds = bound;

            output.NoDataValue = input1.NoDataValue;

            RcIndex index1;
            int max = (output.Bounds.NumRows);
            ProgressMeter pm = new ProgressMeter(progressHandler, "ReSize Cells", max);
            //Loop throug every cell for new value

            for (int i = 0; i < max; i++)
            {
                for (int j = 0; j < output.Bounds.NumColumns; j++)
                {
                    //Projet the cell position to Map
                    Coordinate cellCenter = output.CellToProj(i, j);
                    index1 = input1.ProjToCell(cellCenter);

                    double val;
                    if (index1.Row <= input1.EndRow && index1.Column <= input1.EndColumn && index1.Row > -1 && index1.Column > -1)
                    {
                        if (input1.Value[index1.Row, index1.Column] == input1.NoDataValue)
                            val = output.NoDataValue;
                        else
                            val = input1.Value[index1.Row, index1.Column];
                    }
                    else
                        val = output.NoDataValue;

                    output.Value[i, j] = val;
                }
                pm.CurrentPercent = i;
            }

            output.Save();
            pm.Reset();
            return output;
        }