Example #1
0
        private void SetControlsByStyle(GSOStyle style)
        {
            if (m_Style != null)
            {
                extentSectionLineStyle3D = m_Style as GSOExtendSectionLineStyle3D;
                if (extentSectionLineStyle3D == null)
                {
                    extentSectionLineStyle3D           = new GSOExtendSectionLineStyle3D();
                    extentSectionLineStyle3D.LineColor = Color.Green;
                    GSOPoint3ds points = new GSOPoint3ds();
                    points.Add(new GSOPoint3d(-0.5, 0.5, 0));
                    points.Add(new GSOPoint3d(-0.5, -0.5, 0));
                    points.Add(new GSOPoint3d(0.5, -0.5, 0));
                    points.Add(new GSOPoint3d(0.5, 0.5, 0));
                    extentSectionLineStyle3D.SetSectionPoints(points);
                    RefreshGlobe(extentSectionLineStyle3D);
                }
            }
            else
            {
                extentSectionLineStyle3D           = new GSOExtendSectionLineStyle3D();
                extentSectionLineStyle3D.LineColor = Color.Green;
                GSOPoint3ds points = new GSOPoint3ds();
                points.Add(new GSOPoint3d(-0.5, 0.5, 0));
                points.Add(new GSOPoint3d(-0.5, -0.5, 0));
                points.Add(new GSOPoint3d(0.5, -0.5, 0));
                points.Add(new GSOPoint3d(0.5, 0.5, 0));
                extentSectionLineStyle3D.SetSectionPoints(points);
                RefreshGlobe(extentSectionLineStyle3D);
            }
            // 这句要写到前面,不然下面Checked的时候要检查
            pictureBoxLineColor.BackColor = extentSectionLineStyle3D.LineColor;
            numericUpDownLineOpaque.Value = extentSectionLineStyle3D.LineColor.A;

            textBoxCornerSliceAngle.Text = extentSectionLineStyle3D.CornerSliceAngle.ToString();
            GSOPoint3ds mpoints = extentSectionLineStyle3D.GetSectionPoints();

            if (mpoints != null && mpoints.Count > 0)
            {
                for (int i = 0; i < mpoints.Count; i++)
                {
                    GSOPoint3d point = mpoints[i];
                    if (point != null)
                    {
                        textBoxLineRadius.Text = (Math.Abs(point.X) * 2).ToString();
                        textBoxThickness.Text  = (Math.Abs(point.Y) * 2).ToString();
                        break;
                    }
                }
            }

            m_bInitialized = true;
        }
