//Convert point to pixel
        private RcIndex Point_to_Raster(IMapPointLayer point, IRaster ExecuteRaster)
        {
            IFeatureSet featureSet = point.DataSet;

            if (featureSet.Features.Count > 1 || featureSet.Features.Count <= 0)
            {
                //只能有一个点,不能没有点
                MessageBox.Show("The point is invalid!", "Admin", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(new RcIndex(-9999, -9999));
            }
            Coordinate coor = featureSet.Features[0].Geometry.Coordinates[0]; //获取点要素的坐标
            RcIndex    rc   = ExecuteRaster.Bounds.ProjToCell(coor);          //获取点要素对应的栅格坐标

            return(rc);
        }
        public void Execute()
        {
            RcIndex               rc     = Point_to_Raster(pointLayer, Accumulation);
            RasterPixel_2         rp1    = new RasterPixel_2(rc.Row, rc.Column, Accumulation.Value[rc.Row, rc.Column], Surface.Value[rc.Row, rc.Column]);
            Stack <RasterPixel_2> RpArr1 = new Stack <RasterPixel_2>();
            Stack <RasterPixel_2> RpArr2 = new Stack <RasterPixel_2>();

            RpArr1.Push(rp1);
            Label.Value[rp1.Row, rp1.Column] = rp1.Value2;
            do
            {
                RasterPixel_2 rp2 = RpArr1.Pop();
                RpArr2.Push(rp2);
                is_Satisfy(rp2.Row, rp2.Column, rp2.Row, rp2.Column - 1, Radius, Accumulation, Surface, Label, RpArr1);     //Left
                is_Satisfy(rp2.Row, rp2.Column, rp2.Row, rp2.Column + 1, Radius, Accumulation, Surface, Label, RpArr1);     //Right
                is_Satisfy(rp2.Row, rp2.Column, rp2.Row - 1, rp2.Column, Radius, Accumulation, Surface, Label, RpArr1);     //Top
                is_Satisfy(rp2.Row, rp2.Column, rp2.Row + 1, rp2.Column, Radius, Accumulation, Surface, Label, RpArr1);     //Bottom
                is_Satisfy(rp2.Row, rp2.Column, rp2.Row - 1, rp2.Column - 1, Radius, Accumulation, Surface, Label, RpArr1); //TopLeft
                is_Satisfy(rp2.Row, rp2.Column, rp2.Row - 1, rp2.Column + 1, Radius, Accumulation, Surface, Label, RpArr1); //TopRight
                is_Satisfy(rp2.Row, rp2.Column, rp2.Row + 1, rp2.Column - 1, Radius, Accumulation, Surface, Label, RpArr1); //BottomLeft
                is_Satisfy(rp2.Row, rp2.Column, rp2.Row + 1, rp2.Column + 1, Radius, Accumulation, Surface, Label, RpArr1); //BottomRight
            } while (RpArr1.Count > 0);
            RasterPixel_2 rp3        = Search_pour_pixel(RpArr2);
            Coordinate    ResultCoor = Rc_to_Coor(rp3.Row, rp3.Column, Accumulation);

            FeatureSet pointF = new FeatureSet(FeatureType.Point);

            pointF.Projection = Accumulation.Projection;
            DataColumn Column1 = new DataColumn("ID");

            pointF.DataTable.Columns.Add(Column1);
            DataColumn Column2 = new DataColumn("Accumulation");

            pointF.DataTable.Columns.Add(Column2);
            DataColumn Column3 = new DataColumn("Elevation");

            pointF.DataTable.Columns.Add(Column3);

            Point    point          = new Point(ResultCoor);
            IFeature currentFeature = pointF.AddFeature(point);

            currentFeature.DataRow["ID"]           = 0;
            currentFeature.DataRow["Accumulation"] = rp3.Value1;
            currentFeature.DataRow["Elevation"]    = rp3.Value2;
            pointF.SaveAs(savePath, false);
            MainMap.Layers.Add(pointF);
        }
Beispiel #3
0
        public void TestMethod1()
        {
            double[] affine = new double[6];
            affine[0] = 10;
            affine[1] = 1;
            affine[2] = .2;
            affine[3] = 100;
            affine[4] = .2;
            affine[5] = -1.2;
            RasterBounds rb  = new RasterBounds(100, 100, affine);
            int          row = 40;
            int          col = 30;
            Coordinate   c   = rb.CellCenter_ToProj(row, col);
            RcIndex      rc  = rb.ProjToCell(c);

            Assert.AreEqual(rc.Row, row);
            Assert.AreEqual(rc.Column, col);
        }
        /// <summary>
        /// Finds the average slope in the given polygons.
        /// </summary>
        /// <param name="ras">The dem Raster(Grid file).</param>
        /// <param name="zFactor">The scaler factor</param>
        /// <param name="poly">The flow poly shapefile path.</param>
        /// <param name="output">The resulting DEM of slopes</param>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        public bool Execute(
            IRaster ras,
            double zFactor,
            IFeatureSet poly,
            IFeatureSet output,
            ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (ras == null || poly == null || output == null)
            {
                return(false);
            }

            output.FeatureType = poly.FeatureType;
            foreach (IFeature f in poly.Features)
            {
                output.Features.Add(f);
            }

            output.DataTable.Columns.Add("FID", typeof(int));
            output.DataTable.Columns.Add(TextStrings.AveSlope, typeof(Double));

            IRaster slopeGrid = new Raster {
                DataType = ras.DataType, Bounds = ras.Bounds
            };

            // FeatureSet polyShape = new FeatureSet();
            int previous = 0;

            if (Slope(ref ras, zFactor, false, ref slopeGrid, cancelProgressHandler) == false)
            {
                return(false);
            }

            int shapeCount = output.Features.Count;

            int[]    areaCount = new int[shapeCount];
            double[] areaTotal = new double[shapeCount];
            double[] areaAve   = new double[shapeCount];
            double   dxHalf    = slopeGrid.CellWidth / 2;
            double   dyHalf    = slopeGrid.CellHeight / 2;

            // check whether those two envelope are intersect
            if (ras.Extent.Intersects(output.Extent) == false)
            {
                return(false);
            }

            RcIndex start = slopeGrid.ProjToCell(output.Extent.MinX, output.Extent.MaxY);
            RcIndex stop  = slopeGrid.ProjToCell(output.Extent.MaxX, output.Extent.MinY);

            int rowStart = start.Row;
            int colStart = start.Column;
            int rowStop  = stop.Row;
            int colStop  = stop.Column;

            for (int row = rowStart - 1; row < rowStop + 1; row++)
            {
                int current = Convert.ToInt32((row - rowStart + 1) * 100.0 / (rowStop + 1 - rowStart + 1));

                // only update when increment in percentage
                if (current > previous + 5)
                {
                    cancelProgressHandler.Progress(string.Empty, current, current + TextStrings.progresscompleted);
                    previous = current;
                }

                for (int col = colStart - 1; col < colStop + 1; col++)
                {
                    Coordinate cent  = slopeGrid.CellToProj(row, col);
                    double     xCent = cent.X;
                    double     yCent = cent.Y;
                    for (int shpindx = 0; shpindx < output.Features.Count; shpindx++)
                    {
                        IFeature tempFeat = output.Features[shpindx];
                        Point    pt1      = new Point(xCent, yCent);
                        Point    pt2      = new Point(xCent - dxHalf, yCent - dyHalf);
                        Point    pt3      = new Point(xCent + dxHalf, yCent - dyHalf);
                        Point    pt4      = new Point(xCent + dxHalf, yCent + dyHalf);
                        Point    pt5      = new Point(xCent - dxHalf, yCent + dyHalf);
                        if ((((!tempFeat.Covers(pt1) && !tempFeat.Covers(pt2)) && !tempFeat.Covers(pt3)) &&
                             !tempFeat.Covers(pt4)) && !tempFeat.Covers(pt5))
                        {
                            continue;
                        }

                        areaCount[shpindx]++;
                        areaTotal[shpindx] += slopeGrid.Value[row, col] / 100;

                        if (cancelProgressHandler.Cancel)
                        {
                            return(false);
                        }
                    }
                }
            }

            for (int shpindx = 0; shpindx < output.Features.Count; shpindx++)
            {
                if (areaCount[shpindx] == 0)
                {
                    areaAve[shpindx] = 0;
                }
                else
                {
                    areaAve[shpindx] = areaTotal[shpindx] / areaCount[shpindx];
                }

                output.Features[shpindx].DataRow["FID"] = shpindx;
                output.Features[shpindx].DataRow[TextStrings.AveSlope] = areaAve[shpindx];
            }

            poly.Close();
            slopeGrid.Close();
            output.SaveAs(output.Filename, true);
            return(true);
        }
