Ejemplo n.º 1
0
        /// <summary>
        /// 计算平均坡度和坡长
        /// </summary>
        /// <param name="point"></param>
        /// <param name="reader"></param>
        /// <param name="avglength"></param>
        /// <param name="avgslope"></param>
        public void CalAvgSlopeLength(List <Point3d> points, RasterReader reader, ref double avglength, ref double avgslope)
        {
            double totalLength = 0;
            double totalSlope  = 0;

            if (points != null && points.Count > 0)
            {
                int count = 0;
                for (int i = 0; i < points.Count; i++)
                {
                    Point3d        startpt      = points[i];
                    List <Point3d> resultPt     = GetMaxSlopePoints(points[i], reader);
                    double         singleLength = 0;
                    double         singleSlope  = 0;
                    for (int j = 0; j < resultPt.Count; j++)
                    {
                        Point3d point1 = resultPt[i];
                        Point3d point2 = resultPt[resultPt.Count - 1];
                        singleLength += RasterCoefficientReader.Length(point1, point2);
                    }
                    singleSlope  = Math.Abs((startpt.Z - resultPt[resultPt.Count - 1].Z) / (RasterCoefficientReader.Length(startpt, resultPt[resultPt.Count - 1])));
                    totalSlope  += singleSlope;
                    totalLength += singleLength;
                    count        = points.Count * resultPt.Count;
                    FormOutput.AppendProress(((i + 1) * 100) / points.Count);
                }
                avglength = totalLength / (1000 * count);
                avgslope  = totalSlope * 1000 / points.Count;
            }
        }
Ejemplo n.º 2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            string[] args = e.Argument as string[];

            double avgLength = 0;
            double avgSlope  = 0;

            if (File.Exists(args[0]) && File.Exists(args[1]))
            {
                FormOutput.AppendLog("开始获取线的交点...");
                RasterReader   reader = new RasterReader(args[1]);
                List <Point3d> pts    = CalPoints(args[0], reader);
                FormOutput.AppendLog("开始计算平均坡度和坡长...");
                CalAvgSlopeLength(pts, reader, ref avgLength, ref avgSlope);
                reader.Dispose();
                FormOutput.AppendLog("平均坡长:" + avgLength.ToString("f3"));
                FormOutput.AppendLog("平均坡度:" + avgSlope.ToString("f3"));
            }
            double?r = null;

            if (File.Exists(args[1]) && File.Exists(args[2]))
            {
                FormOutput.AppendLog("开始计算坡面流速系数...");
                r = RasterCoefficientReader.ReadCoeficient(args[2], args[1]);
                if (r.HasValue)
                {
                    FormOutput.AppendLog("结果--坡面流速系数为:" + r.Value.ToString());
                }
            }
            e.Result = new double[] { avgLength, avgSlope, r.GetValueOrDefault(0) };
        }
        /// <summary>
        /// 暴雨损失参数计算
        /// </summary>
        /// <param name="shppath"></param>
        /// <param name="inputDemPath"></param>
        /// <param name="outDemPath"></param>
        public void RainLoss(string Rshppath, string rshppath, string inputDemPath, string areaShp, ref DoWorkEventArgs e)
        {
            //计算流域面积
            double F  = 0;
            double?sf = null;
            double?N  = null;

            if (File.Exists(areaShp))
            {
                FormOutput.AppendLog("开始计算流域面积和折减系数");
                WatershedArea(areaShp, inputDemPath, ref F, ref sf);
                sf = sf / 1000000;
                FormOutput.AppendLog(string.Format("流域表面积SF = {0}km²", sf.Value.ToString("f3")));
                F = F / 1000000;
                FormOutput.AppendLog(string.Format("流域投影面积F = {0}km²", F.ToString("f3")));
                N = 1 / (1 + 0.016 * F * 0.6);//折减系数
                FormOutput.AppendLog("折减系数N = " + N.Value.ToString("f3"));
            }

            //计算折减系数
            double?R = null;

            if (File.Exists(Rshppath))
            {
                FormOutput.AppendLog("开始计算损失系数");
                R = RasterCoefficientReader.ReadCoeficient(Rshppath, inputDemPath);
                if (R.HasValue)
                {
                    FormOutput.AppendLog("损失系数R = " + R.Value.ToString("f3"));
                }
            }
            double?r = null;

            if (File.Exists(rshppath))
            {
                FormOutput.AppendLog("开始计算损失指数");
                r = RasterCoefficientReader.ReadCoeficient(rshppath, inputDemPath);
                if (r.HasValue)
                {
                    FormOutput.AppendLog("损失指数r = " + r.Value.ToString("f3"));
                }
            }
            e.Result = new double?[] { F, N, R, r };
        }