Example #2
0
        private void textBoxLineRadius_TextChanged(object sender, EventArgs e)
        {
            if (extentSectionLineStyle3D != null)
            {
                try
                {
                    double width = 0.0;
                    if (textBoxLineRadius.Text.Trim() == "" || double.TryParse(textBoxLineRadius.Text, out width) == false)
                    {
                        return;
                    }
                    m_GlobeControl.Globe.AddToEditHistroy(mlayer, mfeature, EnumEditType.Modify);

                    GSOPoint3ds points = extentSectionLineStyle3D.GetSectionPoints();
                    for (int i = 0; i < points.Count; i++)
                    {
                        GSOPoint3d point = points[i];
                        if (point != null)
                        {
                            if (point.X > 0)
                            {
                                point.X = width / 2;
                            }
                            else
                            {
                                point.X = -width / 2;
                            }
                        }
                        points[i] = point;
                    }
                    extentSectionLineStyle3D.SetSectionPoints(points);
                    RefreshGlobe(extentSectionLineStyle3D);
                }
                catch (System.Exception exp)
                {
                    Log.PublishTxt(exp);
                }
            }
        }
        private GSOExtendSectionLineStyle3D createRectStyle(double width, double height)
        {
            GSOExtendSectionLineStyle3D style = new GSOExtendSectionLineStyle3D();

            style.LineColor = Color.FromArgb(Convert.ToByte(numOpaqueRect.Value), btnRectColor.BackColor);
            if (width == 0 || height == 0)
            {
                return(null);
            }
            GSOPoint3ds sectionpts = new GSOPoint3ds();

            sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0));
            sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0));
            sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0));
            sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0));

            style.SetSectionPoints(sectionpts);
            style.IsClosed = true;
            style.SetAnchorByAlign(EnumAlign.MiddleCenter);

            return(style);
        }
        private void btnCreateModel_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtModelLayer.Text))
                {
                    MessageBox.Show("管线模型文件路径无效!", "提示");
                    return;
                }
                if (File.Exists(txtModelLayer.Text))
                {
                    MessageBox.Show("管线模型文件已存在!", "提示");
                    return;
                }

                GSOLayer sourceLayer = ctl.Globe.Layers[cmbLayer.SelectedIndex];

                GSOLayer layer = ctl.Globe.Layers.Add(txtModelLayer.Text);
                lgdFilePath = txtModelLayer.Text;
                if (layer != null)
                {
                    GSOFeatures features = sourceLayer.GetAllFeatures();
                    string message = "";
                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOFeature newFeature = new GSOFeature();

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

                        double width = 0;
                        GSOFieldDefn field = (GSOFieldDefn)(f.GetFieldDefn(cmbWidth.SelectedItem.ToString()));
                        if (field.Type == EnumFieldType.Text)
                        {
                            string temp = f.GetFieldAsString(cmbWidth.SelectedItem.ToString());
                            double outNum = 0;
                            bool num = double.TryParse(temp, out outNum);
                            if (num)
                                width = outNum;

                        }
                        else if (field.Type == EnumFieldType.Double)
                            width = f.GetFieldAsDouble(cmbWidth.SelectedItem.ToString());

                        double height = 0;
                        field = (GSOFieldDefn)(f.GetFieldDefn(cmbHeight.SelectedItem.ToString()));
                        if (field.Type == EnumFieldType.Text)
                        {
                            string temp = f.GetFieldAsString(cmbHeight.SelectedItem.ToString());
                            double outNum = 0;
                            bool num = double.TryParse(temp, out outNum);
                            if (num)
                                height = outNum;

                        }
                        else if (field.Type == EnumFieldType.Double)
                            height = f.GetFieldAsDouble(cmbHeight.SelectedItem.ToString());

                        string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString());

                        if (width == 0 || height == 0)
                        {
                            message += "ID为" + f.ID + "的对象的沟宽或者沟高字段的值为0 \n";
                            continue;
                        }
                        GSOPoint3ds sectionpts = new GSOPoint3ds();
                        sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0));
                        sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0));
                        sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0));
                        sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0));

                        style.SetSectionPoints(sectionpts);
                        style.IsClosed = false;
                        style.SetAnchorByAlign(EnumAlign.BottomCenter);

                        f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                        GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D;
                        if (line == null)
                        {
                            message += "ID为" + f.ID + "的对象不是线对象 \n";
                            continue;
                        }
                        double deep1 = f.GetFieldAsDouble(cmbFrom.SelectedItem.ToString());
                        double deep2 = f.GetFieldAsDouble(cmbTo.SelectedItem.ToString());

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

                        for (int n = 0; n < line[0].Count; n++)
                        {
                            GSOPoint3d pt3d = line[0][n];
                            int pointcount = line[0].Count;
                            double radio = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2));
                            pt3d.Z = deep1 + (deep2 - deep1) * radio;
                            line[0][n] = pt3d;
                        }

                        newFeature.Geometry = line; // f.Geometry;
                        newFeature.Geometry.Style = style;
                        newFeature.Name = eventid;
                        layer.AddFeature(newFeature);
                    }
                    ctl.Refresh();
                    layer.Save();
                    ctl.Globe.Layers.Remove(layer);
                    string strMessage = "shp文件中共" + features.Length + "个对象,实际生成" + layer.GetAllFeatures().Length + "个对象!\n";
                    MessageBox.Show(strMessage + message, "提示");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
Example #5
0
        private GSOExtendSectionLineStyle3D createRectStyle(double width, double height)
        {
            GSOExtendSectionLineStyle3D style = new GSOExtendSectionLineStyle3D();
            style.LineColor = Color.FromArgb(Convert.ToByte(numOpaqueRect.Value), btnRectColor.BackColor);

            if (width == 0 || height == 0)
                return null;

            GSOPoint3ds sectionpts = new GSOPoint3ds();
            sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0));
            sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0));
            sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0));
            sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0));

            style.SetSectionPoints(sectionpts);
            style.IsClosed = true;
            style.SetAnchorByAlign(EnumAlign.MiddleCenter);

            return style;
        }
Example #6
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 SetControlsByStyle(GSOStyle style)
        {
            if (m_Style != null)
            {
                extentSectionLineStyle3D = m_Style as GSOExtendSectionLineStyle3D;
                if (extentSectionLineStyle3D == null)
                {
                    extentSectionLineStyle3D = new GSOExtendSectionLineStyle3D();
                    extentSectionLineStyle3D.LineColor = Color.Green;
                    GSOPoint3ds points = new GSOPoint3ds();
                    points.Add(new GSOPoint3d(-0.5, 0.5, 0));
                    points.Add(new GSOPoint3d(-0.5, -0.5, 0));
                    points.Add(new GSOPoint3d(0.5, -0.5, 0));
                    points.Add(new GSOPoint3d(0.5, 0.5, 0));
                    extentSectionLineStyle3D.SetSectionPoints(points);
                    RefreshGlobe(extentSectionLineStyle3D);
                }
            }
            else
            {
                extentSectionLineStyle3D = new GSOExtendSectionLineStyle3D();
                extentSectionLineStyle3D.LineColor = Color.Green;
                GSOPoint3ds points = new GSOPoint3ds();
                points.Add(new GSOPoint3d(-0.5, 0.5, 0));
                points.Add(new GSOPoint3d(-0.5, -0.5, 0));
                points.Add(new GSOPoint3d(0.5,- 0.5, 0));
                points.Add(new GSOPoint3d(0.5, 0.5, 0));
                extentSectionLineStyle3D.SetSectionPoints(points);
                RefreshGlobe(extentSectionLineStyle3D);
            }
            // 这句要写到前面,不然下面Checked的时候要检查
            pictureBoxLineColor.BackColor = extentSectionLineStyle3D.LineColor;
            numericUpDownLineOpaque.Value = extentSectionLineStyle3D.LineColor.A;

            textBoxCornerSliceAngle.Text = extentSectionLineStyle3D.CornerSliceAngle.ToString();
            GSOPoint3ds mpoints = extentSectionLineStyle3D.GetSectionPoints();
            if (mpoints != null && mpoints.Count > 0)
            {
                for (int i = 0; i < mpoints.Count; i++)
                {
                    GSOPoint3d point = mpoints[i];
                    if (point != null)
                    {
                        textBoxLineRadius.Text = (Math.Abs(point.X) * 2).ToString();
                        textBoxThickness.Text = (Math.Abs(point.Y) * 2).ToString();
                        break;
                    }
                }
            }

            m_bInitialized = true;
        }
