/// <summary> /// 设置管段起始终止点为分析点 /// </summary> /// <param name="Geoline3Ds"></param> void SetPoint(List <GeoLine3D> Geoline3Ds) { for (int i = 0; i < Geoline3Ds.Count; i++) { mGeoLine3D = Geoline3Ds[i]; mPoint3Ds = mGeoLine3D[0]; mPoint3Ds = coordinateTrans3D(mPoint3Ds); if (i == 0) { mPoint3D_0 = mPoint3Ds.ToArray(); } else { mPoint3D_1 = mPoint3Ds.ToArray(); } } mResult = ClearDistanceAlgorithm(mPoint3D_0[0], mPoint3D_0[1], mPoint3D_1[0], mPoint3D_1[1]); switch (mFlag) { case 1: GetHResult(); break; case 2: GetVResult(); break; case 4: GetColResult(); break; } }
//如果kml中已经保存运动轨迹,可以选择已保存好的运动轨迹 private void cb_Track_SelectedIndexChanged(object sender, EventArgs e) { if (cb_Track.SelectedIndex == 0) { return; } this.m_sceneControl.Scene.TrackingLayer.Clear(); String trackName = this.cb_Track.SelectedItem as String; Feature3Ds features = m_layerKML.Features; Feature3D[] feature3Ds = features.FindFeature(trackName, Feature3DSearchOption.AllFeatures); if (feature3Ds.Length > 0) { Feature3D feature3D = feature3Ds[0]; GeoPlacemark geoPlacemark = feature3D.Geometry as GeoPlacemark; m_geoLine3D = geoPlacemark.Geometry as GeoLine3D; if (m_geoLine3D != null && m_geoLine3D.PartCount > 0) { if (m_nodeAnimation != null) { m_nodeAnimation.SetTrack(m_geoLine3D); m_nodeAnimation.TimePostition = 0; } this.btn_AddToKML.Enabled = false; } } }
void m_sceneControl_Tracking(object sender, Tracking3DEventArgs e) { if (m_sceneControl.Action == Action3D.CreateLine) { if (m_bHasDone) { m_viewshed3D = CreateViewShed3D(); m_bHasDone = false; } if (m_viewshed3D != null) { GeoLine3D geoline3d = e.Geometry as GeoLine3D; if (geoline3d.PartCount > 0) { Point3Ds pts = geoline3d[0]; m_viewshed3D.ViewerPosition = pts[0]; updateObserverPosition(m_viewshed3D); m_viewshed3D.SetDistDirByPoint(pts[1]); updateParam(m_viewshed3D, false); } } } }
void m_sceneControl_Tracked(object sender, Tracked3DEventArgs e) { this.cb_TargetPtsIndex.Items.Clear(); if (m_sceneControl.Action == Action3D.CreatePolyline) { GeoLine3D geoline3d = e.Geometry as GeoLine3D; if (geoline3d != null && geoline3d.PartCount > 0) { Point3Ds pts = geoline3d[0]; m_sightLine.ViewerPosition = pts[0]; updateObservePosition(pts[0]); m_sightLine.RemoveAllTargetPoints(); for (int i = 1; i < pts.Count; ++i) { m_sightLine.AddTargetPoint(pts[i]); this.cb_TargetPtsIndex.Items.Add(i - 1); } } } if (this.cb_TargetPtsIndex.Items.Count > 0) { this.cb_TargetPtsIndex.SelectedIndex = 0; } }
public void ClearPath() { try { if (mLine3D != null) { mLine3D = null; } mEndPoint.X = 0; mEndPoint.Y = 0; mEndPoint.Z = 0; mStartPoint.X = 0; mStartPoint.Y = 0; mStartPoint.Z = 0; if (RodeTotalLength != 0) { RodeTotalLength = 0; } if (mTextBoxRodeName != null) { mTextBoxRodeName = null; } mSceneControl.MouseDoubleClick -= PathAnalysisMouseClick; mSceneControl.Scene.TrackingLayer.Clear(); } catch (Exception ex) { Trace.WriteLine(ex); } }
private void TrackedSectionEvent(object sender, Tracked3DEventArgs e) { try { //绘制量算线对象 GeoLine3D geoLine3D = e.Geometry.Clone() as GeoLine3D; mRec2D = geoLine3D.Bounds; //设置数据集容量,避免空间查询出现过多对象 mUseData.OutWaterNetWork.Tolerance.NodeSnap = 0.0001; mUseData.SupplyWaterNetWork.Tolerance.NodeSnap = 0.0001; mUseData.ElectricNetWork.Tolerance.NodeSnap = 0.0001; GeoStyle3D mGeoStyle3D = new GeoStyle3D(); // mGeoStyle3D.MarkerColor = Color.FromArgb(255, 0, 255); mGeoStyle3D.LineColor = Color.FromArgb(0x00, 0x99, 0x00); mGeoStyle3D.LineWidth = 3; geoLine3D.Style3D = mGeoStyle3D.Clone(); geoLine3D.Style3D.AltitudeMode = AltitudeMode.Absolute; TrackingLayer3D trackinglayer = mSceneControl.Scene.TrackingLayer; trackinglayer.IsEditable = true; trackinglayer.IsVisible = true; trackinglayer.Add(geoLine3D, "GeoLine3D"); mSceneControl.Action = Action3D.Pan2; CrossSecLine(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
/// <summary> /// 进行网络分析分析 /// </summary> public void BeginNetworkAnalyst() { try { mAnalystResult = mAnalyst.FindTSPPath(mAnalystParameter, false); if (mAnalystResult != null) { int[][] EdgeId = new int[mAnalystResult.Edges.Length][]; //拿到交错数组中第一行元素ID int[] IDedge = new int[mAnalystResult.Edges[0].Length]; for (int i = 0; i < IDedge.Length; i++) { IDedge[i] = mAnalystResult.Edges[0][i]; } //拿到弧段ID后查询路名 string[] RodeName = new string[IDedge.Length]; Recordset recordset = null; for (int i = 0; i < IDedge.Length; i++) { recordset = mRodeNetWork.Query("SmID =" + IDedge[i], CursorType.Static); RodeName[i] = recordset.GetFieldValue("RodeName").ToString().Trim(); mRodeTotalLength += Convert.ToInt32(recordset.GetFieldValue("SmLength")); } //编辑路名显示形式 string mStartRode = "起点→"; string mNewRode = null; for (int i = 0; i < RodeName.Length; i++) { if (i == 0) { mNewRode = mStartRode.Insert(mStartRode.Length, RodeName[i] + "→"); } else { mNewRode = mNewRode.Insert(mNewRode.Length, RodeName[i] + "→"); } } mTextBoxRodeName = mNewRode + "终点"; } GeoLine line = mAnalystResult.Routes[0].ConvertToLine(); if (mLine3D == null) { mLine3D = new GeoLine3D(); } for (Int32 i = 0; i < line.PartCount; i++) { mLine3D.AddPart(line[i].ToPoint3Ds()); } mLine3D[0].Insert(0, new Point3D(mStartPoint.X, mStartPoint.Y, 0)); mLine3D[0].Add(new Point3D(mEndPoint.X, mEndPoint.Y, 0)); DisplayFlyRoute(); } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
public int PickNodeToLine(int nID) { m_SelectedGeoNetwork.Clear(); DatasetVector DvLine = m_workspace.Datasources["Pipeline3D"].Datasets["PipeLine3D"] as DatasetVector; DatasetVector DvNode = m_workspace.Datasources["Pipeline3D"].Datasets["PipePoint3D"] as DatasetVector; int[] id = { nID }; Recordset recordset = DvNode.Query(id, CursorType.Static); Geometry pGeoNode = recordset.GetGeometry(); string strNodeID = "PtID"; int nNodeID = Convert.ToInt32(recordset.GetFieldValue(strNodeID)); string strFNode = "FNode"; string strTNode = "ENode"; QueryParameter queryparameter = new QueryParameter(); queryparameter.CursorType = CursorType.Static; queryparameter.AttributeFilter = String.Format("{0}={1} or {2}={3}", strFNode, nNodeID, strTNode, nNodeID); Recordset Rs = DvLine.Query(queryparameter); int nCount = Rs.RecordCount;; Rs.MoveFirst(); while (!Rs.IsEOF) { GeoLine3D geoline3D = Rs.GetGeometry() as GeoLine3D; NetworkGeometry NetWorkGeometry = new NetworkGeometry(); NetWorkGeometry.nID = geoline3D.ID; NetWorkGeometry.nFNode = Convert.ToInt32(Rs.GetFieldValue(strFNode)); NetWorkGeometry.nTNode = Convert.ToInt32(Rs.GetFieldValue(strTNode)); if (!m_SelectedGeoNetwork.Contains(NetWorkGeometry)) { if (NetWorkGeometry.nTNode == nNodeID) { NetWorkGeometry.geometry = geoline3D; m_SelectedGeoNetwork.Add(NetWorkGeometry);//流入对象在第一位 } else { NetWorkGeometry.bIsIn = false; NetWorkGeometry.geometry = geoline3D; m_SelectedGeoNetwork.Add(NetWorkGeometry);//线对象 } } Rs.MoveNext(); } Rs.Dispose(); return(nCount); }
/// <summary> /// 沿线飞行 /// </summary> public void FlyLine(Geometry3D geometry) { try { GeoLine3D geoline = geometry as GeoLine3D; route = new Route(); route.FromGeoLine3D(geoline); route.IsFlyAlongTheRoute = true; routestopCount = route.Stops.Count; int i; for (i = 0; i < routestopCount; i++) { stop = route.Stops[i]; Camera camera = stop.Camera; camera.Tilt = 90; camera.Altitude = 50; stop.Camera = camera; } route.IsTiltFixed = true; route.IsHeadingFixed = true; route.IsAltitudeFixed = true; route.Speed = 110; route.IsLinesVisible = false; route.IsStopsVisible = false; //m_sceneControl.Scene.IsFirstPersonView = true; flyManager.Routes.Add(route); routestopName = route.Stops[routestopCount - 1].Name; flyManager.Scene = m_sceneControl.Scene; //设置当前路线 if (flyManager.Routes.Count == 1) { flyManager.Routes.CurrentRouteIndex = 0; } else { flyManager.Routes.CurrentRouteIndex = 1; } flyManager.Play(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//关闭对话框 private void DlgNodeAnimation_FormClosing(object sender, FormClosingEventArgs e) { this.cb_Model.Items.Clear(); this.m_sceneControl.Scene.TrackingLayer.Clear(); m_nodeAnimation.TimePositionChanged -= new TimePositionChangedEventHandler(m_nodeAnimationTimePositionChanged); m_sceneControl.Tracked -= new Tracked3DEventHandler(m_sceneControl_Tracked); m_nodeAnimation.IsEnabled = false; m_geoLine3D = null; m_style3D = null; m_nodeAnimation = null; m_geoModel = null; this.btn_AddToKML.Enabled = false; }
/// <summary> /// 显示覆土分析结果 /// </summary> private void ShowC() { String text = String.Empty; Point3D textLocation = new Point3D(0, 0, 0); GeoLine3D geoLine = new GeoLine3D(mTextPoint3Ds); SetGeometry3DStyle(geoLine); mSceneControl.Scene.TrackingLayer.Add(geoLine, "覆土深度"); text = String.Format("{0}{1}{2}", "覆土深度:", Math.Round(Convert.ToDouble(mCDistance), 2), "米"); textLocation = geoLine.InnerPoint3D; GeoText3D geoText = new GeoText3D(new TextPart3D(text, textLocation)); SetResultTextStyle(geoText); mSceneControl.Scene.TrackingLayer.Add(geoText, "覆土"); mSceneControl.ObjectSelected -= new ObjectSelectedEventHandler(mSceneControlSelected); }
//鼠标右键事件,结束分析操作 void m_sceneControl_Tracked(object sender, Tracked3DEventArgs e) { if (m_sceneControl.Action == Action3D.CreateLine) { GeoLine3D geoline3d = e.Geometry as GeoLine3D; if (geoline3d != null && geoline3d.PartCount > 0) { Point3Ds pts = geoline3d[0]; m_profile.StartPoint = pts[0]; m_profile.EndPoint = pts[1]; outPutPic(); } m_sceneControl.Action = m_oldAction; m_bHasDrawn = true; } }
//获取天际线 private void btn_GetSkyline_Click(object sender, EventArgs e) { try { if (m_skyline != null) { GeoLine3D line3D = m_skyline.GetSkyline(); if (m_workspace.Datasources.Count == 0) { MessageBox.Show("请先打开一个数据源"); return; } Datasource datasource = m_workspace.Datasources[0]; Datasets datasets = datasource.Datasets; String datasetName = "NewLine3D"; if (datasource.Datasets.Contains(datasetName)) { datasource.Datasets.Delete(datasetName); } DatasetVectorInfo datasetInfo = new DatasetVectorInfo(); datasetInfo.Type = DatasetType.Line3D; datasetInfo.Name = datasetName; datasetInfo.EncodeType = EncodeType.None; DatasetVector newDataset = datasource.Datasets.Create(datasetInfo); if (newDataset == null) { MessageBox.Show("创建三维面数据集失败!"); } if (m_sceneControl.Scene.Type == SceneType.Globe) { newDataset.PrjCoordSys = new PrjCoordSys(PrjCoordSysType.EarthLongitudeLatitude); } Recordset recordset = newDataset.GetRecordset(false, CursorType.Dynamic); recordset.AddNew(line3D); recordset.Update(); recordset.Dispose(); } } catch (System.Exception ex) { Console.Write(ex.Message); } }
//鼠标移动事件 void m_sceneControl_Tracking(object sender, Tracking3DEventArgs e) { m_sceneControl.Scene.TrackingLayer.Clear(); if (m_sceneControl.Action == Action3D.CreateLine) { GeoLine3D geoline3d = e.Geometry as GeoLine3D; if (geoline3d.PartCount > 0) { Rectangle2D rect = m_contour.CoverageArea; Point3Ds pts = geoline3d[0]; rect.Left = pts[0].X; rect.Top = pts[0].Y; rect.Right = pts[1].X; rect.Bottom = pts[1].Y; m_contour.CoverageArea = rect; } } }
public SampleRun(WorkspaceControl workspaceControl, LayersControl layersControl, MapControl mapControl, MapControl mapControl2, MapLayoutControl mapLayoutControl1, ToolStripStatusLabel toolStripStatusLabel2, TextBox textBoxResult, ToolStripStatusLabel toolStripStatusLabel3, SceneControl scenecontrol ) { workspaceControl1 = workspaceControl; workspace1 = workspaceControl1.WorkspaceTree.Workspace; layersControl1 = layersControl; mapControl1 = mapControl; m_mapControlEagleEye = mapControl2; m_mapLayoutControl = mapLayoutControl1; m_toolStrip = toolStripStatusLabel2; m_textBoxResult = textBoxResult; scontrol = scenecontrol; label1 = toolStripStatusLabel3; m_datasource = workspace1.Datasources[0]; m_point3Ds = new Point3Ds(); m_pointName = "Point"; m_geoLine3D = new GeoLine3D(); m_point3DsAll = new Point3Ds(); m_flyManager = scontrol.Scene.FlyManager; m_flyManager.Routes.Clear(); m_flyManager.Scene = scontrol.Scene; m_mapControlEagleEye.MouseMove += new MouseEventHandler(EagleEyeMapMouseMoveHandler); m_mapControlEagleEye.MouseDown += new MouseEventHandler(EagleEyeMapMouseDownHandler); m_mapControlEagleEye.MouseUp += new MouseEventHandler(EagleEyeMapMouseUpHandler); m_mapControlEagleEye.ActionCursorChanging += new ActionCursorChangingEventHandler(EagleEyeMapCursorChangedHandler); mapControl1.Map.Drawn += new MapDrawnEventHandler(MainMapDrawnHandler); scontrol.MouseDown += new System.Windows.Forms.MouseEventHandler(m_sceneControl_MouseDown); scontrol.MouseMove += new System.Windows.Forms.MouseEventHandler(m_sceneControl_MouseMove); Initialize(); }
public void SetPoint(int flag) { try { StartOrEnd = flag; if (mLine3D != null && mLine3D.PartCount > 0) { mLine3D.SetEmpty(); } else if (mLine3D == null) { mLine3D = new GeoLine3D(); } mSceneControl.Action = Action3D.Select; mSceneControl.MouseDoubleClick -= PathAnalysisMouseClick; mSceneControl.MouseDoubleClick += PathAnalysisMouseClick; } catch (Exception ex) { Trace.WriteLine(ex); } }
private Route GetRoute() { Route route = new Route(); Point3Ds point3Ds = m_geoLine3D[0]; for (int i = 0; i < point3Ds.Count; i++) { Point3D point3D = new Point3D(point3Ds[i].X, point3Ds[i].Y, point3Ds[i].Z + 1000); point3Ds[i] = point3D; } GeoLine3D geoLine3D = new GeoLine3D(point3Ds); route.FromGeoLine3D(geoLine3D); route.IsFlyAlongTheRoute = true; route.IsHeadingFixed = true; route.IsAltitudeFixed = true; route.IsTiltFixed = true; route.IsLinesVisible = false; route.IsStopsVisible = false; return(route); }
void m_sceneControl_Tracking(object sender, Tracking3DEventArgs e) { this.m_sceneControl.Scene.TrackingLayer.Clear(); if (m_sceneControl.Action == Action3D.CreatePolyline) { if (m_sightLine != null) { GeoLine3D geoline3d = e.Geometry as GeoLine3D; if (geoline3d != null && geoline3d.PartCount > 0) { Point3Ds pts = geoline3d[0]; m_sightLine.ViewerPosition = pts[0]; updateObservePosition(pts[0]); m_sightLine.RemoveAllTargetPoints(); for (int i = 1; i < pts.Count; ++i) { m_sightLine.AddTargetPoint(pts[i]); } } } } }
//鼠标右键事件,结束绘制操作 void m_sceneControl_Tracked(object sender, Tracked3DEventArgs e) { int a = 0; if (m_sceneControl.Action == Action3D.CreatePolyline) { GeoLine3D line3D = e.Geometry as GeoLine3D; m_geoLine3D = line3D; m_style3D.LineColor = Color.Yellow; m_style3D.LineWidth = 1; m_style3D.AltitudeMode = AltitudeMode.Absolute; m_geoLine3D.Style3D = m_style3D; m_sceneControl.Scene.TrackingLayer.Add(m_geoLine3D, "track" + (++a)); m_nodeAnimation.SetTrack(m_geoLine3D); m_nodeAnimation.Length = m_length; m_nodeAnimation.TimePostition = 0; m_sceneControl.Action = Action3D.Pan; this.btn_AddToKML.Enabled = true; } }
/// <summary> /// 鼠标动作Up /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void SceneControlMouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { EndOneMeasure(); } if (e.Button == MouseButtons.Left) { if (mPoint3Ds.Count == 0) { //ClearMeasureResult(); } if (mTempPoint != Point3D.Empty && mPoint3Ds.Count > 1) { mPoint3Ds.Remove(mPoint3Ds.Count - 1); mTempPoint = Point3D.Empty; } Point location = mSceneControl.PointToClient(Cursor.Position); Point3D point3D = new Point3D(); if (mSceneControl.Action == Action3D.MeasureDistance && mIndex == 8 || mSceneControl.Action == Action3D.MeasureAltitude && mIndex == 9 || mSceneControl.Action == Action3D.MeasureHorizontalDistance) { point3D = mSceneControl.Scene.PixelToGlobe(new Point(e.X, e.Y), SuperMap.Realspace.PixelToGlobeMode.TerrainAndModel); } else { point3D = mSceneControl.Scene.PixelToGlobe(new Point(e.X, e.Y)); } if (!Double.IsNaN(point3D.X) && !Double.IsNaN(point3D.Y) && !Double.IsNaN(point3D.Z)) { mPoint3Ds.Add(point3D); if (mSceneControl.Action == Action3D.MeasureHorizontalDistance || mSceneControl.Action == Action3D.MeasureDistance && mIndex == 8) { //添加部分段长度 if (!Toolkit.IsZero(mCurLength)) { if (mPoint3Ds.Count >= 2) { mPoint3Ds.RemoveRange(0, mPoint3Ds.Count - 2); String distanceUnit = "米"; GeoLine3D geoLine3D = new GeoLine3D(mPoint3Ds); TextPart3D textPart3D = new TextPart3D(); textPart3D.AnchorPoint = new Point3D(0, 0, 0); Double tempCurLength = mCurLength; textPart3D.Text = String.Format("{0:F2}{1}", tempCurLength, " " + distanceUnit); if (mPoint3Ds[0].X > 0 && mPoint3Ds[1].X > 0 || mPoint3Ds[0].X < 0 && mPoint3Ds[1].X < 0) { textPart3D.X = geoLine3D.InnerPoint3D.X; } else { textPart3D.X = 180; } textPart3D.Y = geoLine3D.InnerPoint3D.Y; textPart3D.Z = geoLine3D.InnerPoint3D.Z; GeoText3D text3d = mCurrentGeoText3DMessage == null?GetGeoText3DMessage() : mCurrentGeoText3DMessage; text3d.AddPart(textPart3D); //设置文字样式 text3d.TextStyle.FontHeight = 6; text3d.TextStyle.Alignment = TextAlignment.BottomLeft; text3d.TextStyle.BackColor = Color.Black; text3d.TextStyle.Outline = true; text3d.Style3D.AltitudeMode = AltitudeMode.Absolute; int index = mSceneControl.Scene.TrackingLayer.IndexOf(MessageTag); if (index >= 0) { mSceneControl.Scene.TrackingLayer.Remove(index); } //ClearTextMessageTag(); mSceneControl.Scene.TrackingLayer.Add(text3d, MessageTag); } } //测地形距离 else if (mSceneControl.Action == Action3D.MeasureTerrainDistance) { //添加部分段长度 if (!Toolkit.IsZero(mCurLength)) { if (mPoint3Ds.Count >= 2) { mPoint3Ds.RemoveRange(0, mPoint3Ds.Count - 2); GeoLine3D geoLine3D = new GeoLine3D(mPoint3Ds); String distanceUnit = "米"; TextPart3D textPart3D = new TextPart3D(); textPart3D.AnchorPoint = new Point3D(0, 0, 0); Double tempCurLength = mCurLength; textPart3D.Text = String.Format("{0:F2}{1}", tempCurLength, " " + distanceUnit); if (mPoint3Ds[0].X > 0 && mPoint3Ds[1].X > 0 || mPoint3Ds[0].X < 0 && mPoint3Ds[1].X < 0) { textPart3D.X = geoLine3D.InnerPoint.X; textPart3D.Y = geoLine3D.InnerPoint.Y; } else { textPart3D.X = 180; textPart3D.Y = geoLine3D.InnerPoint.Y; } textPart3D.Z = 0; GeoText3D text3d = GetGeoText3DMessage(); text3d.AddPart(textPart3D); text3d.TextStyle.FontHeight = 6; text3d.TextStyle.Alignment = TextAlignment.BottomLeft; text3d.TextStyle.BackColor = Color.Black; text3d.TextStyle.Outline = true; text3d.Style3D.AltitudeMode = AltitudeMode.ClampToGround;//贴地高程模式 ClearTextMessageTag(); mSceneControl.Scene.TrackingLayer.Add(text3d, MessageTag); } } } else if (mSceneControl.Action == Action3D.MeasureArea && mIndex == 10) { } else if (mSceneControl.Action == Action3D.MeasureAltitude && mIndex == 9) { //清除量算高度信息 if (!(Toolkit.IsZero(mCurAltitude))) { EndOneMeasure(); } } } } } }
/// <summary> /// 加载地下管道线 /// </summary> public void LoadPipeLine3D() { try { m_SelectedGeoNetwork = new List <NetworkGeometry>(); DatasetVector dataset_PipeLine = m_workspace.Datasources["Pipeline3D"].Datasets["PipeLine3D"] as DatasetVector; DatasetVector dataset_PipePoint = m_workspace.Datasources["Pipeline3D"].Datasets["PipePoint3D"] as DatasetVector; Layer3DSettingVector setvetor = new Layer3DSettingVector(); setvetor.Style.AltitudeMode = AltitudeMode.RelativeToGround; setvetor.Style.LineSymbolID = 962048; setvetor.Style.LineWidth = 0.35; Layer3DDataset layer_ditie = m_sceneControl.Scene.Layers.Add(dataset_PipeLine, setvetor, true, "PipeLine3D"); Layer3DDataset layer_pipepoint = m_sceneControl.Scene.Layers.Add(dataset_PipePoint, setvetor, true, "PipePoint3D"); if (dataset_PipePoint != null) { Theme3DUnique theme = new Theme3DUnique(); theme.UniqueExpression = "SmID"; GeoStyle3D style3D = new GeoStyle3D(); style3D.AltitudeMode = AltitudeMode.RelativeToGround; style3D.Marker3DScaleX = 2.2; style3D.Marker3DScaleY = 2.2; style3D.Marker3DScaleZ = 2.2; style3D.IsMarker3D = true; theme.DefaultStyle = style3D; Recordset rs = dataset_PipePoint.Query("", CursorType.Static); rs.MoveFirst(); while (!rs.IsEOF) { Theme3DUniqueItem item = new Theme3DUniqueItem(); item.Unique = rs.GetID().ToString(); item.IsModellingStyleEnabled = true; GeoStyle3D tempStyle = new GeoStyle3D(style3D); PickNodeToLine(rs.GetID()); GeoPoint3D geoPoint3D = rs.GetGeometry() as GeoPoint3D; List <Vector3d> arrVector3d = new List <Vector3d>(); for (Int32 curIndex = 0; curIndex < m_SelectedGeoNetwork.Count; curIndex++) { NetworkGeometry geoNetWork = m_SelectedGeoNetwork[curIndex]; if (geoNetWork != null) { Vector3d vec = new Vector3d(); GeoLine3D geoLine = geoNetWork.geometry as GeoLine3D; if (geoNetWork.bIsIn) { if (geoLine != null) { Point3Ds point3D = geoLine[0]; Point3D pntTNode = point3D[1]; Point3D pntFNode = point3D[0]; Vector3d vecTNode = SphericalToCartesian(pntTNode.X * DTOR, pntTNode.Y * DTOR, pntTNode.Z); Vector3d vecFNode = SphericalToCartesian(pntFNode.X * DTOR, pntFNode.Y * DTOR, pntFNode.Z); vec = new Vector3d(vecFNode.x - vecTNode.x, vecFNode.y - vecTNode.y, vecFNode.z - vecTNode.z); vec.Normalize(); } } else { if (geoLine != null) { Point3Ds point3D = geoLine[0]; Point3D pntFNode = point3D[0]; Point3D pntTNode = point3D[1]; Vector3d vecTNode = SphericalToCartesian(pntTNode.X * DTOR, pntTNode.Y * DTOR, pntTNode.Z); Vector3d vecFNode = SphericalToCartesian(pntFNode.X * DTOR, pntFNode.Y * DTOR, pntFNode.Z); vec = new Vector3d(vecTNode.x - vecFNode.x, vecTNode.y - vecFNode.y, vecTNode.z - vecFNode.z); vec.Normalize(); } } vec = FromAngleAxis(vec, -geoPoint3D.X * DTOR, new Vector3d(0, 1, 0)); vec = FromAngleAxis(vec, geoPoint3D.Y * DTOR, new Vector3d(1, 0, 0)); vec.Normalize(); arrVector3d.Add(vec); } } Vector3d vecX = new Vector3d(); Vector3d vecY = new Vector3d(); Vector3d vecZ = new Vector3d(); switch (m_SelectedGeoNetwork.Count) { case 2: //弯头或阀门 { if (arrVector3d.Count == 2) { vecX = arrVector3d[0].Normalize().Sub(); vecY = arrVector3d[1].Normalize(); } double dAngle1_2 = vecX.DotProduct(vecY); if (Math.Abs(dAngle1_2) < 0.3) { tempStyle.MarkerSymbolID = 54441; } else if (-1 < dAngle1_2 && dAngle1_2 < 0.7) { tempStyle.MarkerSymbolID = 54442; } else { vecY.z = 0; Vector3d vec = new Vector3d(0, 0, 1); vecX = vecY.CrossProduct(vec); tempStyle.MarkerSymbolID = 54435; } } break; case 3: //三通 { tempStyle.MarkerSymbolID = 54437; if (arrVector3d.Count == 3) { Vector3d vec1 = arrVector3d[0]; Vector3d vec2 = arrVector3d[1]; Vector3d vec3 = arrVector3d[2]; double dAngle1_2 = vec1.DotProduct(vec2); double dAngle1_3 = vec1.DotProduct(vec3); double dAngle2_3 = vec2.DotProduct(vec3); if (Math.Abs(dAngle1_2) < 0.3) { if (Math.Abs(dAngle1_3) < 0.3) { vecX = vec1.Normalize().Sub(); vecY = vec2.Normalize(); } else { vecX = vec2.Normalize().Sub(); vecY = vec1.Normalize(); } } else { vecX = vec3.Normalize().Sub(); vecY = vec1.Normalize(); } } } break; case 4: //四通 { tempStyle.MarkerSymbolID = 54438; if (arrVector3d.Count == 4) { Vector3d vec1 = arrVector3d[0]; Vector3d vec2 = arrVector3d[1]; Vector3d vec3 = arrVector3d[2]; double dAngle1_2 = vec1.DotProduct(vec2); double dAngle1_3 = vec1.DotProduct(vec3); vecX = vec1; if (Math.Abs(dAngle1_2) < 0.3) { vecY = vec2.Normalize(); } else { vecY = vec3.Normalize(); } } } break; default: //结点 { tempStyle.MarkerSymbolID = 330101; } break; } if (m_SelectedGeoNetwork.Count > 1) { vecZ = vecX.CrossProduct(vecY); vecZ.Normalize(); Vector3d vecRotate = ToEulerAnglesXYZ(vecX, vecY, vecZ); tempStyle.Marker3DRotateX = -vecRotate.x * RTOD; tempStyle.Marker3DRotateY = -vecRotate.y * RTOD; tempStyle.Marker3DRotateZ = -vecRotate.z * RTOD; } item.Style = tempStyle; theme.Add(item); rs.MoveNext(); } rs.Dispose(); Layer3D layer_theme = m_sceneControl.Scene.Layers.Add(dataset_PipePoint, theme, true, "underPipeLine3D"); layer_theme.IsSelectable = false; if (m_sceneControl.Scene.Layers.Contains("PipePoint3D")) { m_sceneControl.Scene.Layers.Remove("PipePoint3D"); } Camera camera = m_sceneControl.Scene.Camera; camera.AltitudeMode = AltitudeMode.RelativeToGround; camera.Altitude = 26.978640816174448; camera.Latitude = 39.992608337161023; camera.Longitude = 116.3898561529368; camera.Tilt = 59.567389444384283; camera.Heading = 300.19323029928478; m_sceneControl.Scene.Fly(camera, 1); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 标注流向 /// </summary> public void FlowLabel() { Selection3D[] selection = mSceneControl.Scene.FindSelection(true); //判断选择集是否为空 if (selection == null || selection.Length == 0) { MessageBox.Show("请选择要标注流向的空间对象"); return; } //将选择集转换为记录 Recordset recordset = selection[0].ToRecordset(); GeoLine3D m_line = recordset.GetGeometry() as GeoLine3D; Point3D m_Point3D1 = m_line.InnerPoint3D; double x1 = System.Convert.ToDouble(recordset.GetFieldValue("SmSdriE")); double y1 = System.Convert.ToDouble(recordset.GetFieldValue("SmSdriS")); double z = System.Convert.ToDouble(recordset.GetFieldValue("BottomAltitude")); Point3D m_Point3D2 = new Point3D(x1, y1, z); Point3Ds m_Point3Ds = new Point3Ds(new Point3D[] { m_Point3D1, m_Point3D2 }); m_Point3Ds = coordinateTrans3D(m_Point3Ds); GeoLine3D m_Line3D = new GeoLine3D(m_Point3Ds); // GeoModel3D m_model=m_Line3D.ConvertToGeoModel3D(false); //设置线样式 GeoStyle3D m_Style3D = new GeoStyle3D(); m_Style3D.IsMarker3D = true; m_Style3D.AltitudeMode = AltitudeMode.Absolute; m_Style3D.FillForeColor = Color.FromArgb(0x64, 0x40, 0xFF, 0x5F); m_Style3D.FillMode = FillMode3D.Fill; m_Style3D.LineColor = Color.Lime; m_Style3D.LineWidth = 3; m_Line3D.Style3D = m_Style3D.Clone(); TrackingLayer3D trackinglayer = mSceneControl.Scene.TrackingLayer; trackinglayer.IsEditable = true; trackinglayer.IsVisible = true; trackinglayer.Add(m_Line3D, "FlowLine"); // mSceneControl.Scene.Refresh(); //double x2 = System.Convert.ToDouble(mPoint3D.X); //double y2 = System.Convert.ToDouble(mPoint3D.Y); //Point3D m_Point3D1 = new Point3D(x1, y1, 0); //Point3D m_Point3D2 = new Point3D(x1, y1, 0); // Point3Ds m_Point3Ds = new Point3Ds(new Point3D[] { m_Point3D1, m_Point3D2 }); //m_Point3Ds = coordinateTrans3D(m_Point3Ds); //m_Point3D1 = m_Point3Ds[0]; //m_Point3D2 = m_Point3Ds[1]; //x1 = m_Point3D1.X; //y1 = m_Point3D1.Y; //x2 = m_Point3D2.X; //y2 = m_Point3D2.Y; //double m_Roation = Math.Atan(Math.Abs((y1 - y2) / (x1 - x2))); //m_Roation=m_Roation * 180 / Math.PI; // String m_text = string.Empty; // String m_Start = System.Convert.ToString(recordset.GetFieldValue("SmFNode")); // m_Start=""; // String m_End = System.Convert.ToString(recordset.GetFieldValue("SmTNode")); // m_End=""; // m_text = m_Start + "→→→→→→→→→" + m_End; // TextPart3D mText1 = new TextPart3D(); // mText1.Text = m_text; // mText1.AnchorPoint = m_Point3D1; // TextStyle mTextStyle1 = new TextStyle(); // mTextStyle1.FontName = "微软雅黑"; // mTextStyle1.ForeColor = Color.Red; // mTextStyle1.FontHeight = 7; // mTextStyle1.IsSizeFixed = false; // mTextStyle1.Alignment = TextAlignment.BaselineCenter; //// mTextStyle1.Rotation = m_Roation; // GeoText3D geoText_1 = new GeoText3D(mText1, mTextStyle1); // GeoStyle3D geostyle_1 = new GeoStyle3D(); // geostyle_1.AltitudeMode = AltitudeMode.RelativeToGround; // geoText_1.Style3D = geostyle_1; // TrackingLayer3D trackinglayer = mSceneControl.Scene.TrackingLayer; // trackinglayer.IsEditable = true; // trackinglayer.IsVisible = true; // trackinglayer.Add(geoText_1, "FlowLa"); // mSceneControl.Scene.Refresh(); // //得到所选对象的起点和终点坐标 // double x1=System.Convert.ToDouble(recordset.GetFieldValue("SmSdriW")); // double y1=System.Convert.ToDouble(recordset.GetFieldValue("SmSdriN")); // double x2 = System.Convert.ToDouble(recordset.GetFieldValue("SmSdriE")); // double y2 = System.Convert.ToDouble(recordset.GetFieldValue("SmSdriS")); // double z = System.Convert.ToDouble(recordset.GetFieldValue("BottomAltitude")); // Point3D m_Point3D1 = new Point3D(x1, y1, z); // Point3D m_Point3D2 = new Point3D(x2, y2, z); // Point3Ds m_Point3Ds = new Point3Ds(new Point3D[]{mPoint3D,m_Point3D2}); // m_Point3Ds=coordinateTrans3D(m_Point3Ds); // //根据坐标画线 // GeoLine3D m_Line3D = new GeoLine3D(m_Point3Ds); // //设置线样式 // GeoStyle3D m_Style3D = new GeoStyle3D(); //// m_Style3D.IsMarker3D = true; // m_Style3D.AltitudeMode = AltitudeMode.RelativeToGround; // m_Style3D.LineColor = Color.Lime; // m_Style3D.LineWidth = 3; // m_Line3D.Style3D = m_Style3D; // TrackingLayer3D trackinglayer = mSceneControl.Scene.TrackingLayer; // trackinglayer.IsEditable = true; // trackinglayer.IsVisible = true; // trackinglayer.Add(m_Line3D, "FlowLine"); // mSceneControl.Scene.Refresh(); }
//绘制线触发的事件 private void m_sceneControl_Tracked(object sender, Tracked3DEventArgs e) { Recordset recordset; Double lineWidth = 0.0; Double bottomheight = 0; try { if (flag) { if (!isRegion) { GeoLine3D geoLine3D = e.Geometry as GeoLine3D; GeoStyle3D geoStyle = new GeoStyle3D(); geoStyle.LineSymbolID = m_line3DIndex; geoStyle.LineWidth = lineWidth; geoStyle.AltitudeMode = AltitudeMode.RelativeToGround; geoStyle.BottomAltitude = bottomheight; geoLine3D.Style3D = geoStyle; recordset = m_datasetLine3D.GetRecordset(false, CursorType.Dynamic); recordset.AddNew(geoLine3D); recordset.Update(); recordset.Dispose(); m_layer3DLine.UpdateData(); m_sceneControl.Scene.Refresh(); } else { if (ispointRegion) { GeoRegion3D geoRegion3D = e.Geometry as GeoRegion3D; if (geoRegion3D.PartCount > 0) { Rectangle2D rect = geoRegion3D.Bounds; Datasource datasource = m_workspace.Datasources[0]; DatasetVector pointDataset = datasource.Datasets["Point3D"] as DatasetVector; for (double y = geoRegion3D.Bounds.Bottom; y < geoRegion3D.Bounds.Top;) { for (double x = geoRegion3D.Bounds.Left; x < geoRegion3D.Bounds.Right;) { recordset = pointDataset.GetRecordset(false, CursorType.Dynamic); Point3D pt3d = new Point3D(); pt3d.X = x; pt3d.Y = y; pt3d.Z = 0; GeoPoint3D geopoint3D = new GeoPoint3D(pt3d); GeoStyle3D geoStyle = new GeoStyle3D(); geoStyle.MarkerSymbolID = m_marker3DIndex; geoStyle.IsMarkerSizeFixed = false; geoStyle.MarkerSize = 1; geoStyle.Marker3DScaleX = 1; geoStyle.Marker3DScaleY = 1; geoStyle.Marker3DScaleZ = 1; geoStyle.IsMarker3D = true; geoStyle.AltitudeMode = AltitudeMode.RelativeToGround; geopoint3D.Style3D = geoStyle; recordset.MoveLast(); recordset.AddNew(geopoint3D); recordset.Update(); recordset.Dispose(); m_layer3DPoint.IsSelectable = false; m_layer3DPoint.UpdateData(); m_sceneControl.Scene.Refresh(); x += 0.0002; } y += 0.0002; } } } else { Datasource datasource = m_workspace.Datasources[0]; DatasetVector Region3DDataset = datasource.Datasets["Region3D"] as DatasetVector; recordset = Region3DDataset.GetRecordset(false, CursorType.Dynamic); GeoRegion3D geoRegion = e.Geometry as GeoRegion3D; GeoStyle3D geoStyle = new GeoStyle3D(); geoStyle.FillSymbolID = m_region3DIndex; geoStyle.AltitudeMode = AltitudeMode.RelativeToGround; geoStyle.BottomAltitude = 0.5; geoRegion.Style3D = geoStyle; recordset.AddNew(geoRegion); recordset.Update(); recordset.Dispose(); (m_layer3DRegion.AdditionalSetting as Layer3DSettingVector).Style = geoStyle; m_layer3DRegion.UpdateData(); m_sceneControl.Scene.Refresh(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// 鼠标右键,负责 显示分段量算结果 void m_SceneControl_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { EndOneMeasure(); } if (e.Button == MouseButtons.Left) { if (m_point3Ds.Count == 0) { //ClearMeasureResult(); } if (m_tempPoint != Point3D.Empty && m_point3Ds.Count > 1) { m_point3Ds.Remove(m_point3Ds.Count - 1); m_tempPoint = Point3D.Empty; } Point location = SmObjectLocator.getInstance().GlobeObject.PointToClient(Cursor.Position); Point3D point3D = new Point3D(); if (SmObjectLocator.getInstance().GlobeObject.Action == Action3D.MeasureDistance || SmObjectLocator.getInstance().GlobeObject.Action == Action3D.MeasureAltitude || SmObjectLocator.getInstance().GlobeObject.Action == Action3D.MeasureHorizontalDistance) { point3D = SmObjectLocator.getInstance().GlobeObject.Scene.PixelToGlobe(new Point(e.X, e.Y), SuperMap.Realspace.PixelToGlobeMode.TerrainAndModel); } else { point3D = SmObjectLocator.getInstance().GlobeObject.Scene.PixelToGlobe(new Point(e.X, e.Y)); } if (!Double.IsNaN(point3D.X) && !Double.IsNaN(point3D.Y) && !Double.IsNaN(point3D.Z)) { m_point3Ds.Add(point3D); if (SmObjectLocator.getInstance().GlobeObject.Action == Action3D.MeasureHorizontalDistance || SmObjectLocator.getInstance().GlobeObject.Action == Action3D.MeasureDistance) { //添加部分段长度 if (!Toolkit.IsZero(m_curLength)) { if (m_point3Ds.Count >= 2) { m_point3Ds.RemoveRange(0, m_point3Ds.Count - 2); String distanceUnit = "米"; GeoLine3D geoLine3D = new GeoLine3D(m_point3Ds); TextPart3D textPart3D = new TextPart3D(); textPart3D.AnchorPoint = new Point3D(0, 0, 0); Double tempCurLength = m_curLength; textPart3D.Text = String.Format("{0:F2}{1}", tempCurLength, " " + distanceUnit); if (m_point3Ds[0].X > 0 && m_point3Ds[1].X > 0 || m_point3Ds[0].X < 0 && m_point3Ds[1].X < 0) { textPart3D.X = geoLine3D.InnerPoint3D.X; } else { textPart3D.X = 180; } textPart3D.Y = geoLine3D.InnerPoint3D.Y; textPart3D.Z = geoLine3D.InnerPoint3D.Z; GeoText3D text3d = m_currentGeoText3DMessage == null ? GetGeoText3DMessage() : m_currentGeoText3DMessage; text3d.AddPart(textPart3D); text3d.TextStyle.FontHeight = 6; text3d.TextStyle.Alignment = TextAlignment.BottomLeft; text3d.TextStyle.BackColor = Color.Black; text3d.TextStyle.Outline = true; text3d.Style3D.AltitudeMode = AltitudeMode.Absolute; int index = SmObjectLocator.getInstance().GlobeObject.Scene.TrackingLayer.IndexOf(m_messageTag); if (index >= 0) { SmObjectLocator.getInstance().GlobeObject.Scene.TrackingLayer.Remove(index); } //ClearTextMessageTag(); SmObjectLocator.getInstance().GlobeObject.Scene.TrackingLayer.Add(text3d, m_messageTag); } } else if (SmObjectLocator.getInstance().GlobeObject.Action == Action3D.MeasureTerrainDistance) { //添加部分段长度 if (!Toolkit.IsZero(m_curLength)) { if (m_point3Ds.Count >= 2) { m_point3Ds.RemoveRange(0, m_point3Ds.Count - 2); GeoLine3D geoLine3D = new GeoLine3D(m_point3Ds); String distanceUnit = "米"; TextPart3D textPart3D = new TextPart3D(); textPart3D.AnchorPoint = new Point3D(0, 0, 0); Double tempCurLength = m_curLength; textPart3D.Text = String.Format("{0:F2}{1}", tempCurLength, " " + distanceUnit); if (m_point3Ds[0].X > 0 && m_point3Ds[1].X > 0 || m_point3Ds[0].X < 0 && m_point3Ds[1].X < 0) { textPart3D.X = geoLine3D.InnerPoint.X; textPart3D.Y = geoLine3D.InnerPoint.Y; } else { textPart3D.X = 180; textPart3D.Y = geoLine3D.InnerPoint.Y; } textPart3D.Z = 0; GeoText3D text3d = GetGeoText3DMessage(); text3d.AddPart(textPart3D); text3d.TextStyle.FontHeight = 6; text3d.TextStyle.Alignment = TextAlignment.BottomLeft; text3d.TextStyle.BackColor = Color.Black; text3d.TextStyle.Outline = true; text3d.Style3D.AltitudeMode = AltitudeMode.ClampToGround; ClearTextMessageTag(); SmObjectLocator.getInstance().GlobeObject.Scene.TrackingLayer.Add(text3d, m_messageTag); } } } else if (SmObjectLocator.getInstance().GlobeObject.Action == Action3D.MeasureArea) { } else if (SmObjectLocator.getInstance().GlobeObject.Action == Action3D.MeasureAltitude) { //清除量算高度信息 if (!(Toolkit.IsZero(m_curAltitude))) { EndOneMeasure(); } } } } } }
void mSceneControlSelected(object sender, ObjectSelectedEventArgs e) { Recordset recordset = null; Selection3D[] selection3d = null; mGeoLine3D = new GeoLine3D(); //水平及竖直净距 if (mSceneControl.Action == Action3D.Select && mFlag == 1 || mSceneControl.Action == Action3D.Select && mFlag == 2) { if (e.Count > 0) { selection3d = mSceneControl.Scene.FindSelection(true); recordset = selection3d[0].ToRecordset(); if (recordset.GetGeometry().Type != mGeoLine3D.Type) { MessageBox.Show("请选择三维线对象!"); } else { mGeoLine3D = recordset.GetGeometry() as GeoLine3D; if (TempGeoLine.Count > 0 && TempGeoLine[0].Bounds == mGeoLine3D.Bounds) { MessageBox.Show("请不要选择同一条三维线对象!"); } else { mTextPoint3Ds.Add(mGeoLine3D.InnerPoint3D); TempGeoLine.Add(mGeoLine3D); } } if (TempGeoLine.Count == 2) { this.SetPoint(TempGeoLine); } } } //覆土分析 if (mSceneControl.Action == Action3D.Select && mFlag == 3) { string str = ""; object obj; selection3d = mSceneControl.Scene.FindSelection(true); recordset = selection3d[0].ToRecordset(); if (e.Count > 0) { selection3d = mSceneControl.Scene.FindSelection(true); recordset = selection3d[0].ToRecordset(); if (recordset.GetGeometry().Type != mGeoLine3D.Type) { MessageBox.Show("请选择三维线对象!"); } else { mGeoLine3D = recordset.GetGeometry() as GeoLine3D; mTextPoint3Ds.Add(mGeoLine3D.InnerPoint3D); Point3D cPoint3D = new Point3D(mGeoLine3D.InnerPoint3D.X, mGeoLine3D.InnerPoint3D.Y, 0); mTextPoint3Ds.Add(cPoint3D); for (int i = 0; i < recordset.FieldCount; i++) { str = recordset.GetFieldInfos()[i].Name; if (str == "BottomAltitude") { obj = recordset.GetFieldValue(i); mAltitude = Convert.ToDouble(obj); } if (str == "PipeDiameter") { obj = recordset.GetFieldValue(i); mDiameter = new double[] { Convert.ToDouble(obj) }; } } } GetCoverRusult(); } } //碰撞检测 if (mSceneControl.Action == Action3D.Select && mFlag == 4) { if (e.Count > 0) { string str = ""; object obj; selection3d = mSceneControl.Scene.FindSelection(true); recordset = selection3d[0].ToRecordset(); if (recordset.GetGeometry().Type != mGeoLine3D.Type) { MessageBox.Show("请选择三维线对象!"); } else { mGeoLine3D = recordset.GetGeometry() as GeoLine3D; if (TempGeoLine.Count > 0 && TempGeoLine[0].Bounds == mGeoLine3D.Bounds) { MessageBox.Show("请不要选择同一条三维线对象!"); } else if (TempGeoLine.Count > 0 && recordset.Dataset.Name == TempRecordset.Dataset.Name) { MessageBox.Show("请不要选择同一数据集线对象!"); } else { mTextPoint3Ds.Add(mGeoLine3D.InnerPoint3D); TempGeoLine.Add(mGeoLine3D); TempRecordset = recordset; for (int i = 0; i < recordset.FieldCount; i++) { str = recordset.GetFieldInfos()[i].Name; if (str == "PipeDiameter") { obj = recordset.GetFieldValue(i); if (TempGeoLine.Count == 2) { mDiameter[1] = Convert.ToDouble(obj); } else { mDiameter = new double[2]; mDiameter[0] = Convert.ToDouble(obj); } } } } } if (TempGeoLine.Count == 2) { this.SetPoint(TempGeoLine); } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void TrackedHandler(object sender, Tracked3DEventArgs e) { try { // 清空临时结果 mPoint3Ds.Clear(); mCurLength = 0.0; Geometry3D geometry = e.Geometry; Point3D textLocation = new Point3D(0, 0, 0); String text = String.Empty; if (mSceneControl.Action == Action3D.MeasureDistance && mIndex == 8 || mSceneControl.Action == Action3D.MeasureTerrainDistance) { //绘制量算线对象 GeoLine3D geoLine3D = e.Geometry.Clone() as GeoLine3D; geoLine3D.Style3D = mGeoStyle3D.Clone(); if (mSceneControl.Action == Action3D.MeasureDistance && mIndex == 8) { geoLine3D.Style3D.AltitudeMode = AltitudeMode.Absolute; } else { geoLine3D.Style3D.AltitudeMode = AltitudeMode.ClampToGround; } mSceneControl.Scene.TrackingLayer.Add(geoLine3D, MeasureDistanceTag); //绘制量算点对象 Point3D point3D = Point3D.Empty; for (Int32 i = 0; i < geoLine3D.PartCount; i++) { for (Int32 j = 0; j < geoLine3D[i].Count; j++) { GeoPoint3D geoPoint3D = new GeoPoint3D(geoLine3D[i][j]); geoPoint3D.Style3D = mGeoStyle3D.Clone(); if (mSceneControl.Action == Action3D.MeasureDistance && mIndex == 8) { geoPoint3D.Style3D.AltitudeMode = AltitudeMode.Absolute; } else if (mSceneControl.Action == Action3D.MeasureTerrainDistance) { geoPoint3D.Style3D.AltitudeMode = AltitudeMode.ClampToGround; } mSceneControl.Scene.TrackingLayer.Add(geoPoint3D, MeasureDistanceTag); point3D = geoLine3D[i][j]; } } //量算结果 int index = mSceneControl.Scene.TrackingLayer.IndexOf(MessageTrackingTag); if (index >= 0) { mSceneControl.Scene.TrackingLayer.Remove(index); } // 添加结果文字 if (mSceneControl.Action == Action3D.MeasureDistance && mIndex == 8) { text = String.Format("{0}{1}{2}", "空间距离:", Math.Round(Convert.ToDecimal(e.Length), 2), "米"); } else { text = String.Format("{0}{1}{2}", "依地距离:", Math.Round(Convert.ToDecimal(e.Length), 2), "米"); } textLocation = geoLine3D[0][geoLine3D[0].Count - 1]; GeoText3D geoText = new GeoText3D(new TextPart3D(text, textLocation)); SetResultTextStyle(geoText); mSceneControl.Scene.TrackingLayer.Add(geoText, "MeasureDistance"); //计算首尾点高度差 Point3Ds point3Ds = geoLine3D[0]; double height = point3Ds[point3Ds.Count - 1].Z - point3Ds[0].Z; String message = string.Format("首尾点高度差为:{0}米。", height.ToString("##.00")); } else if (mSceneControl.Action == Action3D.MeasureArea && mIndex == 10 || mSceneControl.Action == Action3D.MeasureTerrainArea) { //绘制量算面对象 GeoRegion3D geoRegion3D = e.Geometry as GeoRegion3D; //绘制量算面对象 geoRegion3D.Style3D = mGeoStyle3D.Clone(); if (mSceneControl.Action == Action3D.MeasureArea) { geoRegion3D.Style3D.AltitudeMode = AltitudeMode.Absolute; } else { geoRegion3D.Style3D.AltitudeMode = AltitudeMode.ClampToGround; } geoRegion3D.Style3D.FillForeColor = Color.FromArgb(120, 250, 250, 50); ClearTextMessageTag(); int index = mSceneControl.Scene.TrackingLayer.IndexOf(MessageTrackingTag); if (index >= 0) { mSceneControl.Scene.TrackingLayer.Remove(index); } if (mIndex == 10) { mSceneControl.Scene.TrackingLayer.Add(geoRegion3D, "geoRegion3D"); } //绘制量算点对象 for (Int32 i = 0; i < geoRegion3D.PartCount; i++) { for (Int32 j = 0; j < geoRegion3D[i].Count; j++) { GeoPoint3D geoPoint3D = new GeoPoint3D(geoRegion3D[i][j]); geoPoint3D.Style3D = mGeoStyle3D.Clone(); if (mSceneControl.Action == Action3D.MeasureArea && mIndex == 10) { geoPoint3D.Style3D.AltitudeMode = AltitudeMode.Absolute; } else if (mSceneControl.Action == Action3D.MeasureTerrainArea) { geoPoint3D.Style3D.AltitudeMode = AltitudeMode.ClampToGround; } mSceneControl.Scene.TrackingLayer.Add(geoPoint3D, MeasureAreaTag + i.ToString() + j.ToString()); } } ClearTextMessageTag(); //量算结果 if (mSceneControl.Action == Action3D.MeasureArea && mIndex == 10) { mStrResult = String.Format("{0}{1}{2}", "空间面积:", Math.Round(Convert.ToDecimal(e.Area), 2), "平方米"); } else { mStrResult = String.Format("{0}{1}{2}", "依地面积:", Math.Round(Convert.ToDecimal(e.Area), 2), "平方米"); } GeoText3D text3d = GetGeoText3DMessage(); text3d[0].Text = mStrResult; text3d[0].X = geoRegion3D.InnerPoint3D.X; text3d[0].Y = geoRegion3D.InnerPoint3D.Y; text3d[0].Z = geoRegion3D.InnerPoint3D.Z; GeoText3D geoText = new GeoText3D(text3d); // 添加结果文字 SetResultTextStyle(geoText); mSceneControl.Scene.TrackingLayer.Add(geoText, "MeasureArea"); } else if (mSceneControl.Action == Action3D.MeasureAltitude && mIndex == 9) { //绘制量算线对象 GeoLine3D geoLine3D = e.Geometry as GeoLine3D; geoLine3D.Style3D = mGeoStyle3D.Clone(); geoLine3D.Style3D.AltitudeMode = AltitudeMode.Absolute; mSceneControl.Scene.TrackingLayer.Add(geoLine3D, "Altitude"); // 添加结果文字 text = String.Format("{0}{1}{2}", "高度:", Math.Round(Convert.ToDecimal(e.Height), 2), "米"); textLocation = geoLine3D[0][geoLine3D[0].Count - 1]; GeoText3D geoText = new GeoText3D(new TextPart3D(text, textLocation)); SetResultTextStyle(geoText); mSceneControl.Scene.TrackingLayer.Add(geoText, "Altitude"); //输出首尾点高度 Point3Ds point3Ds = geoLine3D[0]; double startHeight = point3Ds[0].Z; double endHeight = point3Ds[1].Z; string message = string.Format("首点高度为:{0}米。", startHeight.ToString("##.00")); //bd_formMain.ClearOutputMessage(); //bd_formMain.OutputMessage(message); message = string.Format("尾点高度为:{0}米。", endHeight.ToString("##.00")); //bd_formMain.OutputMessage(message); //绘制量算点对象 for (Int32 i = 0; i < geoLine3D.PartCount; i++) { for (Int32 j = 0; j < geoLine3D[i].Count; j++) { GeoPoint3D geoPoint3D = new GeoPoint3D(geoLine3D[i][j]); geoPoint3D.Style3D = mGeoStyle3D.Clone(); geoPoint3D.Style3D.AltitudeMode = AltitudeMode.Absolute; mSceneControl.Scene.TrackingLayer.Add(geoPoint3D, MeasureAltitudeTag + j.ToString()); } } ClearTextMessageTag(); if (!(Toolkit.IsZero(mCurAltitude))) { EndOneMeasure(); } } else if (mSceneControl.Action == Action3D.MeasureHorizontalDistance) { // 结果线 GeoLine3D resLine3D = e.Geometry as GeoLine3D; resLine3D.Style3D = mGeoStyle3D.Clone(); resLine3D.Style3D.AltitudeMode = AltitudeMode.Absolute; // 结果点 Point3Ds resPoints = resLine3D[0]; for (Int32 i = 0; i < resPoints.Count; i++) { GeoPoint3D geoPoint = new GeoPoint3D(resPoints[i]); SetGeometry3DStyle(geoPoint); mSceneControl.Scene.TrackingLayer.Add(geoPoint, "Geometry" + i.ToString()); } EndOneMeasure(); mSceneControl.Scene.TrackingLayer.Add(resLine3D, "Geometry"); // 添加结果文字 text = String.Format("{0}{1}{2}", "总长度: ", Math.Round(Convert.ToDecimal(e.Length), 2), "米"); GeoLine3D line = (geometry as GeoLine3D); textLocation = line[0][line[0].Count - 2]; //ClearTextMessageTag(); int index = mSceneControl.Scene.TrackingLayer.IndexOf(MessageTrackingTag); if (index >= 0) { mSceneControl.Scene.TrackingLayer.Remove(index); } GeoText3D geoText = new GeoText3D(new TextPart3D(text, textLocation)); SetResultTextStyle(geoText); mSceneControl.Scene.TrackingLayer.Add(geoText, "MeasureResult"); //bd_formMain.ClearOutputMessage(); //bd_formMain.OutputMessage(text); //计算首尾点高度差 Point3Ds point3Ds = resLine3D[0]; double height = point3Ds[point3Ds.Count - 1].Z - point3Ds[0].Z; string message = string.Format("首尾点高度差为:{0}米。", height.ToString("##.00")); //bd_formMain.OutputMessage(message); } } catch (Exception ex) { Trace.WriteLine(ex.Message); } finally { mLabel.Visible = false; } }
/// <summary> /// 获取两点之间的距离 /// </summary> /// <param name="point3D1"></param> /// <param name="point3D2"></param> /// <returns></returns> public double GetLengthBy2Point(Point3D point3D1, Point3D point3D2) { double tempR = 0.0; GeoLine3D tempL = new GeoLine3D(); Point3Ds temp3Ds = new Point3Ds(); temp3Ds.Add(point3D1); temp3Ds.Add(point3D2); tempL.AddPart(temp3Ds); tempR = Geometrist.ComputeLength(tempL, new PrjCoordSys(PrjCoordSysType.EarthLongitudeLatitude)); return tempR == 0.0 ? 10000.0 : tempR; }
private void TrackingHandler(object sender, Tracking3DEventArgs e) { string actionStr = SmObjectLocator.getInstance().GlobeObject.Action.ToString().ToLower(); if (this.TempPoints3Ds.Count == 1) { m_tempPoint = new Point3D(e.X, e.Y, e.Z); TempPoints3Ds.Add(m_tempPoint); } switch (actionStr) { case "createline": if (this.TempPoints3Ds.Count == 2) { int index = SmObjectLocator.getInstance().GlobeObject.Scene.TrackingLayer.IndexOf(spatialTempTag); if (index >= 0) { SmObjectLocator.getInstance().GlobeObject.Scene.TrackingLayer.Remove(index); } GeoLine3D geoLine3D = new GeoLine3D(TempPoints3Ds); geoLine3D.Style3D = GetGeoStyle3D(); SmObjectLocator.getInstance().GlobeObject.Scene.TrackingLayer.Add(geoLine3D, spatialTempTag); TempPoints3Ds.Remove(1); } break; case "createpolygon": if (m_tempPoint != Point3D.Empty) { TempPoints3Ds.Remove(TempPoints3Ds.Count - 1); } m_tempPoint = new Point3D(e.X, e.Y, e.Z); TempPoints3Ds.Add(m_tempPoint); if (this.TempPoints3Ds.Count > 1) { int index = SmObjectLocator.getInstance().GlobeObject.Scene.TrackingLayer.IndexOf(spatialTempTag); if (index >= 0) { SmObjectLocator.getInstance().GlobeObject.Scene.TrackingLayer.Remove(index); } TempPoints3Ds.Add(TempPoints3Ds[0]); GeoLine3D geoLine3D = new GeoLine3D(TempPoints3Ds); geoLine3D.Style3D = GetGeoStyle3D(); SmObjectLocator.getInstance().GlobeObject.Scene.TrackingLayer.Add(geoLine3D, spatialTempTag); TempPoints3Ds.Remove(TempPoints3Ds.Count - 1); } break; default: break; } }