Ejemplo n.º 4
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            string[] args        = e.Argument as string[];
            double   riverlength = 0;
            double   j           = 0;

            if (File.Exists(args[0]) && File.Exists(args[1]))
            {
                FormOutput.AppendLog("开始递归所有沟道分支...");
                List <Dictionary <Point2d, Geometry> > results = GetAllRivers(args[0]);

                FormOutput.AppendLog(string.Format("共得到{0}条支流...", results.Count));

                FormOutput.AppendLog("开始获取主沟道,并计算其长度...");

                riverlength = CaculateRiver(results, args[1], ref _mainRiver);

                riverlength = riverlength / 1000;

                FormOutput.AppendLog("主河道长度:" + riverlength.ToString("f3"));

                FormOutput.AppendLog("开始计算主沟道纵降比...");
                j = GetLonGradient(_mainRiver, args[1]);
                FormOutput.AppendLog("主河道纵降比:" + j.ToString("f3"));
            }

            double?r = null;

            if (File.Exists(args[2]) && File.Exists(args[1]))
            {
                FormOutput.AppendLog("开始计算沟道流域系数...");
                r = RasterCoefficientReader.ReadCoeficient(args[2], args[1]);
                if (r.HasValue)
                {
                    FormOutput.AppendLog("沟道流速系数:" + r.Value.ToString("f3"));
                }
            }

            e.Result = new double[] { riverlength, j, r.GetValueOrDefault(0) };
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 计算当前点的最陡方向
        /// 返回最陡方向的点集
        /// D8算法
        /// </summary>
        /// <param name="point"></param>
        /// <param name="reader"></param>
        /// <param name="outresult"></param>
        private List <Point3d> GetMaxSlopePoints(Point3d point, RasterReader reader)
        {
            double cellSizeX = reader.CellSizeX;
            double cellSizeY = reader.CellSizeY;

            int row = reader.RowCount / 50;
            int col = reader.ColumnCount / 50;

            double[] adfGeoTransform = new double[6];
            reader.DataSet.GetGeoTransform(adfGeoTransform);

            int            _maxR     = 0;
            int            _maxC     = 0;
            List <Point3d> outresult = new List <Point3d>();
            //遍历周围八个点,取最大值
            List <double> dstDic = new List <double>();

            for (int r = 0; r < row; r++)
            {
                for (int c = 0; c < col; c++)
                {
                    double center = RasterCoefficientReader.ReadBand(reader, c, r);
                    //东方,列+1,行不变,p(i,j)-p(i,j+1)
                    if (c + 1 < col)
                    {
                        double e = center - RasterCoefficientReader.ReadBand(reader, c + 1, r);
                        dstDic.Add(e);
                    }
                    else
                    {
                        dstDic.Add(-1);
                    }

                    //东南,列+1,行+1,p(i,j)-p(i+1,j+1)
                    if (c + 1 < col && r + 1 < row)
                    {
                        double es = (center - RasterCoefficientReader.ReadBand(reader, c + 1, r + 1)) / Math.Sqrt(2);
                        dstDic.Add(es);
                    }
                    else
                    {
                        dstDic.Add(-1);
                    }

                    //南,列+0,行+1
                    if (r + 1 < row)
                    {
                        double s = center - RasterCoefficientReader.ReadBand(reader, c, r + 1);
                        dstDic.Add(s);
                    }
                    else
                    {
                        dstDic.Add(-1);
                    }

                    //西南
                    if (0 < c - 1 && 0 < r - 1)
                    {
                        double ws = (center - RasterCoefficientReader.ReadBand(reader, c - 1, r - 1)) / Math.Sqrt(2);
                        dstDic.Add(ws);
                    }
                    else
                    {
                        dstDic.Add(-1);
                    }

                    //西
                    if (0 < c - 1)
                    {
                        double w = center - RasterCoefficientReader.ReadBand(reader, c - 1, r);
                        dstDic.Add(w);
                    }
                    else
                    {
                        dstDic.Add(-1);
                    }

                    //西北
                    if (0 < c - 1 && 0 < r - 1)
                    {
                        double wn = (center - RasterCoefficientReader.ReadBand(reader, c - 1, r - 1)) / Math.Sqrt(2);
                        dstDic.Add(wn);
                    }
                    else
                    {
                        dstDic.Add(-1);
                    }

                    //北
                    if (0 < r - 1)
                    {
                        double n = center - RasterCoefficientReader.ReadBand(reader, c, r - 1);
                        dstDic.Add(n);
                    }
                    else
                    {
                        dstDic.Add(-1);
                    }

                    //东北
                    if (0 < r - 1 && c + 1 < col)
                    {
                        double en = (center - RasterCoefficientReader.ReadBand(reader, c + 1, r - 1)) / Math.Sqrt(2);
                        dstDic.Add(en);
                    }
                    else
                    {
                        dstDic.Add(-1);
                    }

                    int result = 0;
                    //判断该点水流方向
                    var maxTime = dstDic.Select(x => x).Max();
                    int dir     = dstDic.FindIndex(x => x == maxTime) + 1;
                    if (dir == 3)
                    {
                        result = 4;//南
                        _maxR  = r + 1;
                        _maxC  = c;
                    }
                    else if (dir == 2)
                    {
                        result = 2;//东南
                        _maxR  = r + 1;
                        _maxC  = c + 1;
                    }
                    else if (dir == 7)
                    {
                        result = 64;//北
                        _maxR  = r - 1;
                        _maxC  = c;
                    }

                    else if (dir == 1)
                    {
                        result = 1;//东
                        _maxR  = r;
                        _maxC  = c + 1;
                    }

                    else if (dir == 8)
                    {
                        result = 128;//东北
                        _maxR  = r - 1;
                        _maxC  = c + 1;
                    }

                    else if (dir == 6)
                    {
                        result = 32;//西北
                        _maxR  = r - 1;
                        _maxC  = c - 1;
                    }

                    else if (dir == 5)
                    {
                        result = 16;//西
                        _maxR  = r;
                        _maxC  = c - 1;
                    }
                    else if (dir == 4)
                    {
                        result = 8;//西南
                        _maxR  = r + 1;
                        _maxC  = c - 1;
                    }
                    else
                    {
                        result = 0;
                        _maxR  = r;
                        _maxC  = c;
                    }
                    double  px       = point.X + r * adfGeoTransform[1] + c * adfGeoTransform[2];
                    double  py       = point.Y + r * adfGeoTransform[4] + c * adfGeoTransform[5];
                    double  pz       = RasterCoefficientReader.ReadBand(reader, _maxR, _maxC);//_globeView.GetElevation(px, py);
                    Point3d maxPoint = new Point3d(px, py, pz);
                    outresult.Add(maxPoint);
                    Application.DoEvents();
                } /* end for c */
                Application.DoEvents();
            }     /* enf for r */
            return(outresult);
        }