DEM获取地形和计算点是否在矩形面积内的算法

1准备一个DEM地形,打开GlobalMap,如下选择

 

1 选择否,生成边界,将边界导出为shp文件,打开QGIS,坐标系转为4326坐标并保存

2多边形转线,将4326坐标系的shp文件转为线shp

 3安装get wkt插件,选择对应坐标系,获取wkt,如图

 保存为json数据

 经验证,数据无误

 附判断点是否在此坐标范围内代码

 /// <summary>
        /// 判断点是否在多边形内或多边形上
        /// </summary>
        /// <param name="ALon">经度</param>
        /// <param name="ALat">纬度</param>
        /// <param name="Points">多边形边界点集合</param>
        /// <returns></returns>
        public static bool IsPtInPoly(double ALon, double ALat, string rainfallRange)
        {
            //rainfallRange转为区域点对象


            string[] rainfallArray = rainfallRange.Split(';');

            List<Point> Points = new List<Point>(); // 换成自己的

            foreach (string strs in rainfallArray)
            {
                string[] strPoint = strs.Split(',');

                Point point = new Point(Convert.ToDouble(strPoint[0]), Convert.ToDouble(strPoint[1])); // 换成自己的

                Points.Add(point);
            }

            int iSum, iCount, iIndex;
            double dLon1 = 0, dLon2 = 0, dLat1 = 0, dLat2 = 0, dLon;
            if (Points.Count < 3)
            {
                return false;
            }
            iSum = 0;
            iCount = Points.Count;
            for (iIndex = 0; iIndex < iCount; iIndex++)
            {
                if (ALon == Points[iIndex].getX() && ALat == Points[iIndex].getY())  //A点在多边形上    
                    return true;

                if (iIndex == iCount - 1)
                {
                    dLon1 = Points[iIndex].getX();
                    dLat1 = Points[iIndex].getY();
                    dLon2 = Points[0].getX();
                    dLat2 = Points[0].getY();
                }
                else
                {
                    dLon1 = Points[iIndex].getX();
                    dLat1 = Points[iIndex].getY();
                    dLon2 = Points[iIndex + 1].getX();
                    dLat2 = Points[iIndex + 1].getY();
                }

                //以下语句判断A点是否在边的两端点的纬度之间,在则可能有交点
                if (((ALat > dLat1) && (ALat < dLat2)) || ((ALat > dLat2) && (ALat < dLat1)))
                {
                    if (Math.Abs(dLat1 - dLat2) > 0)
                    {
                        //获取A点向左射线与边的交点的x坐标:
                        dLon = dLon1 - ((dLon1 - dLon2) * (dLat1 - ALat)) / (dLat1 - dLat2);
                        //如果交点在A点左侧,则射线与边的全部交点数加一:
                        if (dLon < ALon)
                        {
                            iSum++;
                        }
                        //如果相等,则说明A点在边上
                        if (dLon == ALon)
                            return true;
                    }
                }
            }
            if ((iSum % 2) != 0)
            {
                return true;
            }
            return false;
        }

 public class Point
    {
        private Double x;
        private Double y;
        public Point(Double x, Double y)
        {
            this.x = x;
            this.y = y;
        }
        public Double getX()
        {
            return x;
        }
        public void setX(Double x)
        {
            this.x = x;
        }
        public Double getY()
        {
            return y;
        }
        public void setY(Double y)
        {
            this.y = y;
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于C#DEM的基本地形因子计算,可以使用以下代码: ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DEMCalculation { class Program { static void Main(string[] args) { // DEM数据的高度值数组 double[,] dem = new double[10, 10] { { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }, { 10, 20, 20, 20, 20, 20, 20, 20, 20, 10 }, { 10, 20, 30, 30, 30, 30, 30, 30, 20, 10 }, { 10, 20, 30, 40, 40, 40, 30, 30, 20, 10 }, { 10, 20, 30, 40, 50, 40, 30, 30, 20, 10 }, { 10, 20, 30, 40, 40, 40, 30, 30, 20, 10 }, { 10, 20, 30, 30, 30, 30, 30, 30, 20, 10 }, { 10, 20, 20, 20, 20, 20, 20, 20, 20, 10 }, { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }, { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 } }; // 计算面积 double profileArea = 0; for (int i = 0; i < dem.GetLength(0) - 1; i++) { for (int j = 0; j < dem.GetLength(1) - 1; j++) { double z1 = dem[i, j]; double z2 = dem[i, j + 1]; double z3 = dem[i + 1, j + 1]; double z4 = dem[i + 1, j]; // 计算三角形面积 double a = Math.Sqrt(Math.Pow(i - (i + 1), 2) + Math.Pow(j + 1 - j, 2)); double b = Math.Sqrt(Math.Pow(i - i, 2) + Math.Pow(j + 1 - j, 2)); double c = Math.Sqrt(Math.Pow(i - (i + 1), 2) + Math.Pow(j + 1 - j, 2)); double p = (a + b + c) / 2; double triangleArea1 = Math.Sqrt(p * (p - a) * (p - b) * (p - c)); a = Math.Sqrt(Math.Pow(i - (i + 1), 2) + Math.Pow(j + 1 - j, 2)); b = Math.Sqrt(Math.Pow(i + 1 - (i + 1), 2) + Math.Pow(j + 1 - j, 2)); c = Math.Sqrt(Math.Pow(i - (i + 1), 2) + Math.Pow(j + 1 - j, 2)); p = (a + b + c) / 2; double triangleArea2 = Math.Sqrt(p * (p - a) * (p - b) * (p - c)); profileArea += triangleArea1 + triangleArea2; } } Console.WriteLine("剖面积为:" + profileArea); Console.ReadKey(); } } } ``` 其中,`dem`数组为DEM数据的高度值数组,可以根据实际情况进行修改。该程序通过循环遍历DEM数据的每个网格,并计算每个网格的两个三角形的面积,最终将所有三角形的面积加起来得到剖面积

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值