Example #8
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("管线模型文件路径无效!", "提示");
                    return;
                }
                if (File.Exists(txtModelLayer.Text))
                {
                    MessageBox.Show("管线模型文件已存在!", "提示");
                    return;
                }

                GSOLayer sourceLayer = ctl.Globe.Layers[cmbLayer.SelectedIndex];

                GSOLayer layer = ctl.Globe.Layers.Add(txtModelLayer.Text);
                lgdFilePath = txtModelLayer.Text;
                if (layer != null)
                {
                    GSOFeatures features = sourceLayer.GetAllFeatures();
                    string      message  = "";
                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature f = features[j];

                        GSOFeature newFeature = new GSOFeature();

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

                        double       width = 0;
                        GSOFieldDefn field = (GSOFieldDefn)(f.GetFieldDefn(cmbWidth.SelectedItem.ToString()));
                        if (field.Type == EnumFieldType.Text)
                        {
                            string temp   = f.GetFieldAsString(cmbWidth.SelectedItem.ToString());
                            double outNum = 0;
                            bool   num    = double.TryParse(temp, out outNum);
                            if (num)
                            {
                                width = outNum;
                            }
                        }
                        else if (field.Type == EnumFieldType.Double)
                        {
                            width = f.GetFieldAsDouble(cmbWidth.SelectedItem.ToString());
                        }


                        double height = 0;
                        field = (GSOFieldDefn)(f.GetFieldDefn(cmbHeight.SelectedItem.ToString()));
                        if (field.Type == EnumFieldType.Text)
                        {
                            string temp   = f.GetFieldAsString(cmbHeight.SelectedItem.ToString());
                            double outNum = 0;
                            bool   num    = double.TryParse(temp, out outNum);
                            if (num)
                            {
                                height = outNum;
                            }
                        }
                        else if (field.Type == EnumFieldType.Double)
                        {
                            height = f.GetFieldAsDouble(cmbHeight.SelectedItem.ToString());
                        }

                        string eventid = f.GetFieldAsString(cmbID.SelectedItem.ToString());

                        if (width == 0 || height == 0)
                        {
                            message += "ID为" + f.ID + "的对象的沟宽或者沟高字段的值为0 \n";
                            continue;
                        }
                        GSOPoint3ds sectionpts = new GSOPoint3ds();
                        sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0));
                        sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0));
                        sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0));
                        sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0));

                        style.SetSectionPoints(sectionpts);
                        style.IsClosed = false;
                        style.SetAnchorByAlign(EnumAlign.BottomCenter);

                        f.Geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                        GSOGeoPolyline3D line = f.Geometry as GSOGeoPolyline3D;
                        if (line == null)
                        {
                            message += "ID为" + f.ID + "的对象不是线对象 \n";
                            continue;
                        }
                        double deep1 = f.GetFieldAsDouble(cmbFrom.SelectedItem.ToString());
                        double deep2 = f.GetFieldAsDouble(cmbTo.SelectedItem.ToString());

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

                        for (int n = 0; n < line[0].Count; n++)
                        {
                            GSOPoint3d pt3d       = line[0][n];
                            int        pointcount = line[0].Count;
                            double     radio      = Math.Sqrt(Math.Pow(pt3d.Y - line[0][0].Y, 2) + Math.Pow(pt3d.X - line[0][0].X, 2)) / Math.Sqrt(Math.Pow(line[0][pointcount - 1].Y - line[0][0].Y, 2) + Math.Pow(line[0][pointcount - 1].X - line[0][0].X, 2));
                            pt3d.Z     = deep1 + (deep2 - deep1) * radio;
                            line[0][n] = pt3d;
                        }

                        newFeature.Geometry       = line; // f.Geometry;
                        newFeature.Geometry.Style = style;
                        newFeature.Name           = eventid;
                        layer.AddFeature(newFeature);
                    }
                    ctl.Refresh();
                    layer.Save();
                    ctl.Globe.Layers.Remove(layer);
                    string strMessage = "shp文件中共" + features.Length + "个对象,实际生成" + layer.GetAllFeatures().Length + "个对象!\n";
                    MessageBox.Show(strMessage + message, "提示");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }