Example #1
1
        public void DrawPipeLine(Graphics g,GSOPipeLineStyle3D pipeLineStyle)
        {
            Pen newPen = new Pen(pipeLineStyle.LineColor, 1.0f);

            int nEllipseHeight = (int)(Height * 0.3);
            int nEllipseWidth = nEllipseHeight/2;
            int nStartX = (int)(Width*0.1);

            int nHalfHeight=Height/2;

            int nBodyStartX=nStartX+nEllipseWidth/2;

            Rectangle rcEllipse = new Rectangle(nStartX, nHalfHeight - nEllipseHeight / 2, nEllipseWidth, nEllipseHeight);
            Rectangle rcTailEllipse = new Rectangle(this.Width - nStartX - nEllipseWidth, nHalfHeight - nEllipseHeight / 2, nEllipseWidth, nEllipseHeight);
            Rectangle rcFill = new Rectangle(nBodyStartX, rcEllipse.Top, Width - 2*nBodyStartX+nEllipseWidth/2, nEllipseHeight);

            Color FColor = pipeLineStyle.LineColor;

            Color TColor = Color.FromArgb(255, 255, 255);

            Brush b = new LinearGradientBrush(this.ClientRectangle, FColor, TColor, LinearGradientMode.BackwardDiagonal);

            g.FillRectangle(b, rcFill);

            g.DrawEllipse(newPen, rcEllipse);

            g.DrawEllipse(newPen, rcTailEllipse);

            g.DrawLine(newPen, nBodyStartX, rcEllipse.Top, Width - nBodyStartX, rcEllipse.Top);
            g.DrawLine(newPen, nBodyStartX, rcEllipse.Bottom, Width - nBodyStartX, rcEllipse.Bottom);
        }
Example #2
0
        private void btnExportCAD_Click(object sender, EventArgs e)
        {
            globeControl1.Globe.MemoryLayer.RemoveAllFeature();
            int id = GeoScene.Data.GSOProjectManager.AddProject("+proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=555484.8092 +y_0=-4114948.631 +ellps=krass +units=m +no_defs");

            for (int i = 0; i < listPoint.Count; i++)
            {
                GSOPoint3d geoPoint = (GSOPoint3d)listPoint[i];
                GSOFeature feature  = listFeat[i] as GSOFeature;
                if (feature != null)
                {
                    if (feature.Geometry.Type == EnumGeometryType.GeoPolyline3D)
                    {
                        GSOPipeLineStyle3D style = feature.Geometry.Style as GSOPipeLineStyle3D;
                        double             r     = style.Radius;
                        //ExportCAD(double.Parse(sortIndex[i, 0].ToString()), geoPoint.Z, r);
                        Export(geoPoint, r);
                    }
                }
            }
            GSOLayer layer = globeControl1.Globe.MemoryLayer;

            layer.Dataset.ImportProjectionRefFromProj4("+proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=555484.8092 +y_0=-4114948.631 +ellps=krass +units=m +no_defs");
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = "*.dxf|*.dxf";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                layer.SaveAs(dlg.FileName);
                globeControl1.Globe.MemoryLayer.RemoveAllFeature();
                MessageBox.Show("导出CAD完成!", "提示");
            }
        }
Example #3
0
        //加载shp文件并显示管线
        private void btn_LoadLayer_Click(object sender, EventArgs e)
        {
            if (_layerAdded)
            {
                return;
            }
            _shpLayer          = _glbControl.Globe.Layers.Add(_testShpPath);
            _shpLayer.Editable = true;
            //设置样式
            GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();

            style.LineColor = Color.Green;
            //管线半径
            style.Radius = _radius;
            //获得默认图层的要素
            var features = _shpLayer.GetAllFeatures();

            //遍历要素
            for (int i = 0; i < features.Length; i++)
            {
                GSOGeoPolyline3D geometry = features[i].Geometry as GSOGeoPolyline3D;
                geometry.Style = style;
                //将高度抬高到管径高度
                geometry.MoveZ(style.Radius);
                //重要,要将高度模式设置成相对地表,如果为依附地面则无渲染效果
                geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;
            }
            _glbControl.Refresh();
            FlyToLayer(_shpLayer);
        }
Example #4
0
 private void RefreshGlobe(GSOPipeLineStyle3D pipeLineStyle3D)
 {
     mfeature.Geometry.Style        = pipeLineStyle3D;
     mfeature.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;
     if (m_GlobeControl != null)
     {
         m_GlobeControl.Globe.Refresh();
     }
 }
 public FrmDecjointPipeline(GSOGlobe globe, GSOPipeLineStyle3D style)
 {
     InitializeComponent();
     m_globe = globe;
     m_style = style;
     if (style != null)
     {
         m_oldStyle = (GSOPipeLineStyle3D)style.Clone();
     }
     m_bInitialized = false;
 }
Example #6
0
 public FrmDecjointPipeline(GSOGlobe globe, GSOPipeLineStyle3D style)
 {
     InitializeComponent();
     m_globe = globe;
     m_style = style;
     if (style!=null)
     {
         m_oldStyle = (GSOPipeLineStyle3D)style.Clone();
     }
     m_bInitialized = false;
 }
Example #7
0
        void CheckChangeTailJoint()
        {
            GSOPipeLineStyle3D geoStyle3dOld  = m_OldStyle as GSOPipeLineStyle3D;
            GSOPipeJointParam  tailJointParam = null;
            float fValue = 0;

            if (pipeLineStyle3D != null)
            {
                // 先恢复,再设置
                if (!m_bInitialized || pipeLineStyle3D == null || geoStyle3dOld == null)
                {
                    if (tailJointParam == null)
                    {
                        tailJointParam = new GSOPipeJointParam();
                    }
                    if (float.TryParse(tBoxTailDecValue.Text, out fValue))
                    {
                        if (!(fValue < 0))
                        {
                            tailJointParam.Extent          = -fValue;
                            pipeLineStyle3D.TailJointParam = tailJointParam;
                        }
                    }
                    return;
                }

                // 先恢复一下
                if (geoStyle3dOld.TailJointParam == null)
                {
                    pipeLineStyle3D.TailJointParam = null;
                }
                else
                {
                    pipeLineStyle3D.TailJointParam = geoStyle3dOld.TailJointParam;
                }
                tailJointParam = pipeLineStyle3D.TailJointParam;

                if (tailJointParam == null)
                {
                    tailJointParam = new GSOPipeJointParam();
                }
                if (float.TryParse(tBoxTailDecValue.Text, out fValue))
                {
                    if (!(fValue < 0))
                    {
                        tailJointParam.Extent          = -fValue;
                        pipeLineStyle3D.TailJointParam = tailJointParam;
                    }
                }
            }
        }
Example #8
0
        private void listViewStyle_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (listViewStyle.SelectedIndices.Count > 0)
            {
                tabControl1.TabPages.Clear();
                GSOStyle         oldStyle   = null;
                EnumAltitudeMode oldAltMode = m_Geometry.AltitudeMode;
                // 先复制一个原来的哦,以便在对话框取消的时候恢复
                if (m_Geometry.Style != null)
                {
                    oldStyle = m_Geometry.Style.Clone();
                }
                if (listViewStyle.SelectedIndices[0] == 0)
                {
                    GSOSimpleLineStyle3D simpleLineStyle = m_Geometry.Style as GSOSimpleLineStyle3D;
                    if (simpleLineStyle == null)
                    {
                        m_Geometry.Style = new GSOSimpleLineStyle3D();
                    }

                    FrmSetLineStyle dlg = new FrmSetLineStyle(m_Geometry.Style, mfeature, mlayer, m_GlobeControl);
                    if (dlg.ShowDialog(this) == DialogResult.Cancel)
                    {
                        m_Geometry.Style = oldStyle;
                    }
                }
                else if (listViewStyle.SelectedIndices[0] == 1)
                {
                    GSOPipeLineStyle3D pipeLineStyle = m_Geometry.Style as GSOPipeLineStyle3D;

                    // 管线暂不支持依地模式
                    if (m_Geometry.AltitudeMode == EnumAltitudeMode.ClampToGround)
                    {
                        m_Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;
                    }
                    if (pipeLineStyle == null)
                    {
                        m_Geometry.Style = new GSOPipeLineStyle3D();
                    }

                    FrmSetPipelineStyle dlg = new FrmSetPipelineStyle(m_Geometry.Style, mfeature, mlayer, m_GlobeControl);

                    // 恢复一下
                    if (dlg.ShowDialog(this) == DialogResult.Cancel)
                    {
                        m_Geometry.Style        = oldStyle;
                        m_Geometry.AltitudeMode = oldAltMode;
                    }
                }
            }
        }
        private void SetControlsByStyle(GSOStyle style)
        {
            GSOPipeLineStyle3D geoStyle3d = m_Style as GSOPipeLineStyle3D;

            if (geoStyle3d != null)
            {
                // 这句要写到前面,不然下面Checked的时候要检查
                pictureBoxLineColor.BackColor = Color.FromArgb(255, geoStyle3d.LineColor);
                numericUpDownLineOpaque.Value = geoStyle3d.LineColor.A;
                textBoxLineRadius.Text        = geoStyle3d.Radius.ToString();
                textBoxThickness.Text         = geoStyle3d.Thickness.ToString();
                textBoxSlice.Text             = geoStyle3d.Slice.ToString();
                textBoxCornerSliceAngle.Text  = geoStyle3d.CornerSliceAngle.ToString();
            }
        }
        private void lineColorChanged()
        {
            GSOPipeLineStyle3D pipeLineStyle3D = m_Style as GSOPipeLineStyle3D;

            if (pipeLineStyle3D != null)
            {
                m_GlobeControl.Globe.AddToEditHistroy(mlayer, mfeature, EnumEditType.Modify);

                pipeLineStyle3D.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), pictureBoxLineColor.BackColor);
                if (m_GlobeControl != null)
                {
                    m_GlobeControl.Refresh();
                }
            }
        }
