Example #1
0
        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 dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }

            GSOFeatureLayer pFeatureLayer = geoLayer as GSOFeatureLayer;

            if (pFeatureLayer != null)
            {
                GSOFeature featureFlyTo = dataGridView1.Rows[e.RowIndex].Tag as GSOFeature;
                if (featureFlyTo == null || globeControl1 == null)
                {
                    return;
                }

                if (featureFlyTo.Geometry != null && featureFlyTo.Geometry.Type == EnumGeometryType.GeoPolyline3D)
                {
                    GSOGeoPolyline3D line     = featureFlyTo.Geometry as GSOGeoPolyline3D;
                    double           length   = line.GetSpaceLength(true, 6378137);
                    GSOGeoPolyline3D lineLine = line.GetSegment(0, length / 2);
                    GSOPoint3d       point3d  = lineLine[lineLine.PartCount - 1][lineLine[lineLine.PartCount - 1].Count - 1];

                    globeControl1.Globe.FlyToPosition(point3d, EnumAltitudeMode.Absolute, 0, 45, 5);
                }
                else
                {
                    globeControl1.Globe.FlyToFeature(featureFlyTo, 0, 45, 3);
                }
                globeControl1.Globe.Refresh();
            }
        }
Example #3
0
        /// <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)));
        }
Example #4
0
        /// <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);
                }
            }
        }
Example #5
0
        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);  //把几何要素添加到内存图层中
        }
Example #6
0
        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);
            }
        }
Example #7
0
        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 buttonOK_Click(object sender, EventArgs e)
        {
            string layerPath = textBoxLayerPath.Text.Trim();

            if (layerPath == "")
            {
                MessageBox.Show("请选择目标文件!", "提示");
                return;
            }
            string featureMinLength = textBoxFeatureMinLength.Text.Trim();
            double minLength        = 0;

            if (!double.TryParse(featureMinLength, out minLength))
            {
                MessageBox.Show("请输入正确的最小长度值!", "提示");
                return;
            }
            string featureMaxLength = textBoxFeatureMaxLength.Text.Trim();
            double maxLength        = 0;

            if (!double.TryParse(featureMaxLength, out maxLength))
            {
                MessageBox.Show("请输入正确的最大长度值!", "提示");
                return;
            }
            string featureCount = textBoxFeatureCount.Text.Trim();
            int    count        = 0;

            if (checkBoxFeatureCount.Checked)
            {
                if (!int.TryParse(featureCount, out count))
                {
                    MessageBox.Show("请输入正确的要素个数值!", "提示");
                    return;
                }
            }

            GSOLayer layer = globeControl1.Globe.Layers.Add(layerPath);

            if (layer != null)
            {
                do
                {
                    for (int i = layer.GetAllFeatures().Length - 1; i >= 0; i--)
                    {
                        GSOFeature feature = layer.GetAt(i);
                        if (feature != null && feature.Geometry != null && feature.Geometry.Type == EnumGeometryType.GeoPolyline3D)
                        {
                            GSOGeoPolyline3D line   = feature.Geometry as GSOGeoPolyline3D;
                            double           length = line.GetSpaceLength(false, 6378137.0);
                            if (length >= minLength && length <= maxLength)
                            {
                                feature.Delete();
                            }
                        }
                        //else
                        //{
                        //    feature.Delete();
                        //}
                    }
                    maxLength++;
                }while (checkBoxFeatureCount.Checked && layer.GetAllFeatures().Length > 30000);
                layer.SaveAs(Path.GetDirectoryName(textBoxLayerPath.Text.Trim()) + "/" + layer.Caption + "-处理后" + Path.GetExtension(textBoxLayerPath.Text.Trim()));
                MessageBox.Show("删除成功!", "提示");
            }
        }
        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;
            }
            //判断是数字或者存在特殊字符串
            string SuiD = textBoxNewLayerName.Text.ToString().Trim();
            Regex  reg  = new Regex("^[0-9]+$");//判断是不是数据,要不是就表示没有选择。则从隐藏域里读出来
            Match  ma   = reg.Match(SuiD);

            if (ma.Success)
            {
                MessageBox.Show("管线图层名称不能全部为数字!", "警告");
                return;
            }

            try
            {
                // if (valiPipeData())
                {
                    if (string.IsNullOrEmpty(textBoxNewLayerName.Text))
                    {
                        MessageBox.Show("管线图层名称无效!", "提示");
                        return;
                    }

                    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)
                    {
                        return;
                    }
                    GSOLayer sourceLayer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());
                    newFeatureDataset.Open();
                    GSOFeatures features = sourceLayer.GetAllFeatures(true);
                    string      message  = "";
                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOGeoPolyline3D lineeee = f.Geometry as GSOGeoPolyline3D;
                        if (lineeee == null)
                        {
                            message += "ID为" + f.ID + "的对象不是一个线对象\n";
                            continue;
                        }
                        double length = lineeee.GetSpaceLength(true, 6378137);
                        if (length == 0)
                        {
                            message += "ID为" + f.ID + "的管线长度为0\n";
                            continue;
                        }

                        GSOFeature newFeature = newFeatureDataset.CreateFeature();

                        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.INT32 || field.Type == EnumFieldType.Double)
                        {
                            radius = f.GetFieldAsDouble(cmbRadius.SelectedItem.ToString()) / 2000;  // 探测数据的单位一般是毫米,需换算为米; 管径一般是 直径, 这个需要半径, 所有除以2000
                        }
                        string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString());

                        if (radius == 0)
                        {
                            message += "ID为" + f.ID + "的管线半径为0\n";
                            continue;
                        }

                        style.Radius           = radius;
                        style.Slice            = int.Parse(txtSlice.Text);
                        style.CornerSliceAngle = Convert.ToDouble(textBoxCornerSliceAngle.Text);

                        f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                        GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D;
                        if (line == null)
                        {
                            return;
                        }

                        double deep1 = f.GetFieldAsDouble(cmbFrom.SelectedItem.ToString());
                        double deep2 = f.GetFieldAsDouble(cmbTo.SelectedItem.ToString());

                        if (chkDeep.Checked)
                        {
                            deep1 = 0 - deep1;
                            deep2 = 0 - deep2;
                        }

                        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;
                            }

                            if (double.IsInfinity(pt3d.Z))
                            {
                                pt3d.Z = deep2;
                            }
                            line[0][n] = pt3d;
                        }

                        newFeature.Geometry       = line; // f.Geometry;
                        newFeature.Geometry.Style = style;
                        newFeature.Name           = eventid;

                        for (int i = 0; i < f.GetFieldCount(); i++)
                        {
                            GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(f.GetFieldDefn(i));
                            if (fielddef == null)
                            {
                                continue;
                            }
                            if (!en_cns.Contains(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);
                        }

                        newFeatureDataset.AddFeature(newFeature);
                    }
                    newFeatureDataset.Save();
                    newFeatureDataset.Caption = newFeatureDataset.Name;
                    globeControl1.Globe.Layers.Add(newFeatureDataset);
                    globeControl1.Refresh();

                    string strMessage = "shp文件中共" + features.Length + "个对象,实际入库" + newFeatureDataset.GetAllFeatures().Length + "个对象!\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);
            }
        }
Example #10
0
        //创建管线要素
        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 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();
        }
Example #12
0
 //去除管线对象中多余的节点
 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("检查完毕!", "提示");
 }