当前位置: 首页>>代码示例>>C#>>正文


C# IRaster.CellToProj方法代码示例

本文整理汇总了C#中IRaster.CellToProj方法的典型用法代码示例。如果您正苦于以下问题:C# IRaster.CellToProj方法的具体用法?C# IRaster.CellToProj怎么用?C# IRaster.CellToProj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRaster的用法示例。


在下文中一共展示了IRaster.CellToProj方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RasterMath

        public bool RasterMath(IRaster input1, IRaster input2, IRaster output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input1 == null || input2 == null || output == null)
            {
                return false;
            }

            Extent envelope = UnionEnvelope(input1, input2);

            // Figures out which raster has smaller cells
            IRaster smallestCellRaster = input1.CellWidth < input2.CellWidth ? input1 : 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.CreateRaster(
                output.Filename, string.Empty, noOfCol, noOfRow, 1, typeof(int), new[] { string.Empty });
            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 cellCenter = output.CellToProj(i, j);
                    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 = input1.NoDataValue;
                    }

                    v2 = input2.ProjToCell(cellCenter);
                    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] = Operation(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(string.Empty, current, current + TextStrings.progresscompleted);
                }

                previous = current;
            }

            // output = Temp;
            output.Save();
            return true;
        }
开发者ID:ExRam,项目名称:DotSpatial-PCL,代码行数:95,代码来源:RasterMagic.cs

