Esempio n. 1
0
 /// <summary>
 /// Extends the IRaster interface to return the coordinate of the center of a row column position.
 /// </summary>
 /// <param name="raster">The raster interface to extend</param>
 /// <param name="position">The zero based integer index of the row and column of the cell to locate</param>
 /// <returns>The geographic location of the center of the specified cell</returns>
 public static Coordinate CellToProj(this IRaster raster, RcIndex position)
 {
     if (raster == null)
     {
         return(null);
     }
     if (raster.Bounds == null)
     {
         return(null);
     }
     return(raster.Bounds.CellCenter_ToProj(position.Row, position.Column));
 }
Esempio n. 2
0
        /// <summary>
        /// The affine transform can make figuring out what rows and columns are needed from the original image
        /// in order to correctly fill a geographic extent challenging.  This attempts to handle that back projection
        /// problem.  It returns a System.Drawing.Rectangle in pixel (cell) coordinates that is completely contains
        /// the geographic extents, but is not larger than the bounds of the underlying image.  It back projects
        /// all four corners of the extent and returns the bounding rectangle clipped by the image rectangle.
        /// </summary>
        /// <param name="self"></param>
        /// <param name="extent"></param>
        /// <returns></returns>
        public static Rectangle CellsContainingExtent(this IRasterBounds self, Extent extent)
        {
            List <Coordinate> coords = new List <Coordinate>
            {
                new Coordinate(extent.MinX, extent.MaxY),
                new Coordinate(extent.MaxX, extent.MaxY),
                new Coordinate(extent.MinX, extent.MinY),
                new Coordinate(extent.MaxX, extent.MinY)
            };
            int minX = self.NumColumns;
            int minY = self.NumRows;
            int maxX = 0;
            int maxY = 0;

            foreach (Coordinate c in coords)
            {
                RcIndex rowCol = self.ProjToCell(c);
                if (rowCol.Row < minY)
                {
                    minY = rowCol.Row;
                }
                if (rowCol.Column < minX)
                {
                    minX = rowCol.Column;
                }
                if (rowCol.Row > maxY)
                {
                    maxY = rowCol.Row;
                }
                if (rowCol.Column > maxX)
                {
                    maxX = rowCol.Column;
                }
            }
            if (minX < 0)
            {
                minX = 0;
            }
            if (minY < 0)
            {
                minY = 0;
            }
            if (maxX > self.NumColumns)
            {
                maxX = self.NumColumns;
            }
            if (maxY > self.NumRows)
            {
                maxY = self.NumRows;
            }
            return(new Rectangle(minX, minY, maxX - minX, maxY - minY));
        }
Esempio n. 3
0
        /// <summary>
        /// Retrieves the location from the cell that is closest to the specified coordinates. This will
        /// do nothing if the specified coordinates are outside of the raster.
        /// </summary>
        /// <param name="raster">The IRaster to set the value for</param>
        /// <param name="location">An Icoordinate specifying the location</param>
        /// <param name="value">The value to assign to the nearest cell to the specified location</param>
        public static void SetNearestValue(this IRaster raster, Coordinate location, double value)
        {
            RcIndex position = raster.ProjToCell(location.X, location.Y);

            if (position.Row < 0 || position.Row >= raster.NumRows)
            {
                return;
            }
            if (position.Column < 0 || position.Column >= raster.NumColumns)
            {
                return;
            }
            raster.Value[position.Row, position.Column] = value;
        }
Esempio n. 4
0
        /// <summary>
        /// Retrieves the location from the cell that is closest to the specified coordinates. This will
        /// do nothing if the specified coordinates are outside of the raster.
        /// </summary>
        /// <param name="raster">The IRaster to set the value for</param>
        /// <param name="x">The longitude or horizontal coordinate</param>
        /// <param name="y">The latitude or vertical coordinate</param>
        /// <param name="value">The value to assign to the nearest cell to the specified location</param>
        public static void SetNearestValue(this IRaster raster, double x, double y, double value)
        {
            RcIndex position = raster.ProjToCell(x, y);

            if (position.Row < 0 || position.Row >= raster.NumRows)
            {
                return;
            }
            if (position.Column < 0 || position.Column >= raster.NumColumns)
            {
                return;
            }
            raster.Value[position.Row, position.Column] = value;
        }
Esempio n. 5
0
        /// <summary>
        /// Retrieves the data from the cell that is closest to the specified coordinates. This will
        /// return a No-Data value if the specified coordintes are outside of the grid.
        /// </summary>
        /// <param name="raster">The raster to get the value from</param>
        /// <param name="x">The longitude or horizontal coordinate</param>
        /// <param name="y">The latitude or vertical coordinate</param>
        /// <returns>The double value of the cell that has a center closest to the specified coordinates</returns>
        public static double GetNearestValue(this IRaster raster, double x, double y)
        {
            RcIndex position = raster.ProjToCell(x, y);

            if (position.Row < 0 || position.Row >= raster.NumRows)
            {
                return(raster.NoDataValue);
            }
            if (position.Column < 0 || position.Column >= raster.NumColumns)
            {
                return(raster.NoDataValue);
            }
            return(raster.Value[position.Row, position.Column]);
        }
Esempio n. 6
0
        /// <summary>
        /// Retrieves the data from the cell that is closest to the specified coordinates. This will
        /// return a No-Data value if the specified coordintes are outside of the grid.
        /// </summary>
        /// <param name="raster">The raster to get the value from</param>
        /// <param name="location">A valid implementation of Icoordinate specifying the geographic location.</param>
        /// <returns>The value of type T of the cell that has a center closest to the specified coordinates</returns>
        public static double GetNearestValue(this IRaster raster, Coordinate location)
        {
            RcIndex position = raster.ProjToCell(location.X, location.Y);

            if (position.Row < 0 || position.Row >= raster.NumRows)
            {
                return(raster.NoDataValue);
            }
            if (position.Column < 0 || position.Column >= raster.NumColumns)
            {
                return(raster.NoDataValue);
            }
            return(raster.Value[position.Row, position.Column]);
        }
Esempio n. 7
0
 /// <summary>
 /// Extends the IRaster interface to return the coordinate of the center of a row column position.
 /// </summary>
 /// <param name="raster">The raster interface to extend</param>
 /// <param name="position">The zero based integer index of the row and column of the cell to locate</param>
 /// <returns>The geographic location of the center of the specified cell</returns>
 public static Coordinate CellToProj(this IRaster raster, RcIndex position)
 {
     return(raster?.Bounds?.CellCenterToProj(position.Row, position.Column));
 }
Esempio n. 8
0
 /// <summary>
 /// Extends the IRaster interface to return the coordinate of the center of a row column position.
 /// </summary>
 /// <param name="raster">The raster interface to extend</param>
 /// <param name="position">The zero based integer index of the row and column of the cell to locate</param>
 /// <returns>The geographic location of the center of the specified cell</returns>
 public static Coordinate CellToProj(this IRaster raster, RcIndex position)
 {
     if (raster == null) return null;
     if (raster.Bounds == null) return null;
     return raster.Bounds.CellCenter_ToProj(position.Row, position.Column);
 }