Example #11
0
        private void SetControlsByStyle(GSOStyle style)
        {
            if (m_Style != null)
            {
                pipeLineStyle3D = m_Style as GSOPipeLineStyle3D;
                if (pipeLineStyle3D == null)
                {
                    pipeLineStyle3D = new GSOPipeLineStyle3D();
                    RefreshGlobe(pipeLineStyle3D);
                }
            }
            else
            {
                pipeLineStyle3D = new GSOPipeLineStyle3D();
                RefreshGlobe(pipeLineStyle3D);
            }
            // 这句要写到前面,不然下面Checked的时候要检查
            pictureBoxLineColor.BackColor = Color.FromArgb(255, pipeLineStyle3D.LineColor);
            numericUpDownLineOpaque.Value = pipeLineStyle3D.LineColor.A;
            textBoxLineRadius.Text        = pipeLineStyle3D.Radius.ToString();
            textBoxThickness.Text         = pipeLineStyle3D.Thickness.ToString();
            textBoxSlice.Text             = pipeLineStyle3D.Slice.ToString();
            textBoxCornerSliceAngle.Text  = pipeLineStyle3D.CornerSliceAngle.ToString();

            GSOPipeJointParam headJointParam = pipeLineStyle3D.HeadJointParam;

            if (headJointParam != null && headJointParam.Extent < 0)
            {
                tBoxHeadDecValue.Text = (-headJointParam.Extent).ToString();
            }
            else
            {
                //tBoxHeadDecValue.Text = m_GlobeControl.Globe.DecjointValue.ToString();
            }

            GSOPipeJointParam tailJointParam = pipeLineStyle3D.TailJointParam;

            if (tailJointParam != null && tailJointParam.Extent < 0)
            {
                tBoxTailDecValue.Text = (-tailJointParam.Extent).ToString();
            }
            else
            {
                //tBoxTailDecValue.Text = m_GlobeControl.Globe.DecjointValue.ToString();
            }

            m_bInitialized = true;
        }
Example #12
0
        private void SetControlsByStyle(GSOStyle style)
        {
            if (style != null)
            {
                GSOPipeLineStyle3D pipelineStyle = style as GSOPipeLineStyle3D;
                if (pipelineStyle != null)
                {
                    AddTabPages("pipelineStyle", "管线", new CtrlPipelineStyleSetting(pipelineStyle, mfeature, mlayer, m_GlobeControl));
                }
                else
                {
                    GSOSimpleLineStyle3D simpleLineStyle = style as GSOSimpleLineStyle3D;
                    if (simpleLineStyle != null)
                    {
                        AddTabPages("simpleLineStyle", "简单线", new CtrlLineStyleSetting(simpleLineStyle, mfeature, mlayer, m_GlobeControl));
                    }
                    else
                    {
                        GSOExtendSectionLineStyle3D extentSectionLineStyle = style as GSOExtendSectionLineStyle3D;
                        if (extentSectionLineStyle != null)
                        {
                            AddTabPages("extendSectionLineStyle", "管沟", new CtrlExtentSectionlineStyleSetting(extentSectionLineStyle, mfeature, mlayer, m_GlobeControl));
                        }
                    }
                }

                checkBoxUseStyle.Checked = true;
                GSOLineStyle3D lineStyle = style as GSOLineStyle3D;
                if (lineStyle != null && lineStyle.ArrowVisible && lineStyle.ArrowStyle != null)
                {
                    checkBoxShowArrow.Checked = true;
                }
                else
                {
                    checkBoxShowArrow.Checked = false;
                }
            }
            else
            {
                checkBoxUseStyle.Checked  = false;
                checkBoxShowArrow.Checked = false;
            }

            CheckControlsEnable(checkBoxUseStyle.Checked);
        }
        private void buttonOk_Click(object sender, EventArgs e)
        {
            string caption = comboBoxLayerNames.Text;

            if (caption == "")
            {
                return;
            }
            GSOLayer    layer    = m_globeControl.Globe.Layers.GetLayerByCaption(caption);
            GSOFeatures features = layer.GetAllFeatures();

            for (int i = 0; i < features.Length; i++)
            {
                GSOFeature       feature = features[i];
                GSOGeoPolyline3D line    = feature.Geometry as GSOGeoPolyline3D;
                if (line == null)
                {
                    continue;
                }
                GSOPipeLineStyle3D pipeLineStyle = line.Style as GSOPipeLineStyle3D;

                int mode = 0;
                // 管线暂不支持依地模式
                if (line.AltitudeMode == EnumAltitudeMode.ClampToGround)
                {
                    mode = 1;
                    line.AltitudeMode = EnumAltitudeMode.RelativeToGround;
                }
                if (pipeLineStyle == null)
                {
                    pipeLineStyle = new GSOPipeLineStyle3D();
                }

                pipeLineStyle.LineColor = buttonPipelineColor.BackColor;
                line.Style = pipeLineStyle;
                if (mode == 1)
                {
                    line.AltitudeMode = EnumAltitudeMode.ClampToGround;
                }
            }
            m_globeControl.Refresh();
            this.Close();
        }
        private void buttonOk_Click(object sender, EventArgs e)
        {
            string caption = comboBoxLayerNames.Text;
            if (caption == "")
            {
                return;
            }
            GSOLayer layer = m_globeControl.Globe.Layers.GetLayerByCaption(caption);
            GSOFeatures features = layer.GetAllFeatures();
            for (int i = 0; i < features.Length; i++)
            {
                GSOFeature feature = features[i];
                GSOGeoPolyline3D line = feature.Geometry as GSOGeoPolyline3D;
                if (line == null)
                {
                    continue;
                }
                GSOPipeLineStyle3D pipeLineStyle = line.Style as GSOPipeLineStyle3D;

                int mode = 0;
                // 管线暂不支持依地模式
                if (line.AltitudeMode == EnumAltitudeMode.ClampToGround)
                {
                    mode = 1;
                    line.AltitudeMode = EnumAltitudeMode.RelativeToGround;
                }
                if (pipeLineStyle == null)
                {
                    pipeLineStyle = new GSOPipeLineStyle3D();
                }

                pipeLineStyle.LineColor = buttonPipelineColor.BackColor;
                line.Style = pipeLineStyle;
                if (mode == 1)
                {
                    line.AltitudeMode = EnumAltitudeMode.ClampToGround;
                }

            }
            m_globeControl.Refresh();
            this.Close();
        }
        public void CtrlLineStylePreview_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;


            /*
             * Color FColor = Color.FromArgb(255, 255, 255);
             *
             * Color TColor = Color.FromArgb(221, 221, 221);
             *
             * Brush b = new LinearGradientBrush(this.ClientRectangle, FColor, TColor, LinearGradientMode.Vertical);
             *
             * g.FillRectangle(b, this.ClientRectangle);
             */



            if (m_Style != null)
            {
                GSOSimpleLineStyle3D simpleLineStyle = m_Style as GSOSimpleLineStyle3D;
                if (simpleLineStyle != null)
                {
                    DrawSimpleLine(g, simpleLineStyle);
                }
                else
                {
                    GSOPipeLineStyle3D pipeLineStyle = m_Style as GSOPipeLineStyle3D;
                    if (pipeLineStyle != null)
                    {
                        DrawPipeLine(g, pipeLineStyle);
                    }
                }
            }
            else
            {
                StringFormat stringFormat = new StringFormat();
                stringFormat.LineAlignment = StringAlignment.Center;
                stringFormat.Alignment     = StringAlignment.Center;
                g.DrawString("无风格", new Font("宋体", 10), new SolidBrush(Color.Black), this.Bounds, stringFormat);
            }
        }
        private void textBoxSlice_TextChanged(object sender, EventArgs e)
        {
            GSOPipeLineStyle3D pipeLineStyle3D = m_Style as GSOPipeLineStyle3D;

            if (pipeLineStyle3D != null)
            {
                try
                {
                    m_GlobeControl.Globe.AddToEditHistroy(mlayer, mfeature, EnumEditType.Modify);

                    pipeLineStyle3D.Slice = Convert.ToInt32(textBoxSlice.Text);
                    if (m_GlobeControl != null)
                    {
                        m_GlobeControl.Refresh();
                    }
                }
                catch (System.Exception exp)
                {
                    Log.PublishTxt(exp);
                }
            }
        }
        public void DrawPipeLine(Graphics g, GSOPipeLineStyle3D pipeLineStyle)
        {
            Pen newPen = new Pen(pipeLineStyle.LineColor, 1.0f);


            int nEllipseHeight = (int)(Height * 0.3);
            int nEllipseWidth  = nEllipseHeight / 2;
            int nStartX        = (int)(Width * 0.1);

            int nHalfHeight = Height / 2;


            int nBodyStartX = nStartX + nEllipseWidth / 2;



            Rectangle rcEllipse     = new Rectangle(nStartX, nHalfHeight - nEllipseHeight / 2, nEllipseWidth, nEllipseHeight);
            Rectangle rcTailEllipse = new Rectangle(this.Width - nStartX - nEllipseWidth, nHalfHeight - nEllipseHeight / 2, nEllipseWidth, nEllipseHeight);
            Rectangle rcFill        = new Rectangle(nBodyStartX, rcEllipse.Top, Width - 2 * nBodyStartX + nEllipseWidth / 2, nEllipseHeight);

            Color FColor = pipeLineStyle.LineColor;

            Color TColor = Color.FromArgb(255, 255, 255);

            Brush b = new LinearGradientBrush(this.ClientRectangle, FColor, TColor, LinearGradientMode.BackwardDiagonal);

            g.FillRectangle(b, rcFill);



            g.DrawEllipse(newPen, rcEllipse);


            g.DrawEllipse(newPen, rcTailEllipse);


            g.DrawLine(newPen, nBodyStartX, rcEllipse.Top, Width - nBodyStartX, rcEllipse.Top);
            g.DrawLine(newPen, nBodyStartX, rcEllipse.Bottom, Width - nBodyStartX, rcEllipse.Bottom);
        }
