本文共 2278 字,大约阅读时间需要 7 分钟。
private void PRV_CheckSliver(IFeatureClass IN_Featureclass) { ListTemp_AllError = new List ();//记录所有错误OID //提取所有要素 IFeatureCursor Temp_GetEachFeature = IN_Featureclass.Search(null, true); IFeature Temp_EachFeature = Temp_GetEachFeature.NextFeature(); if (Temp_EachFeature != null) { //尽量不在循环中创建变量 IPointCollection Temp_Vertices; IPoint First_Point = new Point(); IPoint Center_Point = new Point(); IPoint Last_Point = new Point(); int i; //将错误的OID提到List里 while (Temp_EachFeature != null) { //获取要素的点集 Temp_Vertices = Temp_EachFeature.Shape as IPointCollection; Temp_Vertices.AddPoint(Temp_Vertices.get_Point(1)); for (i = 0; i < Temp_Vertices.PointCount - 3; i++) { Temp_Vertices.QueryPoint(i, First_Point); Temp_Vertices.QueryPoint(i + 1, Center_Point); Temp_Vertices.QueryPoint(i + 2, Last_Point); double angle = PRV_GetAngle(Center_Point, First_Point, Last_Point); if (angle < 30|| angle > 360 - 30)//这里设狭长角为30度 Temp_AllError.Add(Temp_EachFeature.OID.ToString()); } Temp_EachFeature = Temp_GetEachFeature.NextFeature(); } } System.Runtime.InteropServices.Marshal.FinalReleaseComObject(Temp_GetEachFeature);//释放 }
计算角度的函数
//三个点计算角度 private double PRV_GetAngle(IPoint cen, IPoint first, IPoint second) { double ma_x = first.X - cen.X; double ma_y = first.Y - cen.Y; double mb_x = second.X - cen.X; double mb_y = second.Y - cen.Y; double v1 = (ma_x * mb_x) + (ma_y * mb_y); double ma_val = Math.Sqrt(ma_x * ma_x + ma_y * ma_y); double mb_val = Math.Sqrt(mb_x * mb_x + mb_y * mb_y); double cosM = v1 / (ma_val * mb_val); double angleAMB = Math.Acos(cosM) * 180 / System.Math.PI; return angleAMB; }
转载地址:http://hrqws.baihongyu.com/