Beispiel #5
0
 /// <summary>
 /// Checks whether this and other are equal.
 /// </summary>
 /// <param name="other">The other RcIndex.</param>
 /// <returns>True if both are equal.</returns>
 public bool Equals(RcIndex other)
 {
     return(Column == other.Column && Row == other.Row);
 }
        void CratePvPole(double xSpacing, IMapFeatureLayer BLineFeLyr)
        {
            project.NumPvPanel = 0;
            IMapRasterLayer demLyr;
            Raster          dem4Pv = new Raster();
            double          poleH  = 1; //Default pole height = 1 m.
            double          z0     = 0;

            try { poleH = Convert.ToDouble(txtPoleHeight.Text); }
            catch
            {
                MessageBox.Show("Pole height value error");
                txtPoleHeight.Text = "1";
                poleH = 1;
            }

            if (project.LyrDEM != -1 & chkDEM.Checked == true)
            {
                demLyr = pvMap.Layers[project.LyrDEM] as IMapRasterLayer;

                if (demLyr == null)
                {
                    MessageBox.Show("Error: DEM Data is not correct");
                    return;
                }

                int mRow = demLyr.Bounds.NumRows;
                int mCol = demLyr.Bounds.NumColumns;
                dem4Pv = (Raster)demLyr.DataSet;
                Coordinate ptReference = new Coordinate(project.UtmE, project.UtmN);
                RcIndex    rc          = dem4Pv.ProjToCell(ptReference);
                //RcIndex rc = demLyr.DataSet.ProjToCell(ptReference);
                if (rc.Column < 0 | rc.Row < 0)
                {
                    z0 = 0;
                }
                else
                {
                    z0 = dem4Pv.Value[rc.Row, rc.Column];
                    //z0 = demLyr.DataSet.Value[rc.Row, rc.Column];
                }
            }
            //------------------------------------------------------------------------------------------------
            // Create pole posion from baseline shapefile
            //------------------------------------------------------------------------------------------------

            int    nShp = BLineFeLyr.DataSet.NumRows(); // get Number of Feature
            double dx   = xSpacing;                     //m.

            FeatureSet fs;

            fs = new FeatureSet(FeatureType.Point);
            //---------------------------------------------------------
            fs.DataTable.Columns.Add(new DataColumn("x", typeof(double)));
            fs.DataTable.Columns.Add(new DataColumn("y", typeof(double)));
            fs.DataTable.Columns.Add(new DataColumn("w", typeof(double)));
            fs.DataTable.Columns.Add(new DataColumn("h", typeof(double)));
            fs.DataTable.Columns.Add(new DataColumn("Azimuth", typeof(double)));
            fs.DataTable.Columns.Add(new DataColumn("Ele_Angle", typeof(double)));
            fs.DataTable.Columns.Add(new DataColumn("ele", typeof(double)));
            //---------------------------------------------------------

            for (int i = 0; i < nShp; i++) //Line shape
            {
                IFeature BLineFe = BLineFeLyr.DataSet.GetFeature(i);
                if (chkSystemSpacing.Checked == true)
                {
                    dx = Convert.ToDouble(txtDx.Text);
                }
                else
                {
                    try
                    {
                        object val = BLineFe.DataRow["spacing"];
                        dx = (double)val;
                        if (dx <= 0)
                        {
                            MessageBox.Show("Error: Spacing data incorrect.");
                            return;
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Error: Spacing data not found.");
                        project.Verify[5] = false;
                        return;
                    }
                }
                xSpacing = dx;
                double sumSegment  = 0;
                double sumL        = 0;
                double iniSegment  = 0;
                double LastSegment = 0;
                for (int n = 0; n < BLineFe.NumPoints - 1; n++) //Line segment
                {
                    double x1    = BLineFe.Coordinates[n].X;
                    double y1    = BLineFe.Coordinates[n].Y;
                    double x2    = BLineFe.Coordinates[n + 1].X;
                    double y2    = BLineFe.Coordinates[n + 1].Y;
                    double LastL = sumL;
                    double dL;

                    sumL      += Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
                    sumSegment = LastSegment;
                    if (sumSegment + xSpacing <= sumL | sumSegment == 0)
                    {
                        for (double Segment = sumSegment; Segment <= sumL; Segment += xSpacing)
                        {
                            dL = Segment - LastL;
                            Coordinate poleLocation = util.PointOnTheLine(x1, y1, x2, y2, dL);
                            if (poleLocation != null)
                            {
                                LastSegment += xSpacing;

                                double poleHeight = Convert.ToDouble(txtPoleHeight.Text);

                                //Coordinate poleLocation = new Coordinate(pt.X, pt.Y, poleHeight);
                                IPoint   poleFe = new DotSpatial.Topology.Point(poleLocation);
                                IFeature ifea   = fs.AddFeature(poleFe);
                                project.NumPvPanel++;

                                //------------------------------------------------------
                                ifea.DataRow.BeginEdit();
                                ifea.DataRow["x"]         = poleLocation.X;
                                ifea.DataRow["y"]         = poleLocation.Y;
                                ifea.DataRow["w"]         = 0;
                                ifea.DataRow["h"]         = 0;
                                ifea.DataRow["Azimuth"]   = 0;
                                ifea.DataRow["Ele_Angle"] = 0;

                                if (project.LyrDEM != -1 & chkDEM.Checked == true)
                                {
                                    RcIndex rc = dem4Pv.ProjToCell(poleLocation);
                                    double  z  = 0;
                                    if (rc.Column < 0 | rc.Row < 0)
                                    {
                                        z = 0;
                                    }
                                    else
                                    {
                                        z = dem4Pv.Value[rc.Row, rc.Column];
                                    }
                                    //demLyr.DataSet
                                    if (radioAboveAssumeDatum.Checked == true)
                                    {
                                        ifea.DataRow["ele"] = poleH;
                                    }
                                    else
                                    {
                                        ifea.DataRow["ele"] = z - z0 + poleH;
                                    }
                                }
                                else
                                {
                                    ifea.DataRow["ele"] = poleH;
                                }
                                ifea.DataRow.EndEdit();
                            }
                        }
                    }
                }
            } // next alignment shape

            fs.Projection = pvMap.Projection;

            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            fs.Name     = "Panel Positon";
            fs.Filename = project.Path + "\\Temp\\" + fs.Name + ".shp";
            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

            fs.SaveAs(fs.Filename, true);
            util.removeDupplicateLyr(fs.Name, pvMap);
            PointSymbolizer p = new PointSymbolizer(Color.Yellow, DotSpatial.Symbology.PointShape.Hexagon, 6);

            p.ScaleMode = ScaleMode.Simple;
            MapPointLayer kasem = new MapPointLayer(fs);

            kasem.Symbolizer = p;
            pvMap.Layers.Add(kasem);

            //loadLayerList();
            //pvMap.MapFrame.DrawingLayers.Clear();
            util.ClearGraphicMap(pvMap);
            project.LyrPoleName = fs.Name;


            /*
             * MapPointLayer rangeRingAxis;
             * rangeRingAxis = new MapPointLayer(fs);
             * pvMap.MapFrame.DrawingLayers.Add(rangeRingAxis);
             * pvMap.MapFrame.Invalidate();
             */
            //project.Verify[5] = true;
            //updateArea();
        }
Beispiel #7
0
        //Extracts the elevation data from the raster layers that lie on the path from the first to the last coordinate
        private void getElevationData(List <Coordinate> coordinates)
        {
            double     curX;
            double     curY;
            double     curElevation = 0;
            double     constXdif, constYdif;
            double     xAxisValue = 0;
            Coordinate a, b, temp;
            int        numberOfRasterLayers = rasterLayers.Length;
            int        pointsOnThisLine;

            //iterate through all line segments
            for (int i = 0; i < coordinates.Count - 1; i++)
            {
                a = coordinates[i];
                b = coordinates[i + 1];
                pointsOnThisLine = (int)(distanceTo(a, b) / totalDist * numberofpoints);
                constXdif        = (Math.Abs(a.X - b.X) / pointsOnThisLine);
                constYdif        = (Math.Abs(a.Y - b.Y) / pointsOnThisLine);

                //extract the appropriate number of points for this line
                for (int j = 0; j < pointsOnThisLine; j++)
                {
                    //x coordinate on graph for this location
                    switch (xUnits)
                    {
                    case Units.Meters:
                        xAxisValue += totalDist / numberofpoints;
                        break;

                    case Units.Kilometers:
                        xAxisValue += totalDist / numberofpoints * distanceUnitFactors[0];
                        break;

                    case Units.Miles:
                        xAxisValue += totalDist / numberofpoints * distanceUnitFactors[1];
                        break;

                    case Units.Feet:
                        xAxisValue += totalDist / numberofpoints * distanceUnitFactors[2];
                        break;
                    }


                    //Get map coordinates
                    if (a.X < b.X)
                    {
                        curX = a.X + j * constXdif;
                    }
                    else
                    {
                        curX = a.X - j * constXdif;
                    }

                    if (a.Y < b.Y)
                    {
                        curY = a.Y + j * constYdif;
                    }
                    else
                    {
                        curY = a.Y - j * constYdif;
                    }

                    temp = new Coordinate(curX, curY);
                    RcIndex rowColumn = new RcIndex();

                    //get the elevation data for each raster layer at point temp
                    for (int k = 0; k < numberOfRasterLayers; k++)
                    {
                        //Calculate raster cell coordinates
                        rowColumn = rasterLayers[k].DataSet.Bounds.ProjToCell(temp);

                        //rasterLayers[k].DataSet.Projection.

                        if (rowColumn != RcIndex.Empty &&
                            rasterLayers[k].DataSet.Value[rowColumn.Row, rowColumn.Column] != rasterLayers[k].NoDataValue)                                      //Extract elevation from raster cell
                        {
                            curElevation = rasterLayers[k].DataSet.Value[rowColumn.Row, rowColumn.Column];
                            switch (yUnits)
                            {
                            case Units.Kilometers:
                                curElevation *= distanceUnitFactors[0];
                                break;

                            case Units.Miles:
                                curElevation *= distanceUnitFactors[1];
                                break;

                            case Units.Feet:
                                curElevation *= distanceUnitFactors[2];
                                break;
                            }
                            pointPair = new PointPair(xAxisValue, curElevation);
                            elevationList[k].Add(pointPair);
                        }
                        else                          //if the raster layer doesn't have data for this coordinate, set y value to NaN
                        {
                            pointPair = new PointPair(xAxisValue, double.NaN);
                            elevationList[k].Add(pointPair);
                        }
                    }
                }
            }
        }