Example #18
0
        private void DrawCurveGraph(double a_x, double a_y)
        {
            // 遍历线,求距离
            table = new DataTable();
            //showTable.Columns.Clear();
            list.Clear();
            chart1.Series["管线"].Points.Clear();

            table.Columns.Add("编号", typeof(string));
            table.Columns.Add("管线类型", typeof(string));
            table.Columns.Add("管线编码", typeof(string));
            table.Columns.Add("管径_毫米", typeof(string));
            table.Columns.Add("材质", typeof(string));
            table.Columns.Add("管线埋深", typeof(string));

            object[,] sortIndex = new object[listPoint.Count, 2];
            for (int i = 0; i < listPoint.Count; i++)
            {
                GSOPoint3d geoPoint = (GSOPoint3d)listPoint[i];
                GSOFeature feature  = listFeat[i] as GSOFeature;
                //坐标投影
                int id = GeoScene.Data.GSOProjectManager.AddProject("+proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=555484.8092 +y_0=-4114948.631 +ellps=krass +units=m +no_defs");

                GeoScene.Data.GSOPoint2d a_Point = GeoScene.Data.GSOProjectManager.Forward(new GSOPoint2d(a_x, a_y), id);//user画的线的起始点

                GeoScene.Data.GSOPoint2d pt2d   = new GeoScene.Data.GSOPoint2d(geoPoint.X, geoPoint.Y);
                GeoScene.Data.GSOPoint2d result = GeoScene.Data.GSOProjectManager.Forward(pt2d, id);
                B_x = result.X;
                B_y = result.Y;

                double x   = System.Math.Abs(B_x - a_Point.X);
                double y   = System.Math.Abs(B_y - a_Point.Y);
                double Dis = Math.Round(Math.Sqrt(x * x + y * y), 2);
                list.Add(geoPoint.Z);
                sortIndex[i, 0] = Dis;
                sortIndex[i, 1] = i;

                chart1.Series["管线"].Points.AddXY(Dis, geoPoint.Z);//绑定数据

                string pipeType = "";
                if (feature.GetFieldAsInt32("管线编码") >= 6000 && feature.GetFieldAsInt32("管线编码") <= 6203)  // 6100是热力管线的编码
                {
                    pipeType = "热力管线";
                }
                else if (feature.GetFieldAsInt32("管线编码") >= 4000 && feature.GetFieldAsInt32("管线编码") <= 4306)//排水
                {
                    pipeType = "排水管线";
                }
                else if (feature.GetFieldAsInt32("管线编码") >= 3000 && feature.GetFieldAsInt32("管线编码") <= 3513)  // 3000是给力管线的编码
                {
                    pipeType = "给水管线";
                }
                else if (feature.GetFieldAsInt32("管线编码") >= 1000 && feature.GetFieldAsInt32("管线编码") <= 1808)  // 电力管线的编码
                {
                    pipeType = "电力管线";
                }
                else if (feature.GetFieldAsInt32("管线编码") >= 2000 && feature.GetFieldAsInt32("管线编码") <= 2300)  // 通信管线的编码
                {
                    pipeType = "通信管线";
                }
                else if (feature.GetFieldAsInt32("管线编码") >= 5000 && feature.GetFieldAsInt32("管线编码") <= 5200)  // 通信管线的编码
                {
                    pipeType = "燃气管线";
                }
                string number = Convert.ToString(i + 1);

                string material = feature.GetFieldAsString("材质");
                string diameter = feature.GetFieldAsString("管径_毫米");
                table.Rows.Add(new object[] { number, pipeType, feature.Name.ToString(), diameter, material, Convert.ToDecimal(list[i].ToString()).ToString("f2") });//list[i].ToString().Substring(0,list[i].ToString().IndexOf('.')+3) }

                //chart1.Series["管线"].Points[i].Label = number;//管线的标签
                chart1.Series["管线"].Points[i].LegendText = number;
                if (feature.Geometry.Style.GetType() == typeof(GSOPipeLineStyle3D))
                {
                    GSOPipeLineStyle3D style = (GSOPipeLineStyle3D)feature.Geometry.Style;
                    chart1.Series["管线"].Points[i].MarkerBorderColor = style.LineColor;     //点的填充色
                }
                else
                {
                    chart1.Series["管线"].Points[i].MarkerBorderColor = Color.Black;
                }

                chart1.Series["管线"].Points[i].MarkerBorderWidth = 3;                                                                                                                                //边框的宽度
                chart1.Series["管线"].Points[i].MarkerColor       = Color.Transparent;
                chart1.Series["管线"].Points[i].MarkerSize        = Convert.ToInt32(Math.Floor((feature.GetFieldAsDouble("管径_毫米") / 0.35 + chart1.Series["管线"].Points[i].MarkerBorderWidth) / 25.0)); //点的大小
            }

            string htmlCode = "<html><head><style>#hor-minimalist-b " +
                              "{-moz-background-clip:border;" +
                              "-moz-background-inline-policy:continuous;" +
                              "-moz-background-origin:padding;" +
                              "background:#FFFFFF none repeat scroll 0 0;" +
                              "border-collapse:collapse;" +
                              "font-family:'Lucida Sans Unicode','Lucida Grande',Sans-Serif;" +
                              " font-size:12px;" +
                              " margin:10px;" +
                              " text-align:left;" +
                              " width:80%;" +
                              " }" +
                              " #hor-minimalist-b th {" +
                              " border-bottom:2px solid #6678B1;" +
                              " color:#003399;" +
                              " font-size:12px;" +
                              "font-weight:normal;" +
                              "  padding:10px 8px;" +
                              " }" +
                              "  #hor-minimalist-b td {" +
                              " border-bottom:1px solid #CCCCCC;" +
                              " font-size:12px;" +
                              " color:#666699;" +
                              "padding:6px 8px;}" +
                              "#hor-minimalist-b tbody tr:hover td {" +
                              "color:#000099;}" +
                              "</style></head>" +
                              "<body style='border:none;' ><table align='center' summary='Employee Pay Sheet' id='hor-minimalist-b'><thead><tr><th scope='col'>管线类型</th><th scope='col'>管线编码</th><th scope='col'>管径_毫米</th>" +
                              "<th scope='col'>材质</th><th scope='col'>管线埋深</th></tr></thead>" +
                              "<tbody><tr><td>" +
                              "</td><td>" +
                              "</td><td>" +
                              "</td><td>" +
                              "</td><td>" +
                              "</td></tr></tbody></table></body><ml>";

            webBrowser1.DocumentText = htmlCode;
        }
 private void RefreshGlobe(GSOPipeLineStyle3D pipeLineStyle3D)
 {
     mfeature.Geometry.Style = pipeLineStyle3D;
     mfeature.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;
     if (m_GlobeControl != null)
     {
         m_GlobeControl.Globe.Refresh();
     }
 }
        private void SetControlsByStyle(GSOStyle style)
        {
            if (m_Style != null)
            {
                pipeLineStyle3D = m_Style as GSOPipeLineStyle3D;
                if (pipeLineStyle3D == null)
                {
                    pipeLineStyle3D = new GSOPipeLineStyle3D();
                    RefreshGlobe(pipeLineStyle3D);
                }
            }
            else
            {
                pipeLineStyle3D = new GSOPipeLineStyle3D();
                RefreshGlobe(pipeLineStyle3D);
            }
            // 这句要写到前面,不然下面Checked的时候要检查
            pictureBoxLineColor.BackColor = Color.FromArgb(255, pipeLineStyle3D.LineColor);
            numericUpDownLineOpaque.Value = pipeLineStyle3D.LineColor.A;
            textBoxLineRadius.Text = pipeLineStyle3D.Radius.ToString();
            textBoxThickness.Text = pipeLineStyle3D.Thickness.ToString();
            textBoxSlice.Text = pipeLineStyle3D.Slice.ToString();
            textBoxCornerSliceAngle.Text = pipeLineStyle3D.CornerSliceAngle.ToString();

            GSOPipeJointParam headJointParam = pipeLineStyle3D.HeadJointParam;
            if (headJointParam != null && headJointParam.Extent < 0)
            {

                tBoxHeadDecValue.Text = (-headJointParam.Extent).ToString();
            }
            else
            {
                //tBoxHeadDecValue.Text = m_GlobeControl.Globe.DecjointValue.ToString();
            }

            GSOPipeJointParam tailJointParam = pipeLineStyle3D.TailJointParam;
            if (tailJointParam != null && tailJointParam.Extent < 0)
            {

                tBoxTailDecValue.Text = (-tailJointParam.Extent).ToString();
            }
            else
            {
                //tBoxTailDecValue.Text = m_GlobeControl.Globe.DecjointValue.ToString();
            }

            m_bInitialized = true;
        }
Example #21
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);
        }
