/// <summary> /// 水平净距分析 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_HorizonDist_Click(object sender, EventArgs e) { btn_CreatePipeLine.PerformClick(); //创建传入参数 GSOPoint3d pntIntersect11 = new GSOPoint3d(); GSOPoint3d pntIntersect12 = new GSOPoint3d(); GSOPoint3d pntProIntersect11 = new GSOPoint3d(); GSOPoint3d pntProIntersect12 = new GSOPoint3d(); //水平净距分析,传入两条线,返回四个点 double vVert1 = _glbControl.Globe.Analysis3D.ComputeVerticalDistance(_pipeFeature1.Geometry as GSOGeoPolyline3D, _pipeFeature2.Geometry as GSOGeoPolyline3D, out pntIntersect11, out pntIntersect12, out pntProIntersect11, out pntProIntersect12, false); //计算两点间的空间距离 GSOGeoPolyline3D polyline1 = new GSOGeoPolyline3D(); GSOPoint3ds points1 = new GSOPoint3ds(); points1.Add(pntIntersect11); points1.Add(pntIntersect12); polyline1.AddPart(points1); //将两点间的空间距离扣除管径即为水平净距, 6378137为地球半径 vVert1 = polyline1.GetSpaceLength(true, 6378137) - _radius - _radius; MessageBox.Show(string.Format("计算出的水平净距为{0}", Math.Round(vVert1, 3))); }
private void buttonAnalyse_Click(object sender, EventArgs e) { if (m_geopolyline != null && m_globe != null) { checkBoxSameScale.Enabled = true; checkBoxXmin.Enabled = true; checkBoxYMin.Enabled = true; GSOPoint3d pntMax, pntMin, pntStart, pntEnd; GSOPoint3ds pnt3ds; double dLineLength; m_globe.Analysis3D.ProfileAnalyse(m_geopolyline, 100, out pnt3ds, out dLineLength, out pntMax, out pntMin, out pntStart, out pntEnd); m_pnt3ds = pnt3ds; m_pntMax = pntMax; m_pntMin = pntMin; m_pntStart = pntStart; m_pntEnd = pntEnd; m_dXTotalLength = dLineLength; m_dSphereLength = m_geopolyline.GetSphereLength(6378137.0); m_dSpaceLength = m_geopolyline.GetSpaceLength(false, 6378137.0); m_dGroundLength = m_globe.Analysis3D.GetGroundLength(m_geopolyline, false, 0); SetLableText(); DrawCurveGraph(); } }
private void Export(GSOPoint3d _pnt, double r) { GSOPoint3ds pnts = new GSOPoint3ds(); GSOPoint3d pnt = new GSOPoint3d(); pnt.X = _pnt.X; pnt.Y = _pnt.Y; pnt.Z = _pnt.Z; pnts.Add(pnt); pnt.X = _pnt.X; pnt.Y = _pnt.Y - 0.0000000005; pnt.Z = _pnt.Z; pnts.Add(pnt); GSOGeoPolyline3D line = new GSOGeoPolyline3D(); line.AddPart(pnts); GSOGeoPolygon3D polygon = line.CreateBuffer(r * 2, true, 5, true, false); GSOPoint3ds points = polygon[0]; GSOGeoPolyline3D newLine = new GSOGeoPolyline3D(); newLine.AddPart(points); newLine.AltitudeMode = EnumAltitudeMode.RelativeToGround; GSOFeature newFeature = new GSOFeature(); newFeature.Geometry = newLine; globeControl1.Globe.MemoryLayer.AddFeature(newFeature); // globeControl1.Globe.FlyToFeature(f); }
/// <summary> /// 开始分析 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonAnalyse_Click(object sender, EventArgs e) { //判断球和分析线不为空 if (m_geopolyline != null && globeControl1.Globe != null) { //获取线的地表长度 输入:半径 m_dSphereLength = m_geopolyline.GetSphereLength(6378137.0); //获取线的空间长度 输入: 是否忽略Z值 ,半径 m_dSpaceLength = m_geopolyline.GetSpaceLength(false, 6378137.0); //获取地标距离 输入:分析线,false,0 m_dGroundLength = globeControl1.Globe.Analysis3D.GetGroundLength(m_geopolyline, false, 0); //采样间距 float jianJu = (float)textBoxJianJu.Value; //采样数量 int pointCount = (int)(m_dSphereLength / jianJu); GSOPoint3d pntMax, pntMin, pntStart, pntEnd; GSOPoint3ds pnt3ds; double dLineLength; //获取分析结果 输入:分析线,采样数量 //输出:点集合,线长度,最大点,最小点,开始点,结束点 globeControl1.Globe.Analysis3D.ProfileAnalyse(m_geopolyline, pointCount, out pnt3ds, out dLineLength, out pntMax, out pntMin, out pntStart, out pntEnd); //开始根据数据整理成到DataGridView中 try { m_pnt3ds = pnt3ds; m_pntMax = pntMax; m_pntMin = pntMin; m_pntStart = pntStart; m_pntEnd = pntEnd; m_dXTotalLength = dLineLength; dataGridViewPoints.Rows.Clear(); int index = 1; for (int i = 0; i < m_pnt3ds.Count; i++) { GSOPoint3d pt = m_pnt3ds[i]; if (pt != null) { int rowIndex = dataGridViewPoints.Rows.Add(); dataGridViewPoints.Rows[rowIndex].Cells[0].Value = index.ToString(); dataGridViewPoints.Rows[rowIndex].Cells[1].Value = pt.X.ToString("0.0000000"); dataGridViewPoints.Rows[rowIndex].Cells[2].Value = pt.Y.ToString("0.0000000"); dataGridViewPoints.Rows[rowIndex].Cells[3].Value = pt.Z.ToString("0.00"); index++; } } //设置文字 SetLableText(); //画出图 DrawCurveGraph(); } catch (Exception ext) { MessageBox.Show("数据异常,参考信息:" + ext.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void SetControlsByStyle(GSOStyle style) { if (m_Style != null) { extentSectionLineStyle3D = m_Style as GSOExtendSectionLineStyle3D; if (extentSectionLineStyle3D == null) { extentSectionLineStyle3D = new GSOExtendSectionLineStyle3D(); extentSectionLineStyle3D.LineColor = Color.Green; GSOPoint3ds points = new GSOPoint3ds(); points.Add(new GSOPoint3d(-0.5, 0.5, 0)); points.Add(new GSOPoint3d(-0.5, -0.5, 0)); points.Add(new GSOPoint3d(0.5, -0.5, 0)); points.Add(new GSOPoint3d(0.5, 0.5, 0)); extentSectionLineStyle3D.SetSectionPoints(points); RefreshGlobe(extentSectionLineStyle3D); } } else { extentSectionLineStyle3D = new GSOExtendSectionLineStyle3D(); extentSectionLineStyle3D.LineColor = Color.Green; GSOPoint3ds points = new GSOPoint3ds(); points.Add(new GSOPoint3d(-0.5, 0.5, 0)); points.Add(new GSOPoint3d(-0.5, -0.5, 0)); points.Add(new GSOPoint3d(0.5, -0.5, 0)); points.Add(new GSOPoint3d(0.5, 0.5, 0)); extentSectionLineStyle3D.SetSectionPoints(points); RefreshGlobe(extentSectionLineStyle3D); } // 这句要写到前面,不然下面Checked的时候要检查 pictureBoxLineColor.BackColor = extentSectionLineStyle3D.LineColor; numericUpDownLineOpaque.Value = extentSectionLineStyle3D.LineColor.A; textBoxCornerSliceAngle.Text = extentSectionLineStyle3D.CornerSliceAngle.ToString(); GSOPoint3ds mpoints = extentSectionLineStyle3D.GetSectionPoints(); if (mpoints != null && mpoints.Count > 0) { for (int i = 0; i < mpoints.Count; i++) { GSOPoint3d point = mpoints[i]; if (point != null) { textBoxLineRadius.Text = (Math.Abs(point.X) * 2).ToString(); textBoxThickness.Text = (Math.Abs(point.Y) * 2).ToString(); break; } } } m_bInitialized = true; }
// 沿线运动对象 private void btn_MoveObj_Click(object sender, EventArgs e) { //创建路线(也可以通过获取) GSOGeoPolyline3D polyLine = new GSOGeoPolyline3D(); GSOPoint3ds pnts = new GSOPoint3ds(); //创建节点对象 //把各节点添加到节点对象上 pnts.Add(new GSOPoint3d(120.4, 31.3, 0)); pnts.Add(new GSOPoint3d(120.41, 31.31, 0)); pnts.Add(new GSOPoint3d(120.42, 31.32, 0)); pnts.Add(new GSOPoint3d(120.43, 31.30, 0)); pnts.Add(new GSOPoint3d(120.44, 31.34, 0)); polyLine.AddPart(pnts); GSORoute route = new GSORoute(); //创建路径 for (int i = 0; i < polyLine[0].Count; i++) { route.Add(polyLine[0][i]); } // 设置路径属性 route.CircleRoute = true; //路径是否闭合 route.Speed = 10; //沿线运动速度 route.SpeedAcceleration = 1; //加速度 route.RotateSpeed = 10; //拐弯速度 //加载模型 GSOGeoModel model = new GSOGeoModel(); model.FilePath = _modelPath; //3D模型路径 //创建沿线运动模型要素 GSOGeoDynamicRoute dynamicRoute = new GSOGeoDynamicRoute(); dynamicRoute.ActorGeometry = model; //添加模型到沿线运动模型上 dynamicRoute.Route = route; //赋路线 dynamicRoute.Play(); //播放运动 dynamicRoute.TimerInterval = 20; //播放时间间隔 GSOFeature feature = new GSOFeature(); feature.Geometry = dynamicRoute; GSOFeature polylineFeature = new GSOFeature(); polylineFeature.Geometry = polyLine; _glbControl.Globe.MemoryLayer.AddFeature(feature); _glbControl.Globe.MemoryLayer.AddFeature(polylineFeature); _glbControl.Globe.FlyToFeature(polylineFeature); }
//水面 private void btn_Water_Click(object sender, EventArgs e) { GSOGeoWater water = new GSOGeoWater(); GSOPoint3ds polygonPnts = new GSOPoint3ds(); // 创建水面的节点 polygonPnts.Add(new GSOPoint3d(120.47, 31.3, 0)); polygonPnts.Add(new GSOPoint3d(120.48, 31.3, 0)); polygonPnts.Add(new GSOPoint3d(120.48, 31.25, 0)); polygonPnts.Add(new GSOPoint3d(120.47, 31.2, 0)); water.AddPart(polygonPnts); water.Play(); //播放水面动态效果 water.WaveSpeedX = 0; //X方向水流速度 water.WaveSpeedY = 0.1; //Y方向水流速度 AddNewGeoToLayer(water, "水面"); }
private void btn_addPowerLine_Click(object sender, EventArgs e) { //创建杆塔节点位置 GSOPoint3d point1 = new GSOPoint3d(120.121, 30.210, 0); GSOPoint3d point2 = new GSOPoint3d(120.121, 30.2105, 0); GSOPoint3ds points = new GSOPoint3ds(); //加载顺序就是连接顺序 points.Add(point1); points.Add(point2); //电力线 GSOGeoPowerLine powerLine = new GSOGeoPowerLine(); for (int i = 0; i < points.Count; i++) { //创建杆塔节点 GSOGeoPowerLineNode node = new GSOGeoPowerLineNode(); node.Position = points[i]; //添加杆塔模型 node.NodeTemplatePath = i % 2 == 0 ? _modelPath : _modelPath; //赋予旋转角(需要调整旋转角适应电力线位置) node.RotateZ = 0; //将杆塔节点添加到电力线 powerLine.AddNode(node); } //电力线样式设置 powerLine.LinkLineStyle = new GSOElecLineStyle3D() { LineColor = Color.White, //电力线半径 Radius = 0.05, //分段数 Slice = 5, //电力线曲率 CurveFactor = 0.0002 }; //新建要素 GSOFeature feature = new GSOFeature(); feature.Geometry = powerLine; //添加要素到globe中 _glbControl.Globe.MemoryLayer.AddFeature(feature); _glbControl.Globe.JumpToFeature(feature, 1500); }
private void AddPolygon() { GSOGeoPolygon3D geoPolygon = new GSOGeoPolygon3D(); //创建多边形对象 //创建节点对象 GSOPoint3ds polygonPnts = new GSOPoint3ds(); polygonPnts.Add(new GSOPoint3d(116.7, 39.8, 0)); polygonPnts.Add(new GSOPoint3d(116.8, 39.9, 0)); polygonPnts.Add(new GSOPoint3d(116.8, 39.7, 0)); polygonPnts.Add(new GSOPoint3d(116.7, 39.7, 0)); geoPolygon.AddPart(polygonPnts); //把节点添加到多边形对象上 GSOSimplePolygonStyle3D stylePolygon = new GSOSimplePolygonStyle3D(); //创建风格 stylePolygon.OutLineVisible = true; //显示多边形的边缘线 //设置多边形的填充颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255 stylePolygon.FillColor = Color.FromArgb(100, 255, 255, 0); geoPolygon.Style = stylePolygon; //把风格添加到多边形上 //创建几何对象并设置属性 GSOFeature f = new GSOFeature(); f.Geometry = geoPolygon; f.Name = "多边形 01"; f.SetFieldValue("description", "a demo polygon"); #region 属性设置 f.Description = "<html>\r\n<head>\r\n<style>\r\n#tab-list {\r\nborder-collapse:collapse;\r\nfont-size:15px;\r\nmargin:20px;\r\ntext-align:left;\r\nwidth:280px;\r\n}\r\n\r\n#tab-list th {\r\nborder-bottom:2px solid #6678B1;\r\ncolor:#003399;\r\nfont-size:14px;\r\nfont-weight:normal;\r\npadding:10px 8px;\r\n}\r\n#tab-list td {\r\nborder-bottom:1px solid #CCCCCC;\r\ncolor:#666699;\r\npadding:6px 8px;\r\n}\r\n</style>\r\n</head>\r\n<body style=\"border:none\">\r\n<center>\r\n<table id=\"tab-list\">\r\n<thead><tr><th>属性名称</th><th>属性值</th></tr></thead>\r\n<tbody>$tablecontent</tbody></table>\r\n</center>\r\n</body>\r\n</html>\r\n"; GSOGeoPolyline3D line = new GSOGeoPolyline3D(); line.AddPart((f.Geometry as GSOGeoPolygon3D)[0]); double length = line.GetSpaceLength(true, 6378137) / 1000; Dictionary <string, string> property = new Dictionary <string, string>(); property.Add("面积", ((f.Geometry as GSOGeoPolygon3D).Area / 1000000).ToString("f4") + "平方千米"); property.Add("周长", length.ToString("f2") + "千米"); f.Description = f.Description.Replace("$tablecontent", maketable(property)); #endregion globeControl1.Globe.MemoryLayer.AddFeature(f); //把几何要素添加到内存图层中 }
// 线 private void btn_Polyline_Click(object sender, System.EventArgs e) { GSOGeoPolyline3D line = new GSOGeoPolyline3D(); //创建线对象 GSOPoint3ds pnts = new GSOPoint3ds(); //创建节点对象 pnts.Add(new GSOPoint3d(120.4, 31.3, 1000)); //把各节点添加到节点对象上 pnts.Add(new GSOPoint3d(120.41, 31.31, 3000)); pnts.Add(new GSOPoint3d(120.42, 31.32, 2000)); pnts.Add(new GSOPoint3d(120.43, 31.30, 2500)); pnts.Add(new GSOPoint3d(120.44, 31.34, 4000)); line.AddPart(pnts); //把节点添加到线上 GSOSimpleLineStyle3D style = new GSOSimpleLineStyle3D(); line.Style = style; AddNewGeoToLayer(line, "线"); }
public void LoadChartEvent() { try { this.Shown += new EventHandler(Frm_HDMAnalysis2_Shown); chart1.Series["管线"].ChartType = SeriesChartType.Point; chart1.Series["管线"]["DrawingStyle"] = "Cylinder"; chart1.Series["管线"].MarkerStyle = MarkerStyle.Circle; //点的类型 chart1.Series["管线"].MarkerBorderColor = Color.Black; //点的边框颜色 chart1.ChartAreas[0].AxisX.Minimum = 0; //x轴的起始点大小 chart1.ChartAreas[0].AxisX.Maximum = line.GetSpaceLength(true, 6378137); chart1.ChartAreas[0].AxisY.Maximum = 0; //y轴的最大值 chart1.ChartAreas[0].AxisX.Title = "距离 (米)"; chart1.ChartAreas[0].AxisY.Title = "埋深 (米)"; //chart1.ChartAreas[0].AxisY2.Title = "大家好 ()"; //chart1.ChartAreas[0].AxisY2.Maximum = 10000; //chart1.ChartAreas[0].AxisY2.CustomLabels.Add(-3d, -2d, "1"); //chart1.ChartAreas[0].AxisY2.CustomLabels.Add(-2d, -1.5d, "2"); //chart1.ChartAreas[0].AxisY2.CustomLabels.Add(-1.5d, -1d, "3"); //chart1.ChartAreas[0].AxisY2.CustomLabels.Add(-1d, -0.5d, "4"); //chart1.ChartAreas[0].AxisY2.CustomLabels.Add(-0.5d, 0d, "5"); //chart1.ChartAreas[0].AxisY2.CustomLabels.Add(0d, 1d, "6"); if (line.PartCount > 0) { GSOPoint3ds nodes = line[0]; GSOPoint3d node = nodes[0]; A_x = node.X; A_y = node.Y; } DrawCurveGraph(A_x, A_y); } catch (Exception ex) { Log.PublishTxt(ex); } }
private GSOPoint3ds getAllPointInPipeline(GSOGeoPolyline3D pipeline) { GSOPoint3ds points = new GSOPoint3ds(); if (pipeline != null) { for (int i = 0; i < pipeline.PartCount; i++) { GSOPoint3ds pnts = pipeline[i]; for (int j = 0; j < pnts.Count; j++) { GSOPoint3d pt = pnts[j]; points.Add(pt); } } } return(points); }
// 面 private void btn_Polygon_Click(object sender, System.EventArgs e) { GSOGeoPolygon3D polygon = new GSOGeoPolygon3D(); //创建多边形对象 //创建节点对象 GSOPoint3ds polygonPnts = new GSOPoint3ds(); polygonPnts.Add(new GSOPoint3d(120.47, 31.3, 0)); polygonPnts.Add(new GSOPoint3d(120.48, 31.3, 0)); polygonPnts.Add(new GSOPoint3d(120.48, 31.25, 0)); polygonPnts.Add(new GSOPoint3d(120.47, 31.2, 0)); polygon.AddPart(polygonPnts); //把节点添加到多边形对象上 GSOSimplePolygonStyle3D style = new GSOSimplePolygonStyle3D(); style.FillColor = Color.FromArgb(255, Color.Gray); polygon.Style = style; AddNewGeoToLayer(polygon, "面"); }
private void buttonInsertNode_Click(object sender, EventArgs e) { if (listViewNodeList.SelectedIndices.Count > 0) { int nSelIndex = listViewNodeList.SelectedIndices[0]; GSOPoint3ds nodes = GetCurNodes(); if (nodes != null && nodes.Count > nSelIndex) { m_GlobeControl.Globe.AddToEditHistroy(mlayer, mfeature, EnumEditType.Modify); GSOPoint3d newPoint = new GSOPoint3d(); try { newPoint.X = Double.Parse(textBoxX.Text); newPoint.Y = Double.Parse(textBoxY.Text); newPoint.Z = Double.Parse(textBoxZ.Value.ToString()); } catch (System.Exception exp) { Log.PublishTxt(exp); } nodes.Insert(nSelIndex, newPoint); /* * ListViewItem item = new ListViewItem(); * item.SubItems.Add(textBoxX.Text); * item.SubItems.Add(textBoxY.Text); * item.SubItems.Add(textBoxZ.Text); * listViewNodeList.Items.Insert(nSelIndex,item); */ UpdateNodeViewList(); // 选中刚才的那个索引 SelectItem(m_nCurSelected); if (m_GlobeControl != null) { m_GlobeControl.Refresh(); } } } }
private void UpdateNodeViewList() { GSOPoint3ds nodes = GetCurNodes(); if (nodes != null) { listViewNodeList.Items.Clear(); for (int i = 0; i < nodes.Count; i++) { ListViewItem item = new ListViewItem(); item.SubItems[0].Text = i.ToString(); item.SubItems.Add(nodes[i].X.ToString()); item.SubItems.Add(nodes[i].Y.ToString()); item.SubItems.Add(nodes[i].Z.ToString()); listViewNodeList.Items.Add(item); } labelNumPoints.Text = "节点共" + listViewNodeList.Items.Count.ToString() + "个"; } }
/// <summary> /// 创建面 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddPolygon_Click(object sender, EventArgs e) { GSOGeoPolygon3D geoPolygon = new GSOGeoPolygon3D(); //创建多边形对象 //创建节点对象 GSOPoint3ds polygonPnts = new GSOPoint3ds(); polygonPnts.Add(new GSOPoint3d(116.7, 39.8, 0)); polygonPnts.Add(new GSOPoint3d(116.8, 39.9, 0)); polygonPnts.Add(new GSOPoint3d(116.8, 39.7, 0)); polygonPnts.Add(new GSOPoint3d(116.7, 39.7, 0)); geoPolygon.AddPart(polygonPnts); //把节点添加到多边形对象上 GSOSimplePolygonStyle3D stylePolygon = new GSOSimplePolygonStyle3D(); //创建风格 stylePolygon.OutLineVisible = true; //显示多边形的边缘线 //设置多边形的填充颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255 stylePolygon.FillColor = Color.FromArgb(100, 255, 255, 0); geoPolygon.Style = stylePolygon; //把风格添加到多边形上 //创建几何对象并设置属性 GSOFeature f = new GSOFeature(); f.Geometry = geoPolygon; f.Name = "多边形 01"; f.SetFieldValue("description", "a demo polygon"); //绑定数据 btnRemovePolygon.Tag = f; globeControl1.Globe.MemoryLayer.AddFeature(f); //把几何要素添加到内存图层中 //下面不属于工程内容,只是飞到点的位置 GSOCameraState cs = new GSOCameraState(); cs.Longitude = 116.75; cs.Latitude = 39.8; cs.Altitude = 50000; globeControl1.Globe.FlyToCameraState(cs); }
private void Form1_Load(object sender, EventArgs e) { #region 创建面要素和飞到面 GSOGeoPolygon3D geoPolygon = new GSOGeoPolygon3D(); //创建多边形对象 //创建节点对象 GSOPoint3ds polygonPnts = new GSOPoint3ds(); polygonPnts.Add(new GSOPoint3d(116.7, 39.8, 0)); polygonPnts.Add(new GSOPoint3d(116.8, 39.9, 0)); polygonPnts.Add(new GSOPoint3d(116.8, 39.7, 0)); polygonPnts.Add(new GSOPoint3d(116.7, 39.7, 0)); geoPolygon.AddPart(polygonPnts); //把节点添加到多边形对象上 GSOSimplePolygonStyle3D stylePolygon = new GSOSimplePolygonStyle3D(); //创建风格 stylePolygon.OutLineVisible = true; //显示多边形的边缘线 //设置多边形的填充颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255 stylePolygon.FillColor = Color.FromArgb(100, 255, 255, 0); geoPolygon.Style = stylePolygon; //把风格添加到多边形上 //下面不属于工程内容,只是飞到点的位置 GSOCameraState cs = new GSOCameraState(); cs.Longitude = 116.75; cs.Latitude = 39.8; cs.Altitude = 50000; globeControl1.Globe.FlyToCameraState(cs); #endregion //创建几何对象并设置属性 GSOFeature f = new GSOFeature(); f.Geometry = geoPolygon; f.Name = "多边形 01"; f.CustomID = 1; f.SetFieldValue("description", "a demo polygon"); f.Description = "这是一个多边形"; //将面添加到球中 feature = globeControl1.Globe.MemoryLayer.AddFeature(f); //添加的时候获取要素 }
private GSOFeature makeLine() { GSOGeoPolyline3D line = new GSOGeoPolyline3D(); //创建线对象 GSOPoint3ds pnts = new GSOPoint3ds(); //创建节点对象 pnts.Add(new GSOPoint3d(116.6, 39.9, 1000)); //把各节点添加到节点对象上 pnts.Add(new GSOPoint3d(116.61, 39.91, 3000)); pnts.Add(new GSOPoint3d(116.62, 39.92, 2000)); pnts.Add(new GSOPoint3d(116.63, 39.90, 2500)); pnts.Add(new GSOPoint3d(116.64, 39.94, 4000)); line.AddPart(pnts); //把节点添加到线上 GSOSimpleLineStyle3D style = new GSOSimpleLineStyle3D(); //创建线的风格 //设置透明度及颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255 style.LineColor = Color.FromArgb(150, 0, 255, 0); style.LineWidth = 3; //设置线的宽度为3 style.VertexVisible = true; //显示线的节点 line.Style = style; //把风格添加到线上 //创建几何对象并设置属性 GSOFeature f = new GSOFeature(); f.Geometry = line; //把线对象添加到几何对象上 f.Name = "线 01"; //设置几何对象的名称 f.SetFieldValue("description", "这是线的属性"); //设置几何对象的字段值 //把几何要素添加到内存图层中 globeControl1.Globe.MemoryLayer.AddFeature(f); //下面不属于工程内容,只是飞到点的位置 GSOCameraState cs = new GSOCameraState(); cs.Longitude = 116.62; cs.Latitude = 39.92; cs.Altitude = 9000; globeControl1.Globe.FlyToCameraState(cs); return(f); }
/// <summary> /// 向图层数据中添加要素Feature /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_EditFeature_Click(object sender, EventArgs e) { //新建要素 GSOGeoPolygon3D polygon = new GSOGeoPolygon3D(); GSOPoint3ds points = new GSOPoint3ds(); points.Add(new GSOPoint3d(120, 30, 0)); points.Add(new GSOPoint3d(120.004, 30, 0)); points.Add(new GSOPoint3d(120.002, 30.001, 0)); polygon.AddPart(points); GSOFeature feature = new GSOFeature(); feature.Geometry = polygon; _featureLayer.AddFeature(feature); _glbControl.Globe.MemoryLayer.AddFeature(feature); _glbControl.Globe.FlyToFeature(feature); _featureLayer.Save(); }
private void textBoxThickness_TextChanged(object sender, EventArgs e) { if (extentSectionLineStyle3D != null) { try { double width = 0.0; if (textBoxThickness.Text.Trim() == "" || double.TryParse(textBoxThickness.Text, out width) == false) { return; } m_GlobeControl.Globe.AddToEditHistroy(mlayer, mfeature, EnumEditType.Modify); GSOPoint3ds points = extentSectionLineStyle3D.GetSectionPoints(); for (int i = 0; i < points.Count; i++) { GSOPoint3d point = points[i]; if (point != null) { if (point.Y > 0) { point.Y = width / 2; } else { point.Y = -width / 2; } } points[i] = point; } extentSectionLineStyle3D.SetSectionPoints(points); RefreshGlobe(extentSectionLineStyle3D); } catch (System.Exception exp) { Log.PublishTxt(exp); } } }
private void buttonAddNode_Click(object sender, EventArgs e) { GSOPoint3ds nodes = GetCurNodes(); if (nodes != null) { m_GlobeControl.Globe.AddToEditHistroy(mlayer, mfeature, EnumEditType.Modify); GSOPoint3d newPoint = new GSOPoint3d(); try { newPoint.X = Double.Parse(textBoxX.Text); newPoint.Y = Double.Parse(textBoxY.Text); newPoint.Z = Double.Parse(textBoxZ.Value.ToString()); } catch (System.Exception exp) { Log.PublishTxt(exp); //MessageBox.Show(exp.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } /* * ListViewItem item = new ListViewItem(); * item.SubItems.Add(textBoxX.Text); * item.SubItems.Add(textBoxY.Text); * item.SubItems.Add(textBoxZ.Text); * listViewNodeList.Items.Add(item); */ nodes.Add(newPoint); UpdateNodeViewList(); // 选中最后一个 SelectItem(listViewNodeList.Items.Count - 1); if (m_GlobeControl != null) { m_GlobeControl.Refresh(); } } }
private GSOExtendSectionLineStyle3D createRectStyle(double width, double height) { GSOExtendSectionLineStyle3D style = new GSOExtendSectionLineStyle3D(); style.LineColor = Color.FromArgb(Convert.ToByte(numOpaqueRect.Value), btnRectColor.BackColor); if (width == 0 || height == 0) { return(null); } GSOPoint3ds sectionpts = new GSOPoint3ds(); sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0)); sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0)); sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0)); sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0)); style.SetSectionPoints(sectionpts); style.IsClosed = true; style.SetAnchorByAlign(EnumAlign.MiddleCenter); return(style); }
private void AddLine() { GSOGeoPolyline3D line = new GSOGeoPolyline3D(); //创建线对象 GSOPoint3ds pnts = new GSOPoint3ds(); //创建节点对象 pnts.Add(new GSOPoint3d(116.6, 39.9, 1000)); //把各节点添加到节点对象上 pnts.Add(new GSOPoint3d(116.61, 39.91, 3000)); pnts.Add(new GSOPoint3d(116.62, 39.92, 2000)); pnts.Add(new GSOPoint3d(116.63, 39.90, 2500)); pnts.Add(new GSOPoint3d(116.64, 39.94, 4000)); line.AddPart(pnts); //把节点添加到线上 GSOSimpleLineStyle3D style = new GSOSimpleLineStyle3D(); //创建线的风格 //设置透明度及颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255 style.LineColor = Color.FromArgb(150, 0, 255, 0); style.LineWidth = 3; //设置线的宽度为3 style.VertexVisible = true; //显示线的节点 line.Style = style; //把风格添加到线上 //创建几何对象并设置属性 GSOFeature lineFeature = new GSOFeature(); lineFeature.Geometry = line; //把线对象添加到几何对象上 lineFeature.Name = "线 01"; //设置几何对象的名称 lineFeature.SetFieldValue("description", "这是线的属性"); //设置几何对象的字段值 lineFeature.Description = "<html>\r\n<head>\r\n<style>\r\n#tab-list {\r\nborder-collapse:collapse;\r\nfont-size:15px;\r\nmargin:20px;\r\ntext-align:left;\r\nwidth:280px;\r\n}\r\n\r\n#tab-list th {\r\nborder-bottom:2px solid #6678B1;\r\ncolor:#003399;\r\nfont-size:14px;\r\nfont-weight:normal;\r\npadding:10px 8px;\r\n}\r\n#tab-list td {\r\nborder-bottom:1px solid #CCCCCC;\r\ncolor:#666699;\r\npadding:6px 8px;\r\n}\r\n</style>\r\n</head>\r\n<body style=\"border:none\">\r\n<center>\r\n<table id=\"tab-list\">\r\n<thead><tr><th>属性名称</th><th>属性值</th></tr></thead>\r\n<tbody>$tablecontent</tbody></table>\r\n</center>\r\n</body>\r\n</html>\r\n"; double lineLength = line.GetSpaceLength(true, 6378137); Dictionary <string, string> property = new Dictionary <string, string>(); property.Add("长度", (lineLength / 1000).ToString("0.00") + "KM"); lineFeature.Description = lineFeature.Description.Replace("$tablecontent", maketable(property)); //把几何要素添加到内存图层中 globeControl1.Globe.MemoryLayer.AddFeature(lineFeature); }
private void buttonDelNode_Click(object sender, EventArgs e) { if (listViewNodeList.SelectedIndices.Count > 0) { int nSelIndex = listViewNodeList.SelectedIndices[0]; GSOPoint3ds nodes = GetCurNodes(); if (nodes != null && nodes.Count > nSelIndex) { m_GlobeControl.Globe.AddToEditHistroy(mlayer, mfeature, EnumEditType.Modify); nodes.Remove(nSelIndex); UpdateNodeViewList(); // 选中刚才的那个索引 SelectItem(m_nCurSelected); if (m_GlobeControl != null) { m_GlobeControl.Refresh(); } } } }
private GSOPoint3ds GetCurNodes() { GSOPoint3ds nodes = null; if (m_Geometry.Type == EnumGeometryType.GeoPolyline3D) { GSOGeoPolyline3D geoPolyline3D = m_Geometry as GSOGeoPolyline3D; if (geoPolyline3D.PartCount > 0) { //一条线由多条子线组成,目前就显示第一条子线的节点内容把 nodes = geoPolyline3D[0]; } } else if (m_Geometry.Type == EnumGeometryType.GeoPolygon3D || m_Geometry.Type == EnumGeometryType.GeoWater) { GSOGeoPolygon3D geoPolygon3D = m_Geometry as GSOGeoPolygon3D; if (geoPolygon3D.PartCount > 0) { nodes = geoPolygon3D[0]; } } return(nodes); }
private GSOExtendSectionLineStyle3D createRectStyle(double width, double height) { GSOExtendSectionLineStyle3D style = new GSOExtendSectionLineStyle3D(); style.LineColor = Color.FromArgb(Convert.ToByte(numOpaqueRect.Value), btnRectColor.BackColor); if (width == 0 || height == 0) return null; GSOPoint3ds sectionpts = new GSOPoint3ds(); sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0)); sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0)); sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0)); sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0)); style.SetSectionPoints(sectionpts); style.IsClosed = true; style.SetAnchorByAlign(EnumAlign.MiddleCenter); return style; }
private GSOFeatures getFeatureByPolygon(GSOLayer layer,GSOFeatures features, GSOPoint3d point, double allowValue) { if (layer == null || point == null || allowValue <= 0) { return null; } GSOGeoPolyline3D bufferLine = new GSOGeoPolyline3D(); GSOPoint3ds points = new GSOPoint3ds(); points.Add(point); GSOPoint3d newPoint = new GSOPoint3d(); newPoint.X = point.X + 0.00001; newPoint.Y = point.Y; newPoint.Z = point.Z; points.Add(newPoint); bufferLine.AddPart(points); GSOGeoPolygon3D polygon = bufferLine.CreateBuffer(allowValue, true, 12, false, false); layer.RemoveAllFeature(); layer.AddFeatures(features); GSOFeatures featuresInPolygon = layer.FindFeaturesInPolygon(polygon, false); return featuresInPolygon; }
private void ConnexityAnalysis() { GSODataset curCAYDataset = m_ConnexityAnalysisFirstLayer.Dataset; string srName = curCAYDataset.Name; GSONetworkDataset curCAYNDataset = curCAYDataset.DataSource.GetDatasetByName(srName + "Network") as GSONetworkDataset; if (curCAYNDataset == null) { MessageBox.Show("该图层没有创建网络拓扑,请先创建网络拓扑信息再进行分析!", "提示"); return; } int[] arryResID; curCAYNDataset.ConnexityAnalysis(m_ConnexityAnalysisFirstFeature.ID, m_ConnexityAnaylsisSecondFeature.ID, out arryResID, false, true); m_ConnexityAnalyResFeatures = m_ConnexityAnalysisFirstLayer.GetFeaturesByIDs(arryResID); if (m_ConnexityAnalyResFeatures == null || m_ConnexityAnalyResFeatures.Length < 1) { String strLine1 = "管线:" + m_ConnexityAnalysisFirstFeature.ID; String strLine2 = "管线:" + m_ConnexityAnaylsisSecondFeature.ID; MessageBox.Show(strLine1 + " 与 " + strLine2 + " 不连通", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { int nCount = m_ConnexityAnalyResFeatures.Length; GSOGeoPolyline3D effectLine = new GSOGeoPolyline3D(); GSOPoint3ds effectPart = new GSOPoint3ds(); for (int i = 0; i < nCount; i++) { m_ConnexityAnalyResFeatures[i].HighLight = true; GSOGeoPolyline3D geoline = m_ConnexityAnalyResFeatures[i].Geometry as GSOGeoPolyline3D; if (geoline != null) { //管线显示流动效果 for (int j = 0; j < geoline.PartCount; j++) { effectLine.AddPart(geoline[j]); } } } effectLine.SmoothToSpline(); GSOFeature feature = new GSOFeature(); feature.Geometry = effectLine; if (feature.Geometry.Style == null) { feature.Geometry.Style = new GSOSimpleLineStyle3D(); } feature.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround; ((GSOStyle3D)feature.Geometry.Style).UsingBlur = true; globeControl1.Globe.MemoryLayer.AddFeature(feature); GSOAniFeature featureAnimation = new GSOAniFeature();//动画的类型--要素动画 featureAnimation.Feature = feature; //动画的关联对象 GSOGeoMarker marker = new GSOGeoMarker(0, 0, 0,""); GSOMarkerStyle3D markerStyle = new GSOMarkerStyle3D(); markerStyle.IconPath = Application.StartupPath + "/Resource/image/star4.bmp"; marker.Style = markerStyle; marker.AltitudeMode = EnumAltitudeMode.RelativeToGround; GSOFeature markerFeature = new GSOFeature(); markerFeature.Geometry = marker; GSOAniEffectLineGrow effect = new GSOAniEffectLineGrow();//动画效果-线增长动画 effect.StartValue = 0; effect.EndValue = 1; effect.FrameCount = 1200; effect.RepeatCount = 1; effect.IsSmooth = false; effect.ActorFeature = markerFeature; GSOAniKeyFrame keyFream = new GSOAniKeyFrame(); //关键帧 keyFream.Frame = 0; keyFream.AddEffect(effect); //给关键帧添加动画效果 GSOAniObjTimeLine timeLine = new GSOAniObjTimeLine();//动画对象 timeLine.Name = "线增长动画对象"; timeLine.AniObject = featureAnimation; //动画对象的动画类型 timeLine.AddKeyFrame(keyFream); //给动画对象添加关键帧 GSOAnimationPage page = new GSOAnimationPage(); //动画 page.FPS = 60; //动画--帧率 page.FrameCount = 20 * 60; //动画时长 * 帧率 //动画--帧总数 page.Name = "线增长动画"; page.AddObjTimeLine(timeLine); //给动画添加动画对象 globeControl1.Globe.AnimationPages.Add(page); globeControl1.Globe.AnimationPages.GetAt(globeControl1.Globe.AnimationPages.Length - 1).Play(); globeControl1.Refresh(); } }
//应用 private void buttonApply_Click(object sender, EventArgs e) { if (comboBoxLayerCaption.SelectedItem == null) { MessageBox.Show("请选择一个管线图层!", "提示"); return; } if (comboBoxLayerValveCaption.SelectedItem == null) { MessageBox.Show("请选择一个工井图层!", "提示"); return; } if (textBoxValueIndented.Text.Trim() == "") { MessageBox.Show("请输入缩进距离!", "提示"); return; } if (textBoxAllowance.Text.Trim() == "") { MessageBox.Show("请输入容限值!", "提示"); return; } double valueAllowance = 0.0; if (double.TryParse(textBoxAllowance.Text.Trim(), out valueAllowance) == false) { MessageBox.Show("请输入一个正确的容限值!", "提示"); return; } float valueIndented = 0.0f; if (float.TryParse(textBoxValueIndented.Text.Trim(), out valueIndented) == false) { MessageBox.Show("请输入一个正确的缩进值!", "提示"); return; } string layerCaption = comboBoxLayerCaption.SelectedItem.ToString().Trim(); string valveLayerCaption = comboBoxLayerValveCaption.SelectedItem.ToString().Trim(); GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(layerCaption); GSOLayer valveLayer = globeControl1.Globe.Layers.GetLayerByCaption(valveLayerCaption); if (layer != null && valveLayerCaption != null) { featuresIndented.RemoveAll(); cancelHighLight(layer.GetAllFeatures()); for (int i = 0; i < layer.GetAllFeatures().Length; i++) { GSOFeature feature = layer.GetAt(i); if (feature != null && feature.Geometry != null && feature.Geometry.Type == EnumGeometryType.GeoPolyline3D) { GSOGeoPolyline3D line = feature.Geometry as GSOGeoPolyline3D; double lineLenght = line.GetSpaceLength(false, 6378137.0); if (lineLenght <= valueIndented * 2) { continue; } featuresIndented.Add(feature);//缩进的管线集合 featuresInit.Add(feature.Clone()); //头缩进 GSOPoint3d headPoint = line[0][0]; GSOGeoPolyline3D newline = new GSOGeoPolyline3D(); GSOPoint3ds part = new GSOPoint3ds(); part.Add(headPoint); headPoint.X = headPoint.X - 0.0000000005; part.Add(headPoint); newline.AddPart(part); GSOGeoPolygon3D buffer = newline.CreateBuffer(valueAllowance, true, 5, true, false); GSOFeatures features = valveLayer.FindFeaturesInPolygon(buffer, false); if (features.Length > 0) { feature.HighLight = true; if (line.Style != null && line.Style is GSOPipeLineStyle3D) { GSOPipeLineStyle3D style = line.Style as GSOPipeLineStyle3D; style.HeadJointParam = new GSOPipeJointParam(); style.HeadJointParam.Extent = -valueIndented; } } //尾缩进 GSOPoint3d tailPoint = line[line.PartCount - 1][line[line.PartCount - 1].Count - 1]; newline = new GSOGeoPolyline3D(); part = new GSOPoint3ds(); part.Add(tailPoint); tailPoint.X = tailPoint.X - 0.0000000005; part.Add(tailPoint); newline.AddPart(part); buffer = newline.CreateBuffer(valueAllowance, true, 5, true, false); features = valveLayer.FindFeaturesInPolygon(buffer, false); if (features.Length > 0) { feature.HighLight = true; if (line.Style != null && line.Style is GSOPipeLineStyle3D) { GSOPipeLineStyle3D style = line.Style as GSOPipeLineStyle3D; style.TailJointParam = new GSOPipeJointParam(); style.TailJointParam.Extent = -valueIndented; } } } } } globeControl1.Globe.Refresh(); }
//去除管线对象中多余的节点 private void 检查管线节点ToolStripMenuItem_Click(object sender, EventArgs e) { GSOLayer layer = globeControl1.Globe.DestLayerFeatureAdd; if (layer != null && layer.ID == globeControl1.Globe.MemoryLayer.ID) { MessageBox.Show("请先设置目标图层!", "提示"); return; } FrmCheckPipelinePoint frm = new FrmCheckPipelinePoint(); if (frm.ShowDialog() == DialogResult.OK && layer.GetAllFeatures().Length > 0) { double distance = frm.pointDistance; for (int i = 0; i < layer.GetAllFeatures().Length; i++) { GSOFeature feature = layer.GetAt(i); if (feature != null && feature.Geometry != null && feature.Geometry.Type == EnumGeometryType.GeoPolyline3D) { GSOGeoPolyline3D line = feature.Geometry as GSOGeoPolyline3D; //获取管线中所有节点 GSOPoint3ds allPoint = new GSOPoint3ds(); for (int j = 0; j < line.PartCount; j++) { GSOPoint3ds points = line[j]; if (points != null) { for (int m = 0; m < points.Count; m++) { GSOPoint3d point = points[m]; allPoint.Add(point); } } } if (allPoint.Count > 2) { for (int j = 0; j < allPoint.Count - 1; j++) { GSOPoint3d point = allPoint[j]; GSOPoint3d point1 = allPoint[j + 1]; GSOPoint3ds points = new GSOPoint3ds(); points.Add(point); points.Add(point1); GSOGeoPolyline3D newLine = new GSOGeoPolyline3D(); newLine.AddPart(points); double length = newLine.GetSpaceLength(false, 6378137.0); if (length < distance) { if (j == allPoint.Count - 2) { allPoint.Remove(j); } else { allPoint.Remove(j + 1); } if (allPoint.Count < 3) { break; } j--; } } } line.Clear(); line.AddPart(allPoint); feature.Geometry = line; globeControl1.Refresh(); } } } MessageBox.Show("检查完毕!", "提示"); }
private void SetControlsByStyle(GSOStyle style) { if (m_Style != null) { extentSectionLineStyle3D = m_Style as GSOExtendSectionLineStyle3D; if (extentSectionLineStyle3D == null) { extentSectionLineStyle3D = new GSOExtendSectionLineStyle3D(); extentSectionLineStyle3D.LineColor = Color.Green; GSOPoint3ds points = new GSOPoint3ds(); points.Add(new GSOPoint3d(-0.5, 0.5, 0)); points.Add(new GSOPoint3d(-0.5, -0.5, 0)); points.Add(new GSOPoint3d(0.5, -0.5, 0)); points.Add(new GSOPoint3d(0.5, 0.5, 0)); extentSectionLineStyle3D.SetSectionPoints(points); RefreshGlobe(extentSectionLineStyle3D); } } else { extentSectionLineStyle3D = new GSOExtendSectionLineStyle3D(); extentSectionLineStyle3D.LineColor = Color.Green; GSOPoint3ds points = new GSOPoint3ds(); points.Add(new GSOPoint3d(-0.5, 0.5, 0)); points.Add(new GSOPoint3d(-0.5, -0.5, 0)); points.Add(new GSOPoint3d(0.5,- 0.5, 0)); points.Add(new GSOPoint3d(0.5, 0.5, 0)); extentSectionLineStyle3D.SetSectionPoints(points); RefreshGlobe(extentSectionLineStyle3D); } // 这句要写到前面,不然下面Checked的时候要检查 pictureBoxLineColor.BackColor = extentSectionLineStyle3D.LineColor; numericUpDownLineOpaque.Value = extentSectionLineStyle3D.LineColor.A; textBoxCornerSliceAngle.Text = extentSectionLineStyle3D.CornerSliceAngle.ToString(); GSOPoint3ds mpoints = extentSectionLineStyle3D.GetSectionPoints(); if (mpoints != null && mpoints.Count > 0) { for (int i = 0; i < mpoints.Count; i++) { GSOPoint3d point = mpoints[i]; if (point != null) { textBoxLineRadius.Text = (Math.Abs(point.X) * 2).ToString(); textBoxThickness.Text = (Math.Abs(point.Y) * 2).ToString(); break; } } } m_bInitialized = true; }
private void btnCreateModel_Click(object sender, EventArgs e) { if (comboBoxDataSourceList.SelectedItem == null) { MessageBox.Show("请选择一个目标数据源!", "提示"); return; } GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim()); if (ds == null) { MessageBox.Show("选择的目标数据源为空!", "提示"); return; } try { if (string.IsNullOrEmpty(textBoxNewLayerName.Text)) { MessageBox.Show("管线图层名称无效!", "提示"); return; } if (valiPipeData()) { GSODataset dataset = ds.GetDatasetByName(textBoxNewLayerName.Text.Trim()); GSOFeatureDataset newFeatureDataset; if (dataset != null) { DialogResult result = MessageBox.Show("管线图层名称在数据库中已存在!是否向该表追加", "提示", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { newFeatureDataset = dataset as GSOFeatureDataset; } else { return; } } else { newFeatureDataset = CreateDBFeatureDataset(textBoxNewLayerName.Text.Trim()); } if (newFeatureDataset == null) { MessageBox.Show("输入的图层名称不符合要求!", "提示"); return; } GSOLayer sourceLayer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim()); if (sourceLayer == null) { MessageBox.Show("选择的shp图层为空!", "提示"); return; } newFeatureDataset.Open(); GSOFeatures features = sourceLayer.GetAllFeatures(true); string message = ""; for (int j = 0; j < features.Length; j++) { GSOFeature f = features[j]; GSOFeature newFeature = newFeatureDataset.CreateFeature(); string maisheFangshi = f.GetFieldAsString(cmbMaiSheFangShi.SelectedItem.ToString()); string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString()); f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround; GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D; if (line == null) { message += "ID为" + f.ID + "的管线不是一个线对象\r\n"; continue; } double deep1 = f.GetFieldAsDouble(cmbFrom.SelectedItem.ToString()); double deep2 = f.GetFieldAsDouble(cmbTo.SelectedItem.ToString()); if (chkDeep.Checked) { deep1 = 0 - deep1; deep2 = 0 - deep2; } if (maisheFangshi == "直埋") { GSOPipeLineStyle3D style = new GSOPipeLineStyle3D(); style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor); double radius = 0; GSOFieldDefn field = (GSOFieldDefn)(f.GetFieldDefn(cmbRadius.SelectedItem.ToString())); if (field.Type == EnumFieldType.Text) { string temp = f.GetFieldAsString(cmbRadius.SelectedItem.ToString()); double outNum = 0; bool num = double.TryParse(temp, out outNum); if (num) { radius = outNum / 2000; } } else if (field.Type == EnumFieldType.Double) { radius = f.GetFieldAsDouble(cmbRadius.SelectedItem.ToString()) / 2000; // 探测数据的单位一般是毫米,需换算为米; 管径一般是 直径, 这个需要半径, 所有除以2000 } if (radius == 0) { message += "ID为" + f.ID + "的管线半径为0\r\n"; continue; } style.Radius = radius; style.Slice = int.Parse(txtSlice.Text); style.CornerSliceAngle = Convert.ToDouble(textBoxCornerSliceAngle.Text); if (cmbReference.SelectedIndex == 0) //管底 { deep1 = deep1 + radius * 2; deep2 = deep2 + radius * 2; } else if (cmbReference.SelectedIndex == 1) //管顶 { deep1 = deep1 - radius * 2; deep2 = deep2 - radius * 2; } for (int n = 0; n < line[0].Count; n++) { GSOPoint3d pt3d = line[0][n]; int pointcount = line[0].Count; double fenmu = Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2)); if (fenmu == 0) { pt3d.Z = deep1; } else { double radio = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / fenmu; pt3d.Z = deep1 + (deep2 - deep1) * radio; } line[0][n] = pt3d; } newFeature.Geometry = line; // f.Geometry; newFeature.Geometry.Style = style; } else if (maisheFangshi == "沟道") { GSOExtendSectionLineStyle3D style = new GSOExtendSectionLineStyle3D(); style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor); double width = 0; GSOFieldDefn field = (GSOFieldDefn)(f.GetFieldDefn(cmbWidth.SelectedItem.ToString())); if (field.Type == EnumFieldType.Text) { string temp = f.GetFieldAsString(cmbWidth.SelectedItem.ToString()); double outNum = 0; bool num = double.TryParse(temp, out outNum); if (num) { width = outNum; } } else if (field.Type == EnumFieldType.Double) { width = f.GetFieldAsDouble(cmbWidth.SelectedItem.ToString()); } double height = 0; field = (GSOFieldDefn)(f.GetFieldDefn(cmbHeight.SelectedItem.ToString())); if (field.Type == EnumFieldType.Text) { string temp = f.GetFieldAsString(cmbHeight.SelectedItem.ToString()); double outNum = 0; bool num = double.TryParse(temp, out outNum); if (num) { height = outNum; } } else if (field.Type == EnumFieldType.Double) { height = f.GetFieldAsDouble(cmbHeight.SelectedItem.ToString()); } if (width == 0 || height == 0) { message += "ID为" + f.ID + "的沟道的宽度或高度为0\r\n"; continue; } GSOPoint3ds sectionpts = new GSOPoint3ds(); sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0)); sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0)); sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0)); sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0)); style.SetSectionPoints(sectionpts); style.IsClosed = false; style.SetAnchorByAlign(EnumAlign.BottomCenter); for (int n = 0; n < line[0].Count; n++) { GSOPoint3d pt3d = line[0][n]; int pointcount = line[0].Count; double fenmu = Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2)); if (fenmu == 0) { pt3d.Z = deep1; } else { double radio = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / fenmu; pt3d.Z = deep1 + (deep2 - deep1) * radio; } line[0][n] = pt3d; } newFeature.Geometry = line; // f.Geometry; newFeature.Geometry.Style = style; } else { message += "ID为" + f.ID + "的对象的埋设方式既不是直埋,也不是沟道\r\n"; continue; // 即不是 直埋,又不是 沟道,那么忽略该记录 } for (int i = 0; i < f.GetFieldCount(); i++) { GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(f.GetFieldDefn(i)); if (!en_cns.ContainsKey(fielddef.Name)) { continue; } object fieldvalue = f.GetValue(fielddef.Name);// convertFieldValue(fielddef.Name, f.GetValue(fielddef.Name)); if (fieldvalue == null) { continue; } string fieldName = en_cns.ContainsKey(fielddef.Name) == true ? en_cns[fielddef.Name].ToString() : fielddef.Name; newFeature.SetValue(fieldName, fieldvalue); } newFeature.Name = eventid; newFeatureDataset.AddFeature(newFeature); } globeControl1.Refresh(); newFeatureDataset.Save(); newFeatureDataset.Close(); newFeatureDataset.Caption = newFeatureDataset.Name; globeControl1.Globe.Layers.Add(newFeatureDataset); string strMessage = "shp文件中共" + features.Length + "个对象,实际入库" + newFeatureDataset.GetAllFeatures().Length + "个对象!\r\n"; if (message == "") { MessageBox.Show(strMessage, "提示"); } else { FrmMessageShow frm = new FrmMessageShow(strMessage + message); frm.ShowDialog(); } this.Close(); } } catch (Exception ex) { Log.PublishTxt(ex); MessageBox.Show(ex.Message); } }
//创建管线要素 public void CreatePipeLine() { //创建线要素 GSOGeoPolyline3D line1 = new GSOGeoPolyline3D(); GSOPoint3ds points1 = new GSOPoint3ds(); GSOPoint3d point1 = new GSOPoint3d(120.27191, 31.9864637, 5); GSOPoint3d point2 = new GSOPoint3d(120.271, 31.9864637, 5); points1.Add(point1); points1.Add(point2); line1.AddPart(points1); //设置线高度模式为相对地表 line1.AltitudeMode = EnumAltitudeMode.RelativeToGround; //设置样式 GSOPipeLineStyle3D style = new GSOPipeLineStyle3D(); //管线颜色 style.LineColor = Color.Brown; //管线半径, 单位:米 style.Radius = 1; line1.Style = style; //相对地表抬高半径的距离 line1.MoveZ(style.Radius); //创建要素 _pipeFeature1 = new GSOFeature(); _pipeFeature1.Geometry = line1; //将要素添加到globe中并显示 _glbControl.Globe.MemoryLayer.AddFeature(_pipeFeature1); _pipeFeature2 = new GSOFeature(); GSOGeoPolyline3D line2 = new GSOGeoPolyline3D(); line2.AltitudeMode = EnumAltitudeMode.RelativeToGround; GSOPoint3ds points2 = new GSOPoint3ds(); GSOPoint3d point3 = new GSOPoint3d(120.27191, 31.986, 0); GSOPoint3d point4 = new GSOPoint3d(120.271, 31.986, 0); points2.Add(point3); points2.Add(point4); line2.AddPart(points2); line2.Style = style; line2.MoveZ(style.Radius); _pipeFeature2.Geometry = line2; _glbControl.Globe.MemoryLayer.AddFeature(_pipeFeature1); _glbControl.Globe.MemoryLayer.AddFeature(_pipeFeature2); _glbControl.Globe.FlyToFeature(_pipeFeature1); //添加辅助线 GSOSimpleLineStyle3D lineStyle = new GSOSimpleLineStyle3D() { LineColor = Color.Yellow, LineType = EnumLineType.Dot }; //水平线 GSOPoint3d pointtemp = new GSOPoint3d(point4.X, point4.Y, point2.Z + _radius); GSOGeoPolyline3D lineHor = new GSOGeoPolyline3D(); GSOPoint3ds pointsHor = new GSOPoint3ds(); pointsHor.Add(pointtemp); pointsHor.Add(new GSOPoint3d(point2.X, point2.Y, point2.Z + _radius)); lineHor.AddPart(pointsHor); lineHor.Style = lineStyle; lineHor.AltitudeMode = EnumAltitudeMode.RelativeToGround; double horLength = Math.Round(lineHor.GetSpaceLength(true, 6378137), 3); GSOFeature featureHorLine = new GSOFeature() { Geometry = lineHor }; featureHorLine.Label = CreateLabel(horLength.ToString()); this._glbControl.Globe.MemoryLayer.AddFeature(featureHorLine); //垂直线 GSOGeoPolyline3D lineVer = new GSOGeoPolyline3D(); GSOPoint3ds pointsVer = new GSOPoint3ds(); pointsVer.Add(pointtemp); pointsVer.Add(new GSOPoint3d(point4.X, point4.Y, point4.Z + _radius)); lineVer.AddPart(pointsVer); lineVer.Style = lineStyle; lineVer.AltitudeMode = EnumAltitudeMode.RelativeToGround; double verLength = Math.Round(Math.Abs(point2.Z - point4.Z)); GSOFeature featureVerLine = new GSOFeature() { Geometry = lineVer }; featureVerLine.Label = CreateLabel(verLength.ToString()); this._glbControl.Globe.MemoryLayer.AddFeature(featureVerLine); }
private void 管线间距分析ToolStripMenuItem_Click(object sender, EventArgs e) { if (globeControl1.Globe.SelObjectCount < 2) { MessageBox.Show("请选中至少两个管线!!"); return; } if (disFeature.ID != 0) { globeControl1.Globe.MemoryLayer.RemoveFeatureByID(disFeature.ID); } if (featureDis.ID != 0) { globeControl1.Globe.MemoryLayer.RemoveFeatureByID(featureDis.ID); } GSOLayer reslayer; globeControl1.Globe.GetSelectObject(0, out m_DisAnalysisFirstFeature, out reslayer); globeControl1.Globe.GetSelectObject(1, out m_DisAnalysisSecondFeature, out reslayer); if (m_DisAnalysisSecondFeature != null && m_DisAnalysisSecondFeature != null) { GSOGeoPolyline3D line1 = m_DisAnalysisFirstFeature.Geometry as GSOGeoPolyline3D; GSOGeoPolyline3D line2 = m_DisAnalysisSecondFeature.Geometry as GSOGeoPolyline3D; if (line1 == null || line2 == null) { MessageBox.Show("请选择管线!!"); return; } GSOPipeLineStyle3D pipeStyle1 = line1.Style as GSOPipeLineStyle3D; GSOPipeLineStyle3D pipeStyle2 = line2.Style as GSOPipeLineStyle3D; if (pipeStyle1 == null || pipeStyle2 == null) { MessageBox.Show("请选择管线!!"); return; } GSOPoint3d pntIntersect1; GSOPoint3d pntIntersect2; double dHonLen; double dVerLen; double dNoIntersectStartRatio = 0; // 计算两条线的距离和交点,若果失败返回-1 // 若在同一直线上,并且有交点,返回0 // 若不在同一平面,返回最近两点的距离,并且计算最近两点 double dDist = globeControl1.Globe.Analysis3D.ComputeTwoGeoPolylineDistance(line1, line2, out pntIntersect1, out pntIntersect2, out dHonLen, out dVerLen, false, false, dNoIntersectStartRatio); if (dDist > -1) { if (dDist == 0) { MessageBox.Show("管线在同一水平面,距离为0"); return; } else { dDist = dDist - pipeStyle1.Radius - pipeStyle2.Radius; GSOGeoPolyline3D disline = new GSOGeoPolyline3D(); GSOPoint3ds point3ds = new GSOPoint3ds(); point3ds.Add(pntIntersect1); point3ds.Add(pntIntersect2); disline.AddPart(point3ds); GSOSimpleLineStyle3D style = new GSOSimpleLineStyle3D(); //创建线的风格 //设置透明度及颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255 style.LineColor = Color.GreenYellow; style.LineWidth = 3; //设置线的宽度为3 style.VertexVisible = true; //显示线的节点 disline.Style = style; //把风格添加到线上 disline.AltitudeMode = EnumAltitudeMode.Absolute; disFeature.Geometry = disline; GSOGeoMarker markerDis = new GSOGeoMarker(); markerDis.X = pntIntersect1.X; markerDis.Y = pntIntersect1.Y; markerDis.Z = (pntIntersect1.Z + pntIntersect2.Z) / 2; markerDis.Text = dDist.ToString().Substring(0, dDist.ToString().IndexOf(".") + 3) + "米"; markerDis.AltitudeMode = EnumAltitudeMode.Absolute; GSOMarkerStyle3D styleMarker = new GSOMarkerStyle3D(); GSOTextStyle styleText = new GSOTextStyle(); styleText.IsSizeFixed = true; styleText.ForeColor = Color.White; styleText.FontSize = 20; styleMarker.TextStyle = styleText; markerDis.Style = styleMarker; featureDis.Geometry = markerDis; layerTemp = globeControl1.Globe.Layers.Add(Application.StartupPath + "\\tempLgdData.lgd"); layerTemp.AddFeature(featureDis); layerTemp.AddFeature(disFeature); globeControl1.Refresh(); } } else { MessageBox.Show("没有交点!!"); return; } } }
private void _glbControl_TrackPolygonEndEvent(object sender, TrackPolygonEndEventArgs e) { //判断绘制的多边形是否在倾斜摄影图层上 GSOPoint3ds polygonPots = e.Polygon[0]; if (!lfpLayer.LatLonBounds.Left.Equals(0.0) && !lfpLayer.LatLonBounds.Bottom.Equals(0.0) && !lfpLayer.LatLonBounds.Top.Equals(0.0) && !lfpLayer.LatLonBounds.Right.Equals(0.0)) { for (int i = 0; i < polygonPots.Count; i++) { if (!lfpLayer.LatLonBounds.Contains(polygonPots[i].X, polygonPots[i].Y)) { MessageBox.Show("请将多边形画于倾斜摄影图层上。"); //清除上一个绘制的分析多边形 _glbControl.Globe.ClearLastTrackPolygon(); return; } } } //压平分析 if (_isPressOn) { //将倾斜摄影图层转换为GSOPageLODFeatureLayer分析图层 GSOPageLODFeatureLayer layer2 = lfpLayer as GSOPageLODFeatureLayer; //压平面 GSOGeoPolygon3D poly1 = e.Polygon; //加入到压平面的List为模型替换做准备 _trackPressPolygon.Add(e.Polygon); //高度模式为绝对高度 poly1.AltitudeMode = EnumAltitudeMode.Absolute; if (layer2 != null) { //添加压平面 layer2.AddFlattenPolygon3D(poly1, ""); //保存压平面 layer2.Save(); } _isPressOn = false; } //填挖方分析 else { //挖方量 double m_dDigVolume = 0; //填方量 double m_dFillVolume = 0; //分析总面积 double m_dTotalArea = 0; //挖方面积(废除) double m_dDigArea = 0; //填方面积(废除) double m_dFillArea = 0; double dAlt = 50; //挖填方高度 double pointDistance = 1; //采样精度,单位:米 //将平面坐标转换为经纬度坐标,使用默认投影ID为0 GSOPoint2d point2D = GSOProjectManager.Inverse(new GSOPoint2d(pointDistance, pointDistance), 0); double dDSampleGap = point2D.X;//重采样的点的距离,单位是:经纬度 //挖方分析线 GSOGeoPolyline3D lineDig = new GSOGeoPolyline3D(); //填方分析线 GSOGeoPolyline3D lineFill = new GSOGeoPolyline3D(); //填挖方分析 bool analysisResult = _glbControl.Globe.Analysis3D.DigFillAnalyseWithModel(e.Polygon, dAlt, out m_dDigVolume, out m_dFillVolume, out m_dDigArea, out m_dFillArea, out m_dTotalArea, dDSampleGap, lineDig, lineFill); //分析成功 if (analysisResult) { StringBuilder str = new StringBuilder(); str.AppendLine("分析高度:" + dAlt.ToString()); str.AppendLine("分析精度:" + pointDistance.ToString() + "米"); str.AppendLine("挖方量:" + m_dDigVolume.ToString() + "立方米"); str.AppendLine("填方量:" + m_dFillVolume.ToString() + "立方米"); str.AppendLine("总面积:" + m_dTotalArea.ToString() + "平方米"); MessageBox.Show(str.ToString()); } else { MessageBox.Show("分析失败。"); } } _glbControl.Refresh(); _glbControl.Globe.Action = EnumAction3D.ActionNull; }
private void btnCreateModel_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtModelLayer.Text)) { MessageBox.Show("管线模型文件路径无效!", "提示"); return; } if (File.Exists(txtModelLayer.Text)) { MessageBox.Show("管线模型文件已存在!", "提示"); return; } GSOLayer sourceLayer = ctl.Globe.Layers[cmbLayer.SelectedIndex]; GSOLayer layer = ctl.Globe.Layers.Add(txtModelLayer.Text); lgdFilePath = txtModelLayer.Text; if (layer != null) { GSOFeatures features = sourceLayer.GetAllFeatures(); string message = ""; for (int j = 0; j < features.Length; j++) { GSOFeature f = features[j]; GSOFeature newFeature = new GSOFeature(); GSOExtendSectionLineStyle3D style = new GSOExtendSectionLineStyle3D(); style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor); double width = 0; GSOFieldDefn field = (GSOFieldDefn)(f.GetFieldDefn(cmbWidth.SelectedItem.ToString())); if (field.Type == EnumFieldType.Text) { string temp = f.GetFieldAsString(cmbWidth.SelectedItem.ToString()); double outNum = 0; bool num = double.TryParse(temp, out outNum); if (num) width = outNum; } else if (field.Type == EnumFieldType.Double) width = f.GetFieldAsDouble(cmbWidth.SelectedItem.ToString()); double height = 0; field = (GSOFieldDefn)(f.GetFieldDefn(cmbHeight.SelectedItem.ToString())); if (field.Type == EnumFieldType.Text) { string temp = f.GetFieldAsString(cmbHeight.SelectedItem.ToString()); double outNum = 0; bool num = double.TryParse(temp, out outNum); if (num) height = outNum; } else if (field.Type == EnumFieldType.Double) height = f.GetFieldAsDouble(cmbHeight.SelectedItem.ToString()); string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString()); if (width == 0 || height == 0) { message += "ID为" + f.ID + "的对象的沟宽或者沟高字段的值为0 \n"; continue; } GSOPoint3ds sectionpts = new GSOPoint3ds(); sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0)); sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0)); sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0)); sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0)); style.SetSectionPoints(sectionpts); style.IsClosed = false; style.SetAnchorByAlign(EnumAlign.BottomCenter); f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround; GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D; if (line == null) { message += "ID为" + f.ID + "的对象不是线对象 \n"; continue; } double deep1 = f.GetFieldAsDouble(cmbFrom.SelectedItem.ToString()); double deep2 = f.GetFieldAsDouble(cmbTo.SelectedItem.ToString()); if (chkDeep.Checked) { deep1 = 0 - deep1; deep2 = 0 - deep2; } for (int n = 0; n < line[0].Count; n++) { GSOPoint3d pt3d = line[0][n]; int pointcount = line[0].Count; double radio = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2)); pt3d.Z = deep1 + (deep2 - deep1) * radio; line[0][n] = pt3d; } newFeature.Geometry = line; // f.Geometry; newFeature.Geometry.Style = style; newFeature.Name = eventid; layer.AddFeature(newFeature); } ctl.Refresh(); layer.Save(); ctl.Globe.Layers.Remove(layer); string strMessage = "shp文件中共" + features.Length + "个对象,实际生成" + layer.GetAllFeatures().Length + "个对象!\n"; MessageBox.Show(strMessage + message, "提示"); this.Close(); } } catch (Exception ex) { Log.PublishTxt(ex); MessageBox.Show(ex.Message); } }
private void buttonAnalyse_Click(object sender, EventArgs e) { if(m_geopolyline!=null && m_globe!=null) { checkBoxSameScale.Enabled = true; checkBoxXmin.Enabled = true; checkBoxYMin.Enabled = true; GSOPoint3d pntMax, pntMin, pntStart, pntEnd; GSOPoint3ds pnt3ds; double dLineLength; m_globe.Analysis3D.ProfileAnalyse(m_geopolyline, 100, out pnt3ds, out dLineLength, out pntMax, out pntMin, out pntStart, out pntEnd); m_pnt3ds = pnt3ds; m_pntMax = pntMax; m_pntMin = pntMin; m_pntStart = pntStart; m_pntEnd = pntEnd; m_dXTotalLength = dLineLength; m_dSphereLength = m_geopolyline.GetSphereLength(6378137.0); m_dSpaceLength = m_geopolyline.GetSpaceLength(false, 6378137.0); m_dGroundLength = m_globe.Analysis3D.GetGroundLength(m_geopolyline, false, 0); SetLableText(); DrawCurveGraph(); } }
private void btnCreateModel_Click(object sender, EventArgs e) { if (comboBoxDataSourceList.SelectedItem == null) { MessageBox.Show("请选择一个目标数据源!", "提示"); return; } GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim()); if (ds == null) { MessageBox.Show("选择的目标数据源为空!", "提示"); return; } try { if (string.IsNullOrEmpty(textBoxNewLayerName.Text)) { MessageBox.Show("管线图层名称无效!", "提示"); return; } if (valiPipeData()) { GSODataset dataset = ds.GetDatasetByName(textBoxNewLayerName.Text.Trim()); GSOFeatureDataset newFeatureDataset; if (dataset != null) { DialogResult result = MessageBox.Show("管线图层名称在数据库中已存在!是否向该表追加", "提示", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { newFeatureDataset = dataset as GSOFeatureDataset; } else { return; } } else { newFeatureDataset = CreateDBFeatureDataset(textBoxNewLayerName.Text.Trim()); } if (newFeatureDataset == null) { MessageBox.Show("输入的图层名称不符合要求!", "提示"); return; } GSOLayer sourceLayer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim()); if (sourceLayer == null) { MessageBox.Show("选择的shp图层为空!", "提示"); return; } newFeatureDataset.Open(); GSOFeatures features = sourceLayer.GetAllFeatures(true); string message = ""; for (int j = 0; j < features.Length; j++) { GSOFeature f = features[j]; GSOFeature newFeature = newFeatureDataset.CreateFeature(); string maisheFangshi = f.GetFieldAsString(cmbMaiSheFangShi.SelectedItem.ToString()); string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString()); f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround; GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D; if (line == null) { message += "ID为" + f.ID + "的管线不是一个线对象\r\n"; continue; } double deep1 = f.GetFieldAsDouble(cmbFrom.SelectedItem.ToString()); double deep2 = f.GetFieldAsDouble(cmbTo.SelectedItem.ToString()); if (chkDeep.Checked) { deep1 = 0 - deep1; deep2 = 0 - deep2; } if (maisheFangshi == "直埋") { GSOPipeLineStyle3D style = new GSOPipeLineStyle3D(); style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor); double radius = 0; GSOFieldDefn field = (GSOFieldDefn)(f.GetFieldDefn(cmbRadius.SelectedItem.ToString())); if (field.Type == EnumFieldType.Text) { string temp = f.GetFieldAsString(cmbRadius.SelectedItem.ToString()); double outNum = 0; bool num = double.TryParse(temp, out outNum); if (num) radius = outNum / 2000; } else if (field.Type == EnumFieldType.Double) radius = f.GetFieldAsDouble(cmbRadius.SelectedItem.ToString()) / 2000; // 探测数据的单位一般是毫米,需换算为米; 管径一般是 直径, 这个需要半径, 所有除以2000 if (radius == 0) { message += "ID为" + f.ID + "的管线半径为0\r\n"; continue; } style.Radius = radius; style.Slice = int.Parse(txtSlice.Text); style.CornerSliceAngle = Convert.ToDouble(textBoxCornerSliceAngle.Text); if (cmbReference.SelectedIndex == 0) //管底 { deep1 = deep1 + radius * 2; deep2 = deep2 + radius * 2; } else if (cmbReference.SelectedIndex == 1) //管顶 { deep1 = deep1 - radius * 2; deep2 = deep2 - radius * 2; } for (int n = 0; n < line[0].Count; n++) { GSOPoint3d pt3d = line[0][n]; int pointcount = line[0].Count; double fenmu = Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2)); if (fenmu == 0) pt3d.Z = deep1; else { double radio = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / fenmu; pt3d.Z = deep1 + (deep2 - deep1) * radio; } line[0][n] = pt3d; } newFeature.Geometry = line; // f.Geometry; newFeature.Geometry.Style = style; } else if (maisheFangshi == "沟道") { GSOExtendSectionLineStyle3D style = new GSOExtendSectionLineStyle3D(); style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor); double width = 0; GSOFieldDefn field = (GSOFieldDefn)(f.GetFieldDefn(cmbWidth.SelectedItem.ToString())); if (field.Type == EnumFieldType.Text) { string temp = f.GetFieldAsString(cmbWidth.SelectedItem.ToString()); double outNum = 0; bool num = double.TryParse(temp, out outNum); if (num) width = outNum; } else if (field.Type == EnumFieldType.Double) width = f.GetFieldAsDouble(cmbWidth.SelectedItem.ToString()); double height = 0; field = (GSOFieldDefn)(f.GetFieldDefn(cmbHeight.SelectedItem.ToString())); if (field.Type == EnumFieldType.Text) { string temp = f.GetFieldAsString(cmbHeight.SelectedItem.ToString()); double outNum = 0; bool num = double.TryParse(temp, out outNum); if (num) height = outNum; } else if (field.Type == EnumFieldType.Double) height = f.GetFieldAsDouble(cmbHeight.SelectedItem.ToString()); if (width == 0 || height == 0) { message += "ID为" + f.ID + "的沟道的宽度或高度为0\r\n"; continue; } GSOPoint3ds sectionpts = new GSOPoint3ds(); sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0)); sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0)); sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0)); sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0)); style.SetSectionPoints(sectionpts); style.IsClosed = false; style.SetAnchorByAlign(EnumAlign.BottomCenter); for (int n = 0; n < line[0].Count; n++) { GSOPoint3d pt3d = line[0][n]; int pointcount = line[0].Count; double fenmu = Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2)); if (fenmu == 0) pt3d.Z = deep1; else { double radio = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / fenmu; pt3d.Z = deep1 + (deep2 - deep1) * radio; } line[0][n] = pt3d; } newFeature.Geometry = line; // f.Geometry; newFeature.Geometry.Style = style; } else { message += "ID为" + f.ID + "的对象的埋设方式既不是直埋,也不是沟道\r\n"; continue; // 即不是 直埋,又不是 沟道,那么忽略该记录 } for (int i = 0; i < f.GetFieldCount(); i++) { GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(f.GetFieldDefn(i)); if (!en_cns.ContainsKey(fielddef.Name)) continue; object fieldvalue = f.GetValue(fielddef.Name);// convertFieldValue(fielddef.Name, f.GetValue(fielddef.Name)); if (fieldvalue == null) continue; string fieldName = en_cns.ContainsKey(fielddef.Name) == true ? en_cns[fielddef.Name].ToString() : fielddef.Name; newFeature.SetValue(fieldName, fieldvalue); } newFeature.Name = eventid; newFeatureDataset.AddFeature(newFeature); } globeControl1.Refresh(); newFeatureDataset.Save(); newFeatureDataset.Close(); newFeatureDataset.Caption = newFeatureDataset.Name; globeControl1.Globe.Layers.Add(newFeatureDataset); string strMessage = "shp文件中共" + features.Length + "个对象,实际入库" + newFeatureDataset.GetAllFeatures().Length + "个对象!\r\n"; if (message == "") { MessageBox.Show(strMessage, "提示"); } else { FrmMessageShow frm = new FrmMessageShow(strMessage + message); frm.ShowDialog(); } this.Close(); } } catch (Exception ex) { Log.PublishTxt(ex); MessageBox.Show(ex.Message); } }
private GSOPoint3ds getAllPointInPipeline(GSOGeoPolyline3D pipeline) { GSOPoint3ds points = new GSOPoint3ds(); if (pipeline != null) { for (int i = 0; i < pipeline.PartCount; i++) { GSOPoint3ds pnts = pipeline[i]; for (int j = 0; j < pnts.Count; j++) { GSOPoint3d pt = pnts[j]; points.Add(pt); } } } return points; }
private void button2_Click(object sender, EventArgs e) { double dMinLon = 0, dMaxLon = 0, dMinLat = 0, dMaxLat = 0; string strLayerPath = saveFileDialog1.FileName; string path = Application.StartupPath + "\\Resource\\image\\DefaultIcon.png"; if (string.IsNullOrEmpty(saveFileDialog1.FileName)) { MessageBox.Show("请选择存储目录"); return; } globeControl1.Globe.MemoryLayer.SaveAs(strLayerPath); layerTemp = globeControl1.Globe.Layers.Add(strLayerPath); layerTemp.RemoveAllFeature(); GSOGeoPolyline3D polyLine = new GSOGeoPolyline3D(); GSOPoint3ds pois = new GSOPoint3ds(); for (int i = 0; i < listView1.Items.Count; i++) { ListViewItem item = listView1.Items[i]; double lon, lat; if (!double.TryParse(item.SubItems[3].Text.ToString() == "" ? "0" : item.SubItems[3].Text.ToString(), out lon)) { MessageBox.Show("经度参数不合法"); return; } if (!double.TryParse(item.SubItems[4].Text.ToString() == "" ? "0" : item.SubItems[4].Text.ToString(), out lat)) { MessageBox.Show("纬度参数不合法"); return; } if (i == 0) { dMaxLon = lon; dMinLon = lon; dMinLat = lat; dMaxLat = lat; } GSOPoint3d node = new GSOPoint3d(lon, lat, 0); pois.Add(node); string strDescriptionPrefix = "<![CDATA[<!-- <BALLOON><CONTENT_CX>800</CONTENT_CX><CONTENT_CY>600</CONTENT_CY>" + "<CONTENT_TYPE>link</CONTENT_TYPE><SHOW_MODE>balloonex</SHOW_MODE>-->"; string strDescription = strDescriptionPrefix + "file:\\\\" + Application.StartupPath + "\\Resource\\Page\\pic_route.html"; strDescription += "?URL=" + item.SubItems[5].Text.ToString(); //strDescription += "]]>"; AddMarker(item.SubItems[1].Text.ToString(), lon, lat, path, strDescription, layerTemp); if (lon < dMinLon) { dMinLon = lon; } else if (lon > dMaxLon) { dMaxLon = lon; } if (lat < dMinLat) { dMinLat = lat; } else if (lat > dMaxLat) { dMaxLat = lat; } } if (layerTemp == null) { MessageBox.Show("没有生成轨迹的数据"); return; } polyLine.AddPart(pois); GSOFeature feature = new GSOFeature(); feature.Geometry = polyLine; layerTemp.AddFeature(feature);//添加线 layerTemp.SaveAs(strLayerPath); globeControl1.Globe.FlyToFeature(feature); }