示例2: Execute

        /// <summary>
        /// Executes the Area tool with programatic input
        /// Ping delete static for external testing
        /// </summary>
        /// <param name="input">The input raster</param>
        /// <param name="output">The output polygon feature set</param>
        /// <param name="zField">The field name containing the values to interpolate</param>
        /// <param name="cellSize">The double geographic size of the raster cells to create</param>
        /// <param name="power">The double power representing the inverse</param>
        /// <param name="neighborType">Fixed distance of fixed number of neighbors</param>
        /// <param name="pointCount">The number of neighbors to include if the neighborhood type
        /// is Fixed</param>
        /// <param name="distance">Points further from the raster cell than this distance are not included 
        /// in the calculation if the neighborhood type is Fixed Distance.</param>
        /// <param name="output">The output raster where values are stored.  The filename is used, but the number
        /// of rows and columns will be computed from the cellSize and input featureset</param>
        /// <param name="cancelProgressHandler">A progress handler for receiving progress messages</param>
        /// <returns>A boolean, true if the IDW process worked correctly</returns>
        public bool Execute(IFeatureSet input, string zField, double cellSize, double power, NeighborhoodType neighborType, int pointCount, double distance, IRaster output, ICancelProgressHandler cancelProgressHandler)
        {
           
            //Validates the input and output data
            if (input == null || output == null)
                return false;

            //If the cellSize is 0 we calculate a cellsize based on the input extents
            if (cellSize == 0)
                cellSize = input.Envelope.Width / 255;

            //Defines the dimesions and position of the raster
            int numColumns = Convert.ToInt32(Math.Round(input.Envelope.Width / cellSize));
            int numRows = Convert.ToInt32(Math.Round(input.Envelope.Height / cellSize));
          
            output = Raster.Create(output.Filename, "",numColumns, numRows, 1, typeof(double), new[] {""} );

            output.CellHeight = cellSize;
            output.CellWidth = cellSize;
            output.Xllcenter = input.Envelope.Minimum.X + (cellSize/2);
            output.Yllcenter = input.Envelope.Minimum.Y + (cellSize/2);

            //Used to calculate progress
            int lastUpdate=0;

            //Populates the KD tree
            MapWindow.Analysis.Topology.KDTree.KDTree kd = new MapWindow.Analysis.Topology.KDTree.KDTree(2);
            List<int> randomList = new List<int>();
            for (int i = 0; i < input.Features.Count; i++)
            {
                randomList.Add(i);
            }

            Random rnd = new Random();
            List<int> completed = new List<int>();
            while (randomList.Count > 0)
            {
                int index = rnd.Next(0,randomList.Count -1);
                Coordinate coord = input.Features[randomList[index]].Coordinates[0];
                while (kd.Search(coord.ToArray()) != null)
                    coord.X = coord.X * 1.000000000000001D;                    
                kd.Insert(coord.ToArray(), input.Features[randomList[index]]);
                completed.Add(randomList[index]);
                randomList.RemoveAt(index);
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            //Makes sure we don't try to search for more points then exist
            if (kd.Count < pointCount)
                pointCount = kd.Count;

            if (neighborType == NeighborhoodType.FixedCount)
            {
                //we add all the old features to output
                for (int x = 0; x < numColumns; x++)
                {
                    for (int y = 0; y < numRows; y++)
                    {                     
                        //Gets the pointCount number of cells closest to the current cell
                        Coordinate cellCenter = output.CellToProj(y, x);
                        Double[] pixelCoord = new double[2];
                        pixelCoord[0] = output.CellToProj(y, x).X;
                        pixelCoord[1] = output.CellToProj(y, x).Y;
                        sw.Start();
                        object[] result = kd.Nearest(pixelCoord, pointCount);
                        sw.Stop();

                        //Sets up the IDW numerator and denominator
                        double top = 0;
                        double bottom = 0;
                        foreach (object feat in result)
                        {
                              IFeature featurePt = feat as Feature;
                              if (featurePt == null) continue;
                              double distanceToCell = cellCenter.Distance(featurePt.Coordinates[0]);
                              if (distanceToCell <= distance || distance == 0)
                              {
                                  //If we can't convert the value to a double throw it out
                                  try
                                  {
                                      Convert.ToDouble(featurePt.DataRow[zField]);
//.........这里部分代码省略.........
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:101,代码来源:IDW.cs

示例3: Execute

        /// <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;
        }
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:96,代码来源:ClipWithPolygon.cs

示例4: Execute

        /// <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;
        }
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:82,代码来源:ReSampleGrid.cs

示例5: getCellCornerPoint

        private Point getCellCornerPoint(IRaster g, int x, int y, int corner)
        {
            ICoordinate center;
            double centerX;
            double centerY;
            double hcellwidth;
            double hcellheight;
            double cornerX;
            double cornerY;
            
            hcellwidth = g.CellWidth/2;
            hcellheight = g.CellHeight/2;
            center = g.CellToProj(x, y);
            centerX = center.X;
            centerY = center.Y;
            switch (corner)
            {
                case 2:
                    {
                        cornerX = centerX + hcellwidth;
                        cornerY = centerY - hcellheight;
                        break;
                    }
                case 4:
                    {
                        cornerX = centerX - hcellwidth;
                        cornerY = centerY - hcellheight;
                        break;
                    }
                case 6:
                    {
                        cornerX = centerX - hcellwidth;
                        cornerY = centerY + hcellheight;
                        break;
                    }
                case 8:
                    {
                        cornerX = centerX + hcellwidth;
                        cornerY = centerY + hcellheight;
                        break;
                    }
                default:
                    {
                        cornerX = -1;
                        cornerY = -1;
                        break;
                    }
            }

            Point tmpPoint = new Point(cornerX, cornerY);
            return tmpPoint;
        }
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:52,代码来源:mwSimpleRasterToPolygon.cs

示例6: fillTrackGrid

 private void fillTrackGrid(IRaster gridTrack, IFeatureSet polyOut, int idxToFill)
 {
     int rowStart;
     int rowStop;
     int colStart;
     int colStop;
     RcIndex start;
     RcIndex stop;
     ICoordinate I;
     start = gridTrack.ProjToCell(polyOut.Features[idxToFill].Envelope.Minimum.X, polyOut.Features[idxToFill].Envelope.Maximum.Y);
     stop = gridTrack.ProjToCell(polyOut.Features[idxToFill].Envelope.Maximum.X, polyOut.Features[idxToFill].Envelope.Minimum.Y);
     rowStart = start.Row;
     colStart = start.Column;
     rowStop = stop.Row;
     colStop = stop.Column;
     for (int rowcell = rowStart; rowcell <= rowStop; rowcell++)
     {
         for (int colcell = colStart; colcell <= colStop; colcell++)
         {
             I = gridTrack.CellToProj(rowcell, colcell);
             Point pt = new Point(I);
             if (polyOut.Features[idxToFill].Covers(pt))
             {
                 gridTrack.Value[rowcell, colcell] = 1;
             }
         }
     }
 }
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:28,代码来源:mwSimpleRasterToPolygon.cs

示例7: Execute

        /// <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)
//.........这里部分代码省略.........
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:101,代码来源:mwPolygonToRaster.cs


注:本文中的IRaster.CellToProj方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。