Example #22
0
        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();

                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOFeature newFeature = new GSOFeature();

                        GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                        style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                        double radius  = f.GetFieldAsDouble(cmbRadius.SelectedIndex) / 1000; // 单位
                        string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString());

                        style.Radius           = radius;
                        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;
                            deep2 = deep2 + radius;
                        }
                        else if (cmbReference.SelectedIndex == 1)  //管顶
                        {
                            deep1 = deep1 - radius;
                            deep2 = deep2 - radius;
                        }
                        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;
                        //newFeature.CustomID = f.ID;
                        layer.AddFeature(newFeature);
                    }
                }
                ctl.Refresh();

                layer.Save();

                ctl.Globe.Layers.Remove(layer);
                this.Close();
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
Example #23
0
        private List <DataTable> CollisionAnalysis()
        {
            List <DataTable> listTable = new List <DataTable>();
            GSOPoint3d       pntIntersect1;
            GSOPoint3d       pntIntersect2;
            int layerCount = listBox1.SelectedItems.Count;

            for (int i = 0; i < layerCount; i++)//遍历所有的图层
            {
                GSOLayer layer1 = globeControl1.Globe.Layers.GetLayerByCaption(listBox1.SelectedItems[i].ToString().Trim());
                if (layer1 != null)
                {
                    DataTable dt = new DataTable();
                    if (layer1.GetAllFeatures().Length > 0)
                    {
                        for (int fieldName = 0; fieldName < layer1.GetAt(0).GetFieldCount(); fieldName++)
                        {
                            GSOFieldDefn field = (GSOFieldDefn)layer1.GetAt(0).GetFieldDefn(fieldName);
                            dt.Columns.Add(field.Name);
                        }
                    }
                    listTable.Add(dt);
                }
            }

            if (listTable.Count > 0 && listTable.Count == layerCount)
            {
                for (int i = 0; i < layerCount; i++)//遍历所有的图层
                {
                    GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(listBox1.SelectedItems[i].ToString().Trim());
                    if (layer.Caption.Contains("管线")) //过滤出管线图层
                    {
                        GSOFeatureLayer   flayer   = layer as GSOFeatureLayer;
                        GSOFeatureDataset fdataset = flayer.Dataset as GSOFeatureDataset;
                        GSOFeatures       feats    = flayer.GetAllFeatures();


                        for (int m = 0; m < feats.Length; m++) //遍历图层中的所有管线
                        {
                            GSOFeature feat = feats[m];

                            GSOGeoPolyline3D line1 = feat.Geometry as GSOGeoPolyline3D;
                            if (line1 == null)
                            {
                                continue;
                            }
                            GSOPipeLineStyle3D pipeStyle1 = line1.Style as GSOPipeLineStyle3D;
                            if (pipeStyle1 == null)
                            {
                                continue;
                            }
                            for (int j = i; j < layerCount; j++)
                            {
                                GSOLayer        layer2  = globeControl1.Globe.Layers.GetLayerByCaption(listBox1.SelectedItems[j].ToString().Trim());
                                GSOFeatureLayer flayer2 = layer2 as GSOFeatureLayer;
                                if (layer2.Caption.Contains("管线"))
                                {
                                    GSOFeatureDataset fdataset2 = flayer2.Dataset as GSOFeatureDataset;
                                    GSOFeatures       feats2    = flayer2.GetAllFeatures();
                                    for (int n = 0; n < feats2.Length; n++)//遍历图层中的所有管线
                                    {
                                        if (i == j)
                                        {
                                            if (m >= n)
                                            {
                                                continue;
                                            }
                                        }
                                        GSOFeature       feat2 = feats2[n];
                                        GSOGeoPolyline3D line2 = feat2.Geometry as GSOGeoPolyline3D;
                                        if (line2 == null)
                                        {
                                            continue;
                                        }
                                        GSOPipeLineStyle3D pipeStyle2 = line2.Style as GSOPipeLineStyle3D;
                                        if (pipeStyle2 == null)
                                        {
                                            continue;
                                        }
                                        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)
                                            {
                                                dDist = dDist - pipeStyle1.Radius - pipeStyle2.Radius;
                                                if (dDist < 0) //发生碰撞,把发生碰撞的管线名称添加到DataTable里
                                                {
                                                    DataRow newRow = listTable[i].NewRow();
                                                    for (int fieldName = 0; fieldName < feats[m].GetFieldCount(); fieldName++)
                                                    {
                                                        newRow[fieldName] = feats[m].GetValue(fieldName);
                                                    }
                                                    if (newRow != null)
                                                    {
                                                        listTable[i].Rows.Add(newRow);
                                                    }

                                                    DataRow newRow1 = listTable[j].NewRow();
                                                    for (int fieldName = 0; fieldName < feats2[n].GetFieldCount(); fieldName++)
                                                    {
                                                        newRow1[fieldName] = feats2[n].GetValue(fieldName);
                                                    }
                                                    if (newRow != null)
                                                    {
                                                        listTable[j].Rows.Add(newRow1);
                                                    }
                                                    //newRow["编号1"] = layer.Caption + "-" + feats[m].ID;
                                                    //newRow["编号2"] = layer2.Caption + "-" + feats2[n].ID;
                                                    //dt.Rows.Add(newRow);
                                                }
                                            }
                                        }
                                        line2.ReleaseInnerPointer();
                                        feat2.ReleaseInnerPointer();
                                    }
                                    feats2.ReleaseInnerPointer();
                                }
                            }
                            line1.ReleaseInnerPointer();
                            feat.ReleaseInnerPointer();
                        }
                        feats.ReleaseInnerPointer();
                    }
                }
            }
            return(listTable);
        }
