using System; using System.Collections.Generic; using System.Linq; using System.Text; using GeoScene.Data; using GeoScene.Engine; using GeoScene.Globe; using System.Windows.Forms; namespace Cyberpipe { public class HDMCoordinate { private double dis; private double z; public double Dis { get { return dis; } set { dis = value; } } public double Z { get { return z; } set { z = value; } } } public class SectionAnalysisTool { public static Dictionary<GSOFeature, HDMCoordinate> hdmDic = new Dictionary<GSOFeature, HDMCoordinate>(); public static void ClearHDMAnalysis(GSOGlobeControl globeControl) { hdmDic.Clear(); globeControl.Globe.ClearLastTrackPolyline(); globeControl.Globe.Action = EnumAction3D.ActionNull; } /** * 计算点与三维线之间的距离 * **/ private static HDMCoordinate getSpaceDisBetweenLineAndPoint(GSOPoint3d point, GSOGeoPolyline3D polyLine) { double a_x = polyLine[0][0].X; double a_y = polyLine[0][0].Y; int id = GeoScene.Data.GSOProjectManager.AddProject(Utility.projectStr); GeoScene.Data.GSOPoint2d a_Point = GeoScene.Data.GSOProjectManager.Forward(new GSOPoint2d(a_x, a_y), id);//user画的线的起始点 GeoScene.Data.GSOPoint2d pt2d = new GeoScene.Data.GSOPoint2d(point.X, point.Y); GeoScene.Data.GSOPoint2d result = GeoScene.Data.GSOProjectManager.Forward(pt2d, id); double B_x = result.X; double B_y = result.Y; double x = System.Math.Abs(B_x - a_Point.X); double y = System.Math.Abs(B_y - a_Point.Y); double Dis = Math.Round(Math.Sqrt(x * x + y * y), 2); HDMCoordinate coor = new HDMCoordinate(); coor.Dis = Dis; coor.Z = point.Z; return coor; } //横断面分析 public static Dictionary<GSOFeature, HDMCoordinate> HDMAnalysis(GSOGlobeControl globeControl, GSOGeoPolyline3D polyLine, List<string> pipeLayerNames) { ClearHDMAnalysis(globeControl); if (globeControl == null || polyLine == null|| pipeLayerNames == null || pipeLayerNames.Count == 0) { return null; } globeControl.Globe.ClearLastTrackPolyline(); globeControl.Globe.Action = EnumAction3D.ActionNull; GSOGeoPolygon3D polygon = polyLine.CreateBuffer(0.1, true, 5, true, false); for (int i = 0; i < pipeLayerNames.Count; i++) { GSOLayer layer = globeControl.Globe.Layers. GetLayerByCaption(pipeLayerNames[i]); if(layer==null || layer.Visible==false|| layer as GSOFeatureLayer==null) continue; GSOFeatureLayer featurelayer = layer as GSOFeatureLayer; GSOFeatures feats = featurelayer.FindFeaturesInPolygon(polygon, false); if(feats==null||feats.Length==0) continue; for (int j = 0; j < feats.Length; j++) { GSOFeature feateline = feats[j]; GSOGeoPolyline3D geoline = feateline.Geometry as GSOGeoPolyline3D; if(geoline!=null &&geoline.Style!=null&& geoline.Style.GetType() == typeof(GSOPipeLineStyle3D)) { GSOPoint3d pntIntersect1 = new GSOPoint3d(); GSOPoint3d pntIntersect2 = new GSOPoint3d(); double honLen; double verLen; double dDist = globeControl.Globe.Analysis3D.ComputeTwoGeoPolylineDistance(polyLine, geoline, out pntIntersect1, out pntIntersect2, out honLen, out verLen, false, false, 0); if (dDist > -1) { HDMCoordinate coord = getSpaceDisBetweenLineAndPoint(pntIntersect2, polyLine); hdmDic.Add(feateline, coord); } } } } return hdmDic; } //纵断面分析 public static List<GSOFeature> ZDMAnalysis(GSOFeatures selectFeatures) { List<GSOFeature> result = new List<GSOFeature>(); if (selectFeatures != null && selectFeatures.Length == 1) { result.Add(selectFeatures[0]); return result; } for (int i = 0; i < selectFeatures.Length; i++) { GSOGeoPolyline3D line = selectFeatures[i].Geometry as GSOGeoPolyline3D; bool isConnect = false; int[] valueCount = new int[2]; valueCount[0] = 0; valueCount[1] = 0; if (line != null && line.PartCount > 0) { for (int j = 0; j < selectFeatures.Length; j++) { if (i == j) { continue; } GSOGeoPolyline3D newLine = selectFeatures[j].Geometry as GSOGeoPolyline3D; if (newLine != null && newLine.PartCount > 0) { int minValueIndex = 0; double limitValue = 1.0; double[] value = new double[4]; value[0] = getDistance(line[line.PartCount - 1][line[line.PartCount - 1].Count - 1], newLine[0][0]); value[1] = getDistance(line[line.PartCount - 1][line[line.PartCount - 1].Count - 1], newLine[newLine.PartCount - 1][newLine[newLine.PartCount - 1].Count - 1]); value[2] = getDistance(line[0][0], newLine[0][0]); value[3] = getDistance(line[0][0], newLine[newLine.PartCount - 1][newLine[newLine.PartCount - 1].Count - 1]); double minValue = value[0]; for (int m = 1; m < value.Length; m++) { if (minValue > value[m]) { minValue = value[m]; minValueIndex = m; } } if (minValue < limitValue) { isConnect = true; if (minValueIndex > 1) { valueCount[1]++; } else { valueCount[0]++; } } } } if (!isConnect || valueCount[0] > 1 || valueCount[1] > 1) { MessageBox.Show("请选择相连接的一条线上的管线!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return null; } } } //2 记录每一条相连接的管线的起点和终点,并添加到一条管线中 for (int p = 0; p < selectFeatures.Length; p++) { GSOGeoPolyline3D line = selectFeatures[p].Geometry as GSOGeoPolyline3D; if (line != null && line.PartCount > 0) { for (int n = 0; n < selectFeatures.Length; n++) { if (p == n) { continue; } GSOGeoPolyline3D newLine = selectFeatures[n].Geometry as GSOGeoPolyline3D; if (newLine != null && newLine.PartCount > 0) { int minValueIndex = 0; double limitValue = 1.0; double[] value = new double[4]; value[0] = getDistance(line[line.PartCount - 1][line[line.PartCount - 1].Count - 1], newLine[0][0]); value[1] = getDistance(line[line.PartCount - 1][line[line.PartCount - 1].Count - 1], newLine[newLine.PartCount - 1][newLine[newLine.PartCount - 1].Count - 1]); value[2] = getDistance(line[0][0], newLine[0][0]); value[3] = getDistance(line[0][0], newLine[newLine.PartCount - 1][newLine[newLine.PartCount - 1].Count - 1]); double minValue = value[0]; for (int m = 1; m < value.Length; m++) { if (minValue > value[m]) { minValue = value[m]; minValueIndex = m; } } if (minValue < limitValue) { GSOFeature featureFromAllSelectedObj = new GSOFeature(); GSOGeoPolyline3D lineFromAllSelectedObj = new GSOGeoPolyline3D(); switch (minValueIndex) { case 0: GSOPoint3ds linePart = new GSOPoint3ds(); for (int i = 0; i < line.PartCount; i++) { for (int j = 0; j < line[i].Count; j++) { linePart.Add(line[i][j]); } } for (int i = 0; i < newLine.PartCount; i++) { for (int j = 0; j < newLine[i].Count; j++) { linePart.Add(newLine[i][j]); } } lineFromAllSelectedObj.AddPart(linePart); break; case 1: linePart = new GSOPoint3ds(); for (int i = 0; i < line.PartCount; i++) { for (int j = 0; j < line[i].Count; j++) { linePart.Add(line[i][j]); } } for (int i = newLine.PartCount - 1; i >= 0; i--) { for (int j = newLine[i].Count - 1; j >= 0; j--) { linePart.Add(newLine[i][j]); } } lineFromAllSelectedObj.AddPart(linePart); break; case 2: linePart = new GSOPoint3ds(); for (int i = line.PartCount - 1; i >= 0; i--) { for (int j = line[i].Count - 1; j >= 0; j--) { linePart.Add(line[i][j]); } } for (int i = 0; i < newLine.PartCount; i++) { for (int j = 0; j < newLine[i].Count; j++) { linePart.Add(newLine[i][j]); } } lineFromAllSelectedObj.AddPart(linePart); break; case 3: linePart = new GSOPoint3ds(); for (int i = line.PartCount - 1; i >= 0; i--) { for (int j = line[i].Count - 1; j >= 0; j--) { linePart.Add(line[i][j]); } } for (int i = newLine.PartCount - 1; i >= 0; i--) { for (int j = newLine[i].Count - 1; j >= 0; j--) { linePart.Add(newLine[i][j]); } } lineFromAllSelectedObj.AddPart(linePart); break; } featureFromAllSelectedObj.Geometry = lineFromAllSelectedObj; selectFeatures.Remove(n); selectFeatures.Remove(p); selectFeatures.Add(featureFromAllSelectedObj); p--; break; } } } } } for (int h = 0; h < selectFeatures.Length; h++) { result.Add(selectFeatures[h]); } return result; } private static double getDistance(GSOPoint3d point1, GSOPoint3d point2) { GSOGeoPolyline3D lineline = new GSOGeoPolyline3D(); GSOPoint3ds point3ds = new GSOPoint3ds(); point3ds.Add(point1); point3ds.Add(point2); lineline.AddPart(point3ds); double distance = lineline.GetSpaceLength(true, 6378137.0); return distance; } } }