Example #24
0
        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 ShpSourceLayer = ctl.Globe.Layers[cmbLayer.SelectedIndex];

                GSOLayer   pipeModelLayer = ctl.Globe.Layers.Add(txtModelLayer.Text);

                string pipeRectFile = Path.GetDirectoryName(txtModelLayer.Text) + "\\" + Path.GetFileNameWithoutExtension(txtModelLayer.Text) + "_Rect" + Path.GetExtension(txtModelLayer.Text);
                GSOLayer layer_Rect = ctl.Globe.Layers.Add(pipeRectFile);
                lgdFilePath = txtModelLayer.Text;

                if (pipeModelLayer != null)
                {
                    GSOFeatures features = ShpSourceLayer.GetAllFeatures();
                    string message = "";
                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOFeature newFeature = new GSOFeature();

                        GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                        style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                        double radius = 0;
                        GSOFieldDefn diameterfield = (GSOFieldDefn)f.GetFieldDefn(cmbRadius.SelectedItem.ToString());
                        if (diameterfield.Type == EnumFieldType.Text)
                        {
                            radius = Convert.ToDouble(f.GetFieldAsString(cmbRadius.SelectedItem.ToString())) / 2000;
                        }
                        else
                        {
                            radius = f.GetFieldAsDouble(cmbRadius.SelectedItem.ToString()) / 2000;  // 探测数据的单位一般是毫米,需换算为米; 管径一般是 直径, 这个需要半径, 所有除以2000
                        }

                        string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString());
                        int num_width = f.GetFieldAsInt32(cmbWidthNum.SelectedItem.ToString());
                        int num_height = f.GetFieldAsInt32(cmbHeightNum.SelectedItem.ToString());
                        double interval = radius * 2;    //  f.GetFieldAsDouble(cmbInterval.SelectedItem.ToString());
                        double rectWidth = radius * 2 * num_width + 0.08;// 两端空出0.04
                        double rectHeight = radius * 2 * num_height + 0.08;
                        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)
                         {
                             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;
                         }

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

                             if (double.IsInfinity(pt3d.Z))
                             {
                                 pt3d.Z = deep2;
                             }
                             line[0][n] = pt3d;
                         }
                         if (num_height == 0 || num_width == 0) // 直埋
                         {
                             newFeature.Geometry = line;
                             newFeature.Geometry.Style = style;
                             newFeature.Name = eventid;
                             pipeModelLayer.AddFeature(newFeature);
                         }
                         else
                         {
                             GSOFeature rectfeat = CreatePipeRect(f, line,rectWidth,rectHeight);
                             if (rectfeat != null)
                             {
                                 layer_Rect.AddFeature(rectfeat);
                             }
                             one2Multi(line, num_width, num_height, interval, style, pipeModelLayer, eventid);
                         }
                    }
                    ctl.Refresh();

                    pipeModelLayer.Save();
                    layer_Rect.Save();
                    string strMessage = "shp文件中共" + features.Length + "个对象,实际生成" + (pipeModelLayer.GetAllFeatures().Length + layer_Rect.GetAllFeatures().Length) + "个对象!\n";
                    MessageBox.Show(strMessage + message, "提示");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
        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;
            }
            if (string.IsNullOrEmpty(textBoxNewLayerName.Text))
            {
                MessageBox.Show("请选择一个Shp图层!", "提示");
                return;
            }
            if (ds.GetDatasetByName(textBoxNewLayerName.Text) != null)
            {
                MessageBox.Show("图层名称已存在!", "提示");
                return;
            }
            try
            {
                GSOLayer ShpSourceLayer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());
                GSOFeatureDataset pipeline = CreateDBFeatureDataset(textBoxNewLayerName.Text.Trim());
                if (pipeline == null)
                {
                    MessageBox.Show("输入的图层名称不符合要求!", "提示");
                    return;
                }
                pipeline.Open();
                GSOFeatureDataset pipelineRect = CreateDBFeatureDataset(textBoxNewLayerName.Text.Trim() + "_Rect");
                if (pipelineRect == null)
                {
                    return;
                }
                pipelineRect.Open();

                GSOFeatures features = ShpSourceLayer.GetAllFeatures();
                string message = "";
                for (int j = 0; j < features.Length; j++)
                {
                    GSOFeature f = features[j];

                    GSOFeature newFeature = pipeline.CreateFeature();

                    GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                    style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                    double radius = 0;
                    if (cmbRadius.SelectedItem == null)
                    {
                        cmbRadius.SelectedIndex = 0;
                    }
                    GSOFieldDefn diameterfield = (GSOFieldDefn)f.GetFieldDefn(cmbRadius.SelectedItem.ToString());
                    string fieldText = f.GetFieldAsString(cmbRadius.SelectedItem.ToString());
                    if (diameterfield.Type == EnumFieldType.Text)
                    {
                        if (double.TryParse(fieldText, out radius))
                        {
                            radius = radius / 2000;
                        }
                        else
                        {
                            message += "ID为" + f.ID + "的对象的管径字段值不符合要求!\r\n";
                            continue;
                        }
                    }
                    else
                    {
                        radius = f.GetFieldAsDouble(cmbRadius.SelectedItem.ToString()) / 2000;  // 探测数据的单位一般是毫米,需换算为米; 管径一般是 直径, 这个需要半径, 所有除以2000
                    }

                    if (cmbID.SelectedItem == null)
                    {
                        cmbID.SelectedIndex = 0;
                    }
                    if (cmbWidthNum.SelectedItem == null)
                    {
                        cmbWidthNum.SelectedIndex = 0;
                    }
                    if (cmbHeightNum.SelectedItem == null)
                    {
                        cmbHeightNum.SelectedIndex = 0;
                    }
                    string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString());
                    double interval = radius * 2;
                    int num_width = 0;
                    int num_height = 0;
                    if (!int.TryParse(f.GetFieldAsString(cmbWidthNum.SelectedItem.ToString()), out num_width))
                    {
                        message += "ID为" + f.ID + "的对象的宽度字段值不符合要求!\r\n";
                        continue;
                    }
                    if (!int.TryParse(f.GetFieldAsString(cmbHeightNum.SelectedItem.ToString()), out num_height))
                    {
                        message += "ID为" + f.ID + "的对象的高度字段值不符合要求!\r\n";
                        continue;
                    }

                    double rectWidth = radius * 2 * num_width + 0.08;// 两端空出0.04
                    double rectHeight = radius * 2 * num_height + 0.08;

                    if (radius == 0)
                    {
                        message += "ID为" + f.ID + "的对象的管径字段值为0!\r\n";
                        continue;
                    }

                    int intSlice = 0;
                    double cornerSliceAngle = 0;
                    if (!int.TryParse(txtSlice.Text.Trim(), out intSlice))
                    {
                        message += "ID为" + f.ID + "的对象的截面分段数字段值不符合要求!\r\n";
                        continue;
                    }
                    if (!double.TryParse(textBoxCornerSliceAngle.Text.Trim(), out cornerSliceAngle))
                    {
                        message += "ID为" + f.ID + "的对象的拐弯平滑度字段值不符合要求!\r\n";
                        continue;
                    }
                    style.Radius = radius;
                    style.Slice = intSlice;
                    style.CornerSliceAngle = cornerSliceAngle;

                    f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                    GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D;
                    if (line == null)
                    {
                        message += "ID为" + f.ID + "的对象不是一个线对象!\r\n";
                        continue;
                    }

                    if (cmbFrom.SelectedItem == null)
                    {
                        cmbFrom.SelectedIndex = 0;
                    }
                    if (cmbTo.SelectedItem == null)
                    {
                        cmbTo.SelectedIndex = 0;
                    }
                    double deep1 = 0;
                    double deep2 = 0;
                    if (!double.TryParse(f.GetFieldAsString(cmbFrom.Items[cmbTo.SelectedIndex].ToString().Trim()), out deep1))
                    {
                        message += "ID为" + f.ID + "的对象的起点埋深字段值不符合要求!\r\n";
                        continue;
                    }
                    if (!double.TryParse(f.GetFieldAsString(cmbTo.Items[cmbTo.SelectedIndex].ToString().Trim()), out deep2))
                    {
                        message += "ID为" + f.ID + "的对象的终点埋深字段值不符合要求!\r\n";
                        continue;
                    }

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

                        if (double.IsInfinity(pt3d.Z))
                        {
                            pt3d.Z = deep2;
                        }
                        line[0][n] = pt3d;
                    }
                    if (num_height == 0 || num_width == 0) // 直埋
                    {
                        newFeature.Geometry = line;
                        newFeature.Geometry.Style = style;
                        newFeature.Name = eventid;
                        SetFields(f, newFeature);

                        pipeline.AddFeature(newFeature);
                    }
                    else
                    {
                        GSOFeature rectfeat = pipelineRect.CreateFeature();
                        rectfeat.Geometry = CreatePipeRect(line, rectWidth, rectHeight);
                        if (rectfeat != null)
                        {
                            SetFields(f, rectfeat);
                            pipelineRect.AddFeature(rectfeat);
                        }
                        one2Multi(line, num_width, num_height, interval, style, pipeline, eventid, f);
                    }
                }
                globeControl1.Refresh();

                pipeline.Save();
                pipelineRect.Save();
                pipeline.Close();
                pipelineRect.Close();
                string strMessage = "shp文件中共" + features.Length + "个对象,实际入库" + pipeline.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 void one2Multi(GSOGeoPolyline3D line, int num_width, int num_height, double interval, GSOPipeLineStyle3D style, GSOLayer layer, string name)
        {
            line = LatLon2Coord_Line(line);

            double width_all  = interval * (num_width - 1);
            double height_all = interval * (num_height - 1);

            line.Clone();
            GSOGeoPolyline3D line_1 = line.Clone() as GSOGeoPolyline3D;

            GSOPoint3d p1 = line[0][0];
            GSOPoint3d p2 = line[0][1];

            double daltaX = p2.X - p1.X;
            double daltaY = p2.Y - p1.Y;

            double agree = Math.Atan(daltaY / daltaX);

            line.MoveXY((-0.5 * width_all - interval) * Math.Sin(agree), (0.5 * width_all + interval) * Math.Cos(agree));

            line.MoveZ(height_all / -2);

            for (int i = 0; i < num_width; i++)
            {
                for (int j = 0; j < num_height; j++)
                {
                    GSOGeoPolyline3D templine = line.Clone() as GSOGeoPolyline3D;

                    templine.MoveXY((i + 1) * interval * Math.Sin(agree), -1 * (i + 1) * interval * Math.Cos(agree));

                    templine = Coord2LatLon_Line(templine);

                    templine.MoveZ(interval * j);

                    GSOFeature feat = new GSOFeature();
                    feat.Geometry       = templine;
                    feat.Geometry.Style = style;
                    feat.Name           = name;
                    layer.AddFeature(feat);
                }
            }
        }
        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);
            }
        }
        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;
            }
            if (string.IsNullOrEmpty(textBoxNewLayerName.Text))
            {
                MessageBox.Show("请选择一个Shp图层!", "提示");
                return;
            }
            if (ds.GetDatasetByName(textBoxNewLayerName.Text) != null)
            {
                MessageBox.Show("图层名称已存在!", "提示");
                return;
            }
            try
            {
                GSOLayer          ShpSourceLayer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());
                GSOFeatureDataset pipeline       = CreateDBFeatureDataset(textBoxNewLayerName.Text.Trim());
                if (pipeline == null)
                {
                    MessageBox.Show("输入的图层名称不符合要求!", "提示");
                    return;
                }
                pipeline.Open();
                GSOFeatureDataset pipelineRect = CreateDBFeatureDataset(textBoxNewLayerName.Text.Trim() + "_Rect");
                if (pipelineRect == null)
                {
                    return;
                }
                pipelineRect.Open();

                GSOFeatures features = ShpSourceLayer.GetAllFeatures();
                string      message  = "";
                for (int j = 0; j < features.Length; j++)
                {
                    GSOFeature f = features[j];

                    GSOFeature newFeature = pipeline.CreateFeature();

                    GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                    style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                    double radius = 0;
                    if (cmbRadius.SelectedItem == null)
                    {
                        cmbRadius.SelectedIndex = 0;
                    }
                    GSOFieldDefn diameterfield = (GSOFieldDefn)f.GetFieldDefn(cmbRadius.SelectedItem.ToString());
                    string       fieldText     = f.GetFieldAsString(cmbRadius.SelectedItem.ToString());
                    if (diameterfield.Type == EnumFieldType.Text)
                    {
                        if (double.TryParse(fieldText, out radius))
                        {
                            radius = radius / 2000;
                        }
                        else
                        {
                            message += "ID为" + f.ID + "的对象的管径字段值不符合要求!\r\n";
                            continue;
                        }
                    }
                    else
                    {
                        radius = f.GetFieldAsDouble(cmbRadius.SelectedItem.ToString()) / 2000;  // 探测数据的单位一般是毫米,需换算为米; 管径一般是 直径, 这个需要半径, 所有除以2000
                    }

                    if (cmbID.SelectedItem == null)
                    {
                        cmbID.SelectedIndex = 0;
                    }
                    if (cmbWidthNum.SelectedItem == null)
                    {
                        cmbWidthNum.SelectedIndex = 0;
                    }
                    if (cmbHeightNum.SelectedItem == null)
                    {
                        cmbHeightNum.SelectedIndex = 0;
                    }
                    string eventid    = f.GetFieldAsString(cmbID.SelectedItem.ToString());
                    double interval   = radius * 2;
                    int    num_width  = 0;
                    int    num_height = 0;
                    if (!int.TryParse(f.GetFieldAsString(cmbWidthNum.SelectedItem.ToString()), out num_width))
                    {
                        message += "ID为" + f.ID + "的对象的宽度字段值不符合要求!\r\n";
                        continue;
                    }
                    if (!int.TryParse(f.GetFieldAsString(cmbHeightNum.SelectedItem.ToString()), out num_height))
                    {
                        message += "ID为" + f.ID + "的对象的高度字段值不符合要求!\r\n";
                        continue;
                    }

                    double rectWidth  = radius * 2 * num_width + 0.08;// 两端空出0.04
                    double rectHeight = radius * 2 * num_height + 0.08;

                    if (radius == 0)
                    {
                        message += "ID为" + f.ID + "的对象的管径字段值为0!\r\n";
                        continue;
                    }

                    int    intSlice         = 0;
                    double cornerSliceAngle = 0;
                    if (!int.TryParse(txtSlice.Text.Trim(), out intSlice))
                    {
                        message += "ID为" + f.ID + "的对象的截面分段数字段值不符合要求!\r\n";
                        continue;
                    }
                    if (!double.TryParse(textBoxCornerSliceAngle.Text.Trim(), out cornerSliceAngle))
                    {
                        message += "ID为" + f.ID + "的对象的拐弯平滑度字段值不符合要求!\r\n";
                        continue;
                    }
                    style.Radius           = radius;
                    style.Slice            = intSlice;
                    style.CornerSliceAngle = cornerSliceAngle;

                    f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                    GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D;
                    if (line == null)
                    {
                        message += "ID为" + f.ID + "的对象不是一个线对象!\r\n";
                        continue;
                    }

                    if (cmbFrom.SelectedItem == null)
                    {
                        cmbFrom.SelectedIndex = 0;
                    }
                    if (cmbTo.SelectedItem == null)
                    {
                        cmbTo.SelectedIndex = 0;
                    }
                    double deep1 = 0;
                    double deep2 = 0;
                    if (!double.TryParse(f.GetFieldAsString(cmbFrom.Items[cmbTo.SelectedIndex].ToString().Trim()), out deep1))
                    {
                        message += "ID为" + f.ID + "的对象的起点埋深字段值不符合要求!\r\n";
                        continue;
                    }
                    if (!double.TryParse(f.GetFieldAsString(cmbTo.Items[cmbTo.SelectedIndex].ToString().Trim()), out deep2))
                    {
                        message += "ID为" + f.ID + "的对象的终点埋深字段值不符合要求!\r\n";
                        continue;
                    }


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

                        if (double.IsInfinity(pt3d.Z))
                        {
                            pt3d.Z = deep2;
                        }
                        line[0][n] = pt3d;
                    }
                    if (num_height == 0 || num_width == 0) // 直埋
                    {
                        newFeature.Geometry       = line;
                        newFeature.Geometry.Style = style;
                        newFeature.Name           = eventid;
                        SetFields(f, newFeature);

                        pipeline.AddFeature(newFeature);
                    }
                    else
                    {
                        GSOFeature rectfeat = pipelineRect.CreateFeature();
                        rectfeat.Geometry = CreatePipeRect(line, rectWidth, rectHeight);
                        if (rectfeat != null)
                        {
                            SetFields(f, rectfeat);
                            pipelineRect.AddFeature(rectfeat);
                        }
                        one2Multi(line, num_width, num_height, interval, style, pipeline, eventid, f);
                    }
                }
                globeControl1.Refresh();

                pipeline.Save();
                pipelineRect.Save();
                pipeline.Close();
                pipelineRect.Close();
                string strMessage = "shp文件中共" + features.Length + "个对象,实际入库" + pipeline.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);
            }
        }
Example #29
0
        private void btnEnter_Click(object sender, EventArgs e)
        {
            int n = 0;

            layer = globeControl1.Globe.Layers.GetLayerByCaption(cmbPipeShow.Text.Trim());
            GSOFeatureLayer flayer = layer as GSOFeatureLayer;

            if (flayer == null)
            {
                return;
            }
            GSOFeatureDataset fdataset = flayer.Dataset as GSOFeatureDataset;

            if (fdataset == null || fdataset.DataSource == null)
            {
                return;
            }
            connectParams = Utility.getConnectParamsByDatasourceName(globeControl1, fdataset.DataSource.Name);
            if (connectParams == null)
            {
                return;
            }
            GSOFeatures feats = flayer.GetAllFeatures();
            string      type  = layer.Caption.Substring(0, 2);
            string      sql   = "select * " + " from " + layer.Caption + "  where";

            for (int i = 0; i < feats.Length; i++)
            {
                GSOFeature f = feats[i];
                if (f.Geometry.Type == EnumGeometryType.GeoPolyline3D)
                {
                    GSOGeoPolyline3D   line  = f.Geometry as GSOGeoPolyline3D;
                    GSOPipeLineStyle3D style = line.Style as GSOPipeLineStyle3D;
                    if (style != null)
                    {
                        GSOPoint3ds pnts = getAllPointInPipeline(line);
                        for (int j = 0; j < pnts.Count; j++)
                        {
                            GSOPoint3d pt = pnts[j];
                            if (Math.Abs(pt.Z) < style.Radius)
                            {
                                n++;
                                sql += "  编号='" + f.Name + "' or ";
                                break;
                            }
                        }
                    }
                }
            }
            if (n > 0)
            {
                sql = sql.Substring(0, sql.Length - 3);
                DataTable dt = new DataTable();
                dt = OledbHelper.QueryTable(sql, connectParams);

                if (dt == null)
                {
                    MessageBox.Show("没有地上管线!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    if (dt.Columns.Count > 3)
                    {
                        dt.Columns.RemoveAt(0);
                        dt.Columns.RemoveAt(0);
                        dt.Columns.RemoveAt(0);
                    }
                    dataGridView1.ReadOnly   = !layer.Editable;
                    dataGridView1.DataSource = dt;
                    if (statusStrip1.Items.Count > 0)
                    {
                        statusStrip1.Items[0].Text = " 共有 " + dt.Rows.Count + " 条记录";
                    }
                    globeControl1.Globe.Refresh();
                }
            }
            else
            {
                MessageBox.Show("没有地上管线!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                dataGridView1.DataSource = null;
                if (statusStrip1.Items.Count > 0)
                {
                    statusStrip1.Items[0].Text = " 共有 " + 0 + " 条记录";
                }
            }
        }
        //应用
        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 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 #32
0
        //缩进接头
        void CheckChangeHeadJoint()
        {
            GSOPipeLineStyle3D geoStyle3dOld  = m_OldStyle as GSOPipeLineStyle3D;
            GSOPipeJointParam  headJointParam = null;
            float fValue = 0;

            if (pipeLineStyle3D != null)
            {
                // 先恢复,再设置
                if (!m_bInitialized || pipeLineStyle3D == null || geoStyle3dOld == null)
                {
                    if (headJointParam == null)
                    {
                        headJointParam = new GSOPipeJointParam();
                    }

                    if (float.TryParse(tBoxHeadDecValue.Text, out fValue))
                    {
                        if (!(fValue < 0))
                        {
                            headJointParam.Extent          = -fValue;
                            pipeLineStyle3D.HeadJointParam = headJointParam;
                        }
                    }

                    if (headJointParam != null && headJointParam.Extent < 0)
                    {
                        //pipeLineStyle3D.HeadJointParam = null;
                        headJointParam = null;
                    }
                    return;
                }
                headJointParam = geoStyle3dOld.HeadJointParam;
                // 先恢复一下
                if (geoStyle3dOld.HeadJointParam == null)
                {
                    pipeLineStyle3D.HeadJointParam = null;
                }
                else
                {
                    pipeLineStyle3D.HeadJointParam = geoStyle3dOld.HeadJointParam;
                }


                if (headJointParam == null)
                {
                    headJointParam = new GSOPipeJointParam();
                }
                //float fValue = 0;
                if (float.TryParse(tBoxHeadDecValue.Text, out fValue))
                {
                    if (!(fValue < 0))
                    {
                        headJointParam.Extent          = -fValue;
                        pipeLineStyle3D.HeadJointParam = headJointParam;
                    }
                }

                if (headJointParam != null && headJointParam.Extent < 0)
                {
                    //pipeLineStyle3D.HeadJointParam = null;
                    headJointParam = null;
                }
            }
        }
        private void btnCreateModel_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtModelLayer.Text))
                {
                    MessageBox.Show("kml文件路径无效!", "提示");
                    return;
                }
                if (File.Exists(txtModelLayer.Text))
                {
                    MessageBox.Show("kml文件已存在!", "提示");
                    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();

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

                        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     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 comboBoxLayers_TextChanged(object sender, EventArgs e)
        {
            string layerName = comboBoxLayers.Text;

            if (layerName.Trim().Equals(""))
            {
                return;
            }
            GSOLayer layer = mGlobeControl.Globe.Layers.GetLayerByCaption(layerName);

            if (layer == null)
            {
                return;
            }
            //清空上一个图层的style
            textBoxIconPath.Text = "";

            textBoxLineColor.BackColor = this.BackColor;
            textBoxLineWidth.Text      = "";

            textBoxOutlineColor.BackColor = this.BackColor;
            textBoxPolygonColor.BackColor = this.BackColor;
            textBoxOutlineWidth.Text      = "";
            textBoxPolygonAlpha.Text      = "";

            bool        markerExists  = false;
            bool        lineExists    = false;
            bool        polygonExists = false;
            GSOFeatures features      = GetAllRealFeatures(layer);

            for (int i = 0; i < features.Length; i++)
            {
                GSOFeature feature = features[i];
                if (feature == null)
                {
                    continue;
                }

                if (feature.Geometry != null)
                {
                    switch (feature.Geometry.Type)
                    {
                    case EnumGeometryType.GeoMarker:
                        if (!markerExists)
                        {
                            GSOGeoMarker marker = (GSOGeoMarker)feature.Geometry;

                            GSOMarkerStyle3D style = (GSOMarkerStyle3D)marker.Style;
                            if (style != null)
                            {
                                textBoxIconPath.Text = style.IconPath;
                                checkBoxHideLabelOfMarker.Checked = !style.TextVisible;
                                markerExists = true;
                            }
                        }
                        break;

                    case EnumGeometryType.GeoPolyline3D:
                        if (!lineExists)
                        {
                            GSOGeoPolyline3D line = (GSOGeoPolyline3D)feature.Geometry;
                            if (line.Label != null)
                            {
                                checkBoxHideLabelOfPolygon.Checked = !line.Label.Visible;
                            }
                            if (line.Style != null)
                            {
                                GSOSimpleLineStyle3D simpleLineStyle = (GSOSimpleLineStyle3D)line.Style;
                                if (simpleLineStyle != null)
                                {
                                    textBoxLineColor.BackColor = simpleLineStyle.LineColor;
                                    textBoxLineWidth.Text      = (simpleLineStyle.LineWidth == 0 ? "1".ToString() : simpleLineStyle.LineWidth.ToString());
                                    lineExists = true;
                                }
                                else
                                {
                                    GSOPipeLineStyle3D pipeLineStyle = (GSOPipeLineStyle3D)line.Style;
                                    if (pipeLineStyle != null)
                                    {
                                        textBoxLineColor.BackColor = pipeLineStyle.LineColor;
                                        textBoxLineWidth.Text      = (pipeLineStyle.Radius * 2).ToString();
                                        lineExists = true;
                                    }
                                }
                            }
                        }
                        break;

                    case EnumGeometryType.GeoPolygon3D:
                        if (!polygonExists)
                        {
                            GSOGeoPolygon3D polygon = (GSOGeoPolygon3D)feature.Geometry;
                            if (polygon.Label != null)
                            {
                                checkBoxHideLabelOfLine.Checked = !polygon.Label.Visible;
                            }
                            GSOSimplePolygonStyle3D stylePolygon = (GSOSimplePolygonStyle3D)polygon.Style;

                            if (stylePolygon != null)
                            {
                                textBoxPolygonColor.BackColor = Color.FromArgb(stylePolygon.FillColor.R, stylePolygon.FillColor.G, stylePolygon.FillColor.B);
                                textBoxPolygonAlpha.Text      = stylePolygon.FillColor.A.ToString();
                                GSOSimpleLineStyle3D styleOutline = (GSOSimpleLineStyle3D)stylePolygon.OutlineStyle;
                                if (styleOutline != null)
                                {
                                    textBoxOutlineColor.BackColor = styleOutline.LineColor;
                                    textBoxOutlineWidth.Text      = (styleOutline.LineWidth == 0 ? "1".ToString() : styleOutline.LineWidth.ToString());
                                }
                                polygonExists = true;
                            }
                        }
                        break;
                    }
                }
            }
        }
        //开始查询
        private void btn_Apply_Click(object sender, EventArgs e)
        {
            string caption = cbox_Layers.Text;
            if (caption == "")
            {
                MessageBox.Show("请先添加图层","提示");
                return;
            }
            GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(caption);
            if (layer == null)
            {
                return;
            }

            if (!checkBox1.Checked)
            {
                GSOFeatures features = layer.GetAllFeatures();
                for (int i = 0; i < features.Length; i++)
                {
                    GSOFeature newfeature = features[i];

                    GSOGeoPolyline3D line = newfeature.Geometry as GSOGeoPolyline3D;
                    if (line == null)
                    {
                        continue;
                    }
                    GSOPipeLineStyle3D pipeLineStyle = line.Style as GSOPipeLineStyle3D;

                    // 管线暂不支持依地模式

                    if (pipeLineStyle == null)
                    {
                        pipeLineStyle = new GSOPipeLineStyle3D();
                    }

                    pipeLineStyle.LineColor = buttonPipelineColor.BackColor;
                    line.Style = pipeLineStyle;
                }
            }
            else
            {
                string sql = "select * from " + cbox_Layers.Text.Trim();
                if (textBox_WhereClause.Text != "")
                {
                    sql += " where " + textBox_WhereClause.Text;
                    try
                    {
                        if (layer.Dataset == null || layer.Dataset.DataSource == null
                            || (layer.Dataset.DataSource.Type != EnumDataSourceType.SqlServer && layer.Dataset.DataSource.Type != EnumDataSourceType.Oracle))
                        {
                            return ;
                        }
                        DatabaseConnectParams connectParams = Utility.getConnectParamsByDatasourceName(globeControl1, layer.Dataset.DataSource.Name);
                        if (connectParams == null)
                        {
                            return ;
                        }
                        DataTable table = OledbHelper.QueryTable(sql, connectParams);
                        if (table == null)
                        {
                            return ;
                        }

                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            int id = Convert.ToInt32(table.Rows[i]["LSSYS_ID"]);
                            GSOFeature newfeature = layer.GetFeatureByID(id);

                            GSOGeoPolyline3D line = newfeature.Geometry as GSOGeoPolyline3D;
                            if (line == null)
                            {
                                continue;
                            }
                            GSOPipeLineStyle3D pipeLineStyle = line.Style as GSOPipeLineStyle3D;

                            // 管线暂不支持依地模式
                            if (pipeLineStyle == null)
                            {
                                pipeLineStyle = new GSOPipeLineStyle3D();
                            }
                            pipeLineStyle.LineColor = buttonPipelineColor.BackColor;
                            line.Style = pipeLineStyle;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.PublishTxt(ex);
                        MessageBox.Show(ex.Message, "提示");
                        return ;
                    }
                }
            }

            globeControl1.Refresh();
            return ;
        }
        //开始查询
        private void btn_Apply_Click(object sender, EventArgs e)
        {
            string caption = cbox_Layers.Text;

            if (caption == "")
            {
                MessageBox.Show("请先添加图层", "提示");
                return;
            }
            GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(caption);

            if (layer == null)
            {
                return;
            }

            if (!checkBox1.Checked)
            {
                GSOFeatures features = layer.GetAllFeatures();
                for (int i = 0; i < features.Length; i++)
                {
                    GSOFeature newfeature = features[i];

                    GSOGeoPolyline3D line = newfeature.Geometry as GSOGeoPolyline3D;
                    if (line == null)
                    {
                        continue;
                    }
                    GSOPipeLineStyle3D pipeLineStyle = line.Style as GSOPipeLineStyle3D;


                    // 管线暂不支持依地模式

                    if (pipeLineStyle == null)
                    {
                        pipeLineStyle = new GSOPipeLineStyle3D();
                    }

                    pipeLineStyle.LineColor = buttonPipelineColor.BackColor;
                    line.Style = pipeLineStyle;
                }
            }
            else
            {
                string sql = "select * from " + cbox_Layers.Text.Trim();
                if (textBox_WhereClause.Text != "")
                {
                    sql += " where " + textBox_WhereClause.Text;
                    try
                    {
                        if (layer.Dataset == null || layer.Dataset.DataSource == null ||
                            (layer.Dataset.DataSource.Type != EnumDataSourceType.SqlServer && layer.Dataset.DataSource.Type != EnumDataSourceType.Oracle))
                        {
                            return;
                        }
                        DatabaseConnectParams connectParams = Utility.getConnectParamsByDatasourceName(globeControl1, layer.Dataset.DataSource.Name);
                        if (connectParams == null)
                        {
                            return;
                        }
                        DataTable table = OledbHelper.QueryTable(sql, connectParams);
                        if (table == null)
                        {
                            return;
                        }

                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            int        id         = Convert.ToInt32(table.Rows[i]["LSSYS_ID"]);
                            GSOFeature newfeature = layer.GetFeatureByID(id);

                            GSOGeoPolyline3D line = newfeature.Geometry as GSOGeoPolyline3D;
                            if (line == null)
                            {
                                continue;
                            }
                            GSOPipeLineStyle3D pipeLineStyle = line.Style as GSOPipeLineStyle3D;

                            // 管线暂不支持依地模式
                            if (pipeLineStyle == null)
                            {
                                pipeLineStyle = new GSOPipeLineStyle3D();
                            }
                            pipeLineStyle.LineColor = buttonPipelineColor.BackColor;
                            line.Style = pipeLineStyle;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.PublishTxt(ex);
                        MessageBox.Show(ex.Message, "提示");
                        return;
                    }
                }
            }

            globeControl1.Refresh();
            return;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (comboBoxLayers.Text == "")
            {
                MessageBox.Show("请选择一个图层!");
                return;
            }
            GSOLayer layer = mGlobeControl.Globe.Layers.GetLayerByCaption(comboBoxLayers.Text.Trim());

            if (layer == null)
            {
                MessageBox.Show("您选择的图层不存在!");
                return;
            }

            string iconPath = textBoxIconPath.Text.Trim();

            if (iconPath == "")
            {
                iconPath = Application.StartupPath + "\\Resource\\DefaultIcon.png";
            }

            Color  lineColor     = textBoxLineColor.BackColor;
            string strLineWidth  = textBoxLineWidth.Text.Trim();
            double lineWidth     = 1;
            bool   blIsLineWidth = double.TryParse(strLineWidth, out lineWidth);

            Color  outlineColor     = textBoxOutlineColor.BackColor;
            string strOutlineWidth  = textBoxOutlineWidth.Text.Trim();
            double outlineWidth     = 1;
            bool   blIsOutlineWidth = double.TryParse(strOutlineWidth, out outlineWidth);
            Color  polygonColor     = textBoxPolygonColor.BackColor;
            string strPolygonAlpha  = textBoxPolygonAlpha.Text.Trim();
            int    polygonAlpha     = 255;
            bool   blIsPolygonAlpha = int.TryParse(strPolygonAlpha, out polygonAlpha);

            polygonColor = Color.FromArgb(polygonAlpha, polygonColor);

            for (int i = 0; i < layer.GetAllFeatures().Length; i++)
            {
                GSOFeature feature = layer.GetAt(i);
                if (feature.Geometry != null)
                {
                    switch (feature.Geometry.Type)
                    {
                    case EnumGeometryType.GeoPoint3D:
                        if (panelPoints.Enabled)
                        {
                            GSOGeoPoint3D point  = (GSOGeoPoint3D)feature.Geometry;
                            GSOGeoMarker  marker = new GSOGeoMarker();
                            marker.Position    = point.Position;
                            marker.Name        = point.Name;
                            marker.CameraState = point.CameraState;
                            marker.Label       = point.Label;

                            GSOFeature newFeature = new GSOFeature();
                            newFeature.Name     = feature.Name;
                            newFeature.Geometry = marker;

                            layer.RemoveAt(i);
                            layer.AddFeature(newFeature);
                            i--;
                        }
                        break;

                    case EnumGeometryType.GeoMarker:
                        if (panelPoints.Enabled)
                        {
                            GSOGeoMarker     marker = (GSOGeoMarker)feature.Geometry;
                            GSOMarkerStyle3D style  = null;

                            if (marker.Style == null)
                            {
                                style = new GSOMarkerStyle3D();
                            }
                            else
                            {
                                style = (GSOMarkerStyle3D)marker.Style;
                            }

                            style.TextVisible = !checkBoxHideLabelOfMarker.Checked;
                            style.IconPath    = iconPath.Trim();

                            marker.Style = style;
                        }
                        break;

                    case EnumGeometryType.GeoPolyline3D:
                        if (panelLines.Enabled)
                        {
                            GSOGeoPolyline3D line = (GSOGeoPolyline3D)feature.Geometry;
                            if (line.Label != null)
                            {
                                line.Label.Visible = !checkBoxHideLabelOfLine.Checked;
                            }
                            if (line.Style == null)
                            {
                                GSOSimpleLineStyle3D styleLine = new GSOSimpleLineStyle3D();
                                styleLine.LineColor = lineColor;
                                styleLine.LineWidth = lineWidth;
                                line.Style          = styleLine;
                            }
                            else
                            {
                                GSOSimpleLineStyle3D styleLine = (GSOSimpleLineStyle3D)line.Style;
                                if (styleLine == null)
                                {
                                    GSOPipeLineStyle3D pipeStyle = (GSOPipeLineStyle3D)line.Style;
                                    if (pipeStyle != null)
                                    {
                                        pipeStyle.LineColor = lineColor;
                                        pipeStyle.Radius    = lineWidth / 2;
                                        line.Style          = pipeStyle;
                                    }
                                }
                                else
                                {
                                    styleLine.LineColor = lineColor;
                                    styleLine.LineWidth = lineWidth;
                                    line.Style          = styleLine;
                                }
                            }
                        }
                        break;

                    case EnumGeometryType.GeoPolygon3D:
                        if (panelPolygons.Enabled)
                        {
                            GSOGeoPolygon3D polygon = (GSOGeoPolygon3D)feature.Geometry;
                            if (polygon.Label != null)
                            {
                                polygon.Label.Visible = !checkBoxHideLabelOfPolygon.Checked;
                            }
                            GSOSimplePolygonStyle3D stylePolygon = (polygon.Style == null ? new GSOSimplePolygonStyle3D() : (GSOSimplePolygonStyle3D)polygon.Style);
                            stylePolygon.FillColor      = polygonColor;
                            stylePolygon.OutLineVisible = true;
                            GSOSimpleLineStyle3D styleOutline = (GSOSimpleLineStyle3D)stylePolygon.OutlineStyle;
                            if (styleOutline == null)
                            {
                                styleOutline = new GSOSimpleLineStyle3D();
                            }
                            styleOutline.LineWidth    = outlineWidth;
                            styleOutline.LineColor    = outlineColor;
                            stylePolygon.OutlineStyle = styleOutline;
                            polygon.Style             = stylePolygon;
                        }
                        break;
                    }
                }
            }
            mGlobeControl.Globe.Refresh();
            this.Close();
        }
        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 ShpSourceLayer = ctl.Globe.Layers[cmbLayer.SelectedIndex];

                GSOLayer pipeModelLayer = ctl.Globe.Layers.Add(txtModelLayer.Text);

                string   pipeRectFile = Path.GetDirectoryName(txtModelLayer.Text) + "\\" + Path.GetFileNameWithoutExtension(txtModelLayer.Text) + "_Rect" + Path.GetExtension(txtModelLayer.Text);
                GSOLayer layer_Rect   = ctl.Globe.Layers.Add(pipeRectFile);
                lgdFilePath = txtModelLayer.Text;

                if (pipeModelLayer != null)
                {
                    GSOFeatures features = ShpSourceLayer.GetAllFeatures();
                    string      message  = "";
                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOFeature newFeature = new GSOFeature();

                        GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                        style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                        double       radius        = 0;
                        GSOFieldDefn diameterfield = (GSOFieldDefn)f.GetFieldDefn(cmbRadius.SelectedItem.ToString());
                        if (diameterfield.Type == EnumFieldType.Text)
                        {
                            radius = Convert.ToDouble(f.GetFieldAsString(cmbRadius.SelectedItem.ToString())) / 2000;
                        }
                        else
                        {
                            radius = f.GetFieldAsDouble(cmbRadius.SelectedItem.ToString()) / 2000;  // 探测数据的单位一般是毫米,需换算为米; 管径一般是 直径, 这个需要半径, 所有除以2000
                        }

                        string eventid    = f.GetFieldAsString(cmbID.SelectedItem.ToString());
                        int    num_width  = f.GetFieldAsInt32(cmbWidthNum.SelectedItem.ToString());
                        int    num_height = f.GetFieldAsInt32(cmbHeightNum.SelectedItem.ToString());
                        double interval   = radius * 2;                    //  f.GetFieldAsDouble(cmbInterval.SelectedItem.ToString());
                        double rectWidth  = radius * 2 * num_width + 0.08; // 两端空出0.04
                        double rectHeight = radius * 2 * num_height + 0.08;
                        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)
                        {
                            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;
                        }

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

                            if (double.IsInfinity(pt3d.Z))
                            {
                                pt3d.Z = deep2;
                            }
                            line[0][n] = pt3d;
                        }
                        if (num_height == 0 || num_width == 0)  // 直埋
                        {
                            newFeature.Geometry       = line;
                            newFeature.Geometry.Style = style;
                            newFeature.Name           = eventid;
                            pipeModelLayer.AddFeature(newFeature);
                        }
                        else
                        {
                            GSOFeature rectfeat = CreatePipeRect(f, line, rectWidth, rectHeight);
                            if (rectfeat != null)
                            {
                                layer_Rect.AddFeature(rectfeat);
                            }
                            one2Multi(line, num_width, num_height, interval, style, pipeModelLayer, eventid);
                        }
                    }
                    ctl.Refresh();

                    pipeModelLayer.Save();
                    layer_Rect.Save();
                    string strMessage = "shp文件中共" + features.Length + "个对象,实际生成" + (pipeModelLayer.GetAllFeatures().Length + layer_Rect.GetAllFeatures().Length) + "个对象!\n";
                    MessageBox.Show(strMessage + message, "提示");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
Example #39
0
        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();

                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOFeature newFeature = new GSOFeature();

                        GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                        style.LineColor = Color.FromArgb(Convert.ToByte(numericUpDownLineOpaque.Value), btnPipelineColor.BackColor);

                        double radius = f.GetFieldAsDouble(cmbRadius.SelectedIndex) / 1000;  // 单位
                        string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString());

                        style.Radius = radius;
                        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;
                             deep2 = deep2 + radius;
                         }
                         else if (cmbReference.SelectedIndex == 1) //管顶
                         {
                             deep1 = deep1 - radius;
                             deep2 = deep2 - radius;
                         }
                         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;
                        //newFeature.CustomID = f.ID;
                        layer.AddFeature(newFeature);
                    }
                }
                ctl.Refresh();

                layer.Save();

                ctl.Globe.Layers.Remove(layer);
                this.Close();
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
Example #40
0
        private void one2Multi(GSOGeoPolyline3D line, int num_width, int num_height, double interval, GSOPipeLineStyle3D style, GSOLayer layer,string name)
        {
            line = LatLon2Coord_Line(line);

            double width_all = interval * (num_width-1);
            double height_all = interval * (num_height-1);

            line.Clone();
            GSOGeoPolyline3D line_1 = line.Clone() as GSOGeoPolyline3D;

            GSOPoint3d p1 = line[0][0];
            GSOPoint3d p2 = line[0][1];

            double daltaX = p2.X-p1.X;
            double daltaY = p2.Y-p1.Y;

            double agree = Math.Atan(daltaY/daltaX);

            line.MoveXY((-0.5*width_all-interval)*Math.Sin(agree),(0.5*width_all+interval)*Math.Cos(agree));

            line.MoveZ(height_all / -2);

            for (int i = 0; i < num_width; i++)
            {
                for (int j = 0; j < num_height; j++)
                {
                    GSOGeoPolyline3D templine = line.Clone() as GSOGeoPolyline3D;

                    templine.MoveXY((i + 1) * interval * Math.Sin(agree), -1 * (i + 1) * interval * Math.Cos(agree));

                    templine = Coord2LatLon_Line(templine);

                    templine.MoveZ(interval*j);

                    GSOFeature feat = new GSOFeature();
                    feat.Geometry = templine;
                    feat.Geometry.Style = style;
                    feat.Name = name;
                    layer.AddFeature(feat);
                }
            }
        }
Example #41
0
        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 void btnCreateModel_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtModelLayer.Text))
                {
                    MessageBox.Show("kml文件路径无效!", "提示");
                    return;
                }
                if (File.Exists(txtModelLayer.Text))
                {
                    MessageBox.Show("kml文件已存在!", "提示");
                    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();

                        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

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

                        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 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);
            }
        }
Example #43
0
        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);
            }
        }