private void button1_Click(object sender, EventArgs e)//确定
 {
     if (listBox1.SelectedItems.Count > 0)
     {
         GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());
         if (ds != null)
         {
             DateTime timeStart = DateTime.Now;
             for (int i = 0; i < listBox1.SelectedItems.Count; i++)
             {
                 GSODataset dataset = ds.GetDatasetByName(listBox1.SelectedItems[i].ToString().Trim());
                 if (dataset != null)
                 {
                     dataset.Caption = dataset.Name;
                     GSOLayer layer = globeControl1.Globe.Layers.Add(dataset);
                     layer.MaxVisibleAltitude = 7000;
                 }
             }
             TimeSpan timeConnect    = DateTime.Now - timeStart;
             double   secondsConnect = timeConnect.TotalSeconds;
             MessageBox.Show("打开" + listBox1.SelectedItems.Count.ToString() + "个图层, 用时" + secondsConnect.ToString() + "秒", "提示");
             this.Close();
         }
     }
 }
Exemple #2
0
 private void cbbLayers_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (comboBoxDBLayerList.SelectedItem != null && comboBoxDataSourceList.SelectedItem != null)
     {
         GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());
         if (ds != null)
         {
             GSODataset dataset = ds.GetDatasetByName(comboBoxDBLayerList.SelectedItem.ToString().Trim());
             if (dataset != null)
             {
                 textBoxTopoName.Text = dataset.Name + "Network";
             }
         }
     }
 }
        private void Set()
        {
            if (listBoxCopyLayerList.SelectedItems.Count <= 0)
            {
                MessageBox.Show("请选择要复制的数据集!", "提示");
                return;
            }
            if (comboBoxTargetDataSource.SelectedItem == null)
            {
                MessageBox.Show("请选择目标数据源!", "提示");
                return;
            }
            if (checkBoxCopyOne.Checked == true && textboxNewLayerName.Text.Trim() == "")
            {
                MessageBox.Show("请给要复制的数据集命名!", "提示");
                return;
            }
            if (checkBoxCopyOne.Checked == true)
            {
                GSODataSource dsTarget = Utility.getDataSourceByFullName(globeControl1, comboBoxTargetDataSource.SelectedItem.ToString().Trim());
                if (dsTarget != null)
                {
                    GSODataset newDataset = dsTarget.GetDatasetByName(textboxNewLayerName.Text.Trim());
                    if (newDataset != null)
                    {
                        MessageBox.Show("输入的新的数据集的名称已存在目标数据源中!", "提示");
                        return;
                    }
                    GSOFeatureDataset newFeatureDataset = dsTarget.CreateFeatureDataset(textboxNewLayerName.Text.Trim());
                    if (newFeatureDataset == null)
                    {
                        MessageBox.Show("输入的新数据集的名称不符合要求!", "提示");
                        return;
                    }
                    GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());
                    if (ds != null)
                    {
                        GSODataset        dataset        = ds.GetDatasetByName(listBoxCopyLayerList.SelectedItem.ToString().Trim());
                        GSOFeatureDataset featureDataset = dataset as GSOFeatureDataset;
                        if (featureDataset != null)
                        {
                            try
                            {
                                featureDataset.Open();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "提示");
                                if (featureDataset.IsOpened == true)
                                {
                                    featureDataset.Close();
                                }
                                return;
                            }
                            //向新数据集写入字段
                            for (int i = 0; i < featureDataset.FieldCount; i++)
                            {
                                GSOFieldAttr fieldFromDs = featureDataset.GetField(i);
                                newFeatureDataset.AddField(fieldFromDs);
                            }

                            //向新的要素集写入数据
                            for (int i = 0; i < featureDataset.GetAllFeatures().Length; i++)
                            {
                                GSOFeature featureInDs       = featureDataset.GetFeatureAt(i);
                                GSOFeature featureInTargetDs = featureInDs.Clone();
                                featureInDs.Dispose();
                                newFeatureDataset.AddFeature(featureInTargetDs);
                            }
                            newFeatureDataset.Save();
                            featureDataset.Close();
                            MessageBox.Show("复制成功!", "提示");
                        }
                    }
                }
            }
            else if (checkBoxCopyMult.Checked == true)
            {
                GSODataSource dsTarget = Utility.getDataSourceByFullName(globeControl1, comboBoxTargetDataSource.SelectedItem.ToString().Trim());
                if (dsTarget != null)
                {
                    string datasetNames = "";
                    for (int i = 0; i < listBoxCopyLayerList.SelectedItems.Count; i++)
                    {
                        GSODataset datasetInTargetDs = dsTarget.GetDatasetByName(listBoxCopyLayerList.SelectedItems[i].ToString().Trim());
                        if (datasetInTargetDs != null)
                        {
                            datasetNames += "\"" + listBoxCopyLayerList.SelectedItems[i].ToString().Trim() + "\" ";
                        }
                    }
                    if (datasetNames != "")
                    {
                        MessageBox.Show("数据集名称" + datasetNames + "在目标数据源中已存在", "提示");
                        return;
                    }
                    GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());
                    if (ds != null)
                    {
                        progressBar1.Visible = true;
                        progressBar1.Maximum = listBoxCopyLayerList.SelectedItems.Count - 1;
                        progressBar1.Minimum = 0;
                        for (int j = 0; j < listBoxCopyLayerList.SelectedItems.Count; j++)
                        {
                            //获取要复制的要素集
                            GSODataset        datasetInDs        = ds.GetDatasetByName(listBoxCopyLayerList.SelectedItems[j].ToString().Trim());
                            GSOFeatureDataset featureDatasetInDs = datasetInDs as GSOFeatureDataset;
                            if (featureDatasetInDs == null)
                            {
                                continue;
                            }
                            featureDatasetInDs.Open();

                            //创建新的数据库要素集
                            GSOFeatureDataset featureDatasetInTargetDs = dsTarget.CreateFeatureDataset(listBoxCopyLayerList.SelectedItems[j].ToString().Trim());

                            if (featureDatasetInTargetDs == null)
                            {
                                continue;
                            }
                            featureDatasetInTargetDs.Open();
                            for (int i = 0; i < featureDatasetInDs.FieldCount; i++)
                            {
                                GSOFieldAttr fieldInDs = featureDatasetInDs.GetField(i);
                                featureDatasetInTargetDs.AddField(fieldInDs);
                            }

                            //(2)向新的要素集写入数据
                            for (int i = 0; i < featureDatasetInDs.GetAllFeatures().Length; i++)
                            {
                                GSOFeature featureInDs       = featureDatasetInDs.GetFeatureAt(i);
                                GSOFeature featureInTargetDs = featureInDs.Clone();
                                featureInDs.Dispose();
                                featureDatasetInTargetDs.AddFeature(featureInTargetDs);
                            }
                            featureDatasetInTargetDs.Save();
                            featureDatasetInTargetDs.Close();
                            featureDatasetInDs.Close();

                            progressBar1.Value = j;
                        }
                        progressBar1.Visible = false;
                        MessageBox.Show("数据复制成功!", "提示");
                    }
                }
            }
        }
Exemple #4
0
        private void button3_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 (textBoxModelFolder.Text == "")
            {
                return;
            }
            if (comboBoxShpLayerList.SelectedIndex < 0)
            {
                return;
            }
            try
            {
                Regex regNum = new Regex("^[0-9]");

                DirectoryInfo theFolder = new DirectoryInfo(textBoxModelFolder.Text);
                foreach (FileInfo nextFile in theFolder.GetFiles())
                {
                    if (nextFile.Name.ToLower().IndexOf("3ds") > -1 || nextFile.Name.ToLower().IndexOf("gcm") > -1)
                    {
                        files.Add(nextFile.Name);
                        string temp      = nextFile.Name.Substring(nextFile.Name.IndexOf("-") + 1, nextFile.Name.LastIndexOf(".") - nextFile.Name.IndexOf("-") - 1);
                        string modeltype = nextFile.Name.Substring(0, nextFile.Name.IndexOf("-"));
                        modeltypes.Add(modeltype);

                        double Num;
                        bool   isNum = double.TryParse(temp, out Num);

                        if (isNum)
                        {
                            deeps.Add(Convert.ToDouble(temp));
                        }
                    }
                }
                GSODataset        dataset = ds.GetDatasetByName(textBoxNewLayerName.Text.Trim());
                GSOFeatureDataset featdataset;
                if (dataset != null)
                {
                    DialogResult result = MessageBox.Show("工井图层名称在数据库中已存在!是否向该表追加", "提示", MessageBoxButtons.YesNo);
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                    else if (result == DialogResult.Yes)
                    {
                        featdataset = dataset as GSOFeatureDataset;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    featdataset = CreateDBFeatureDataset(textBoxNewLayerName.Text.Trim());
                }
                if (featdataset == null)
                {
                    return;
                }
                featdataset.Open();

                GSOLayer shpLayer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());
                if (shpLayer == null)
                {
                    return;
                }

                GSOFeatures features = shpLayer.GetAllFeatures(true);
                string      message  = "";
                for (int j = 0; j < features.Length; j++)
                {
                    GSOFeature    f        = features[j];
                    GSOGeoPoint3D shpPoint = f.Geometry as GSOGeoPoint3D;

                    double x;
                    double y;
                    double rotateAngle      = 0;
                    string currentModelType = f.GetValue(combCode.SelectedItem.ToString()).ToString();
                    double z    = Convert.ToDouble(txtUpGround.Text);
                    double deep = f.GetFieldAsDouble(combDeep.SelectedItem.ToString());

                    int    index = -1;
                    double diff  = double.MaxValue;
                    for (int i = 0; i < deeps.Count; i++)
                    {
                        double tempdeep  = Convert.ToDouble(deeps[i]);
                        string modeltype = modeltypes[i].ToString();
                        if (modeltype != currentModelType)
                        {
                            continue;
                        }

                        if (tempdeep > deep)
                        {
                            double chazhi = tempdeep - deep;
                            if (diff > chazhi)
                            {
                                diff  = chazhi;
                                index = i;
                            }
                        }
                    }
                    if (index < 0)
                    {
                        message += "ID为" + f.ID + "的对象没有找到符合井深的工井模型\r\n";
                        continue;
                    }

                    GSOFeature  feature = featdataset.CreateFeature();
                    GSOGeoModel model   = new GSOGeoModel();
                    GSOPoint3d  pt      = new GSOPoint3d();
                    pt.X = shpPoint.X;
                    pt.Y = shpPoint.Y;
                    pt.Z = z;

                    model.Position     = pt;
                    model.Align        = EnumEntityAlign.TopCenter; //接口已修复作用
                    model.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                    model.RotateZ = 0 - rotateAngle * 180 / Math.PI + 90;

                    model.FilePath   = textBoxModelFolder.Text + "\\" + files[index];
                    model.Name       = f.GetValue(combModelName.SelectedItem.ToString()).ToString();
                    feature.Name     = f.GetValue(combModelName.SelectedItem.ToString()).ToString();
                    feature.Geometry = model;

                    for (int i = 0; i < f.GetFieldCount(); i++)
                    {
                        GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(f.GetFieldDefn(i));

                        if (fielddef == null)
                        {
                            continue;
                        }
                        if (!gj_cns.ContainsKey(fielddef.Name))
                        {
                            continue;
                        }

                        object obu = f.GetValue(fielddef.Name);
                        if (obu != null)
                        {
                            string fieldName = gj_cns.ContainsKey(fielddef.Name) == true ? gj_cns[fielddef.Name].ToString() : fielddef.Name;
                            feature.SetValue(fieldName, obu);
                        }
                    }
                    featdataset.AddFeature(feature);
                }

                featdataset.Save();
                featdataset.Close();
                string strMessage = "shp文件中共" + features.Length + "个对象,实际入库" + featdataset.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 button3_Click(object sender, EventArgs e)
        {
            if (txtFolder.Text == "")
            {
                return;
            }

            //if (txtPath.Text == "")
            //    return;

            try
            {
                Regex regNum = new Regex("^[0-9]");

                DirectoryInfo theFolder = new DirectoryInfo(txtFolder.Text);
                foreach (FileInfo nextFile in theFolder.GetFiles())
                {
                    if (nextFile.Name.ToLower().IndexOf("3ds") > -1 || nextFile.Name.ToLower().IndexOf("gcm") > -1)
                    {
                        files.Add(nextFile.Name);
                        string temp      = nextFile.Name.Substring(nextFile.Name.IndexOf("-") + 1, nextFile.Name.LastIndexOf(".") - nextFile.Name.IndexOf("-") - 1);
                        string modeltype = nextFile.Name.Substring(0, nextFile.Name.IndexOf("-"));
                        modeltypes.Add(modeltype);

                        double Num;
                        bool   isNum = double.TryParse(temp, out Num);

                        if (isNum)
                        {
                            deeps.Add(Convert.ToDouble(temp));
                        }
                    }
                }

                //        TextReader tr = new StreamReader(txtPath.Text);

                //        string line = tr.ReadLine();

                //        GSOFeatureDataset featdataset = CreateDBFeatureDataset(txtLayerName.Text);  // 创建 数据库要素集
                //        return;



                if (string.IsNullOrEmpty(txtLayerName.Text))
                {
                    MessageBox.Show("管线图层无效!", "提示");
                    return;
                }
                GSODataset dataset = ds.GetDatasetByName(txtLayerName.Text.Trim());

                GSOFeatureDataset layer;
                if (dataset != null)
                {
                    DialogResult restult = MessageBox.Show("管线图层名称在数据库中已存在!是否向该表追加", "提示", MessageBoxButtons.YesNo);
                    if (restult == DialogResult.No)
                    {
                        return;
                    }
                    else if (restult == DialogResult.Yes)
                    {
                        layer = dataset as GSOFeatureDataset;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    layer = CreateDBFeatureDataset(txtLayerName.Text.Trim());
                }

                if (layer == null)
                {
                    return;
                }

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

                MessageBox.Show("创建成功!");



                layer.Open();
                lgdFilePath = txtLayerName.Text;
                if (layer != null)
                {
                    GSOFeatures features = sourceLayer.GetAllFeatures(true);
                    for (int j = 0; j < features.Length; j++)
                    {
                        GSOFeature    f       = features[j];
                        GSOGeoPoint3D lineeee = f.Geometry as GSOGeoPoint3D;

                        //double x;
                        //double y;

                        //double rotateAngle = 0;

                        //string currentModelType = f.GetValue("管线点编码").ToString(); // paras[6];
                        //double z = Convert.ToDouble(txtUpGround.Text);

                        //double deep = f.GetFieldAsDouble("井深");

                        //int index = -1;
                        //double diff = double.MaxValue;
                        //for (int i = 0; i < deeps.Count; i++)
                        //{
                        //    double tempdeep = Convert.ToDouble(deeps[i]);
                        //    string modeltype = modeltypes[i].ToString();
                        //    if (modeltype != currentModelType)
                        //    {
                        //        continue;
                        //    }

                        //    if (tempdeep > deep)
                        //    {
                        //        double chazhi = tempdeep - deep;
                        //        if (diff > chazhi)
                        //        {
                        //            diff = chazhi;
                        //            index = i;
                        //        }
                        //    }
                        //}
                        //if (index < 0)
                        //{
                        //    continue;
                        //}

                        //GSOFeature newFeature = layer.CreateFeature();
                        //GSOGeoModel model = new GSOGeoModel();
                        //GSOPoint3d pt = new GSOPoint3d();
                        //pt.X = lineeee.X;
                        //pt.Y = lineeee.Y;
                        //pt.Z = z;

                        //model.Position = pt;
                        //model.Align = EnumEntityAlign.TopCenter; //接口已修复作用
                        //model.AltitudeMode = EnumAltitudeMode.RelativeToGround;

                        //model.RotateZ = 0 - rotateAngle * 180 / Math.PI + 90;

                        //model.FilePath = txtFolder.Text + "\\" + files[index];



                        GSOFeature newFeature = layer.CreateFeature();

                        for (int i = 0; i < features[0].GetFieldCount(); i++)
                        {
                            GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(features[0].GetFieldDefn(i));
                            if (!en_cns.ContainsKey(fielddef.Name))
                            {
                                continue;
                            }
                            object fieldvalue = convertFieldValue(fielddef.Name, f.GetValue(fielddef.Name));
                            if (fielddef == null)
                            {
                                continue;
                            }

                            newFeature.SetValue(en_cns[fielddef.Name].ToString(), fieldvalue);
                        }
                        layer.AddFeature(newFeature);
                    }
                }
                globeControl1.Refresh();
                layer.Save();
                layer.Caption = layer.Name;
                globeControl1.Globe.Layers.Add(layer);
                this.Close();


                //创建

                //featdataset.Open();
                //while (line != null)
                //{
                //    string[] paras = line.Split(',');

                //    if (paras.Length != 16)
                //    {
                //        line = tr.ReadLine();
                //        continue;
                //    }

                //    if (paras.Length <= 15)
                //    {
                //        line = tr.ReadLine();
                //        continue;
                //    }

                //    if (paras[4] == "" || paras[5] == "" || paras[6] == "")
                //    {
                //        line = tr.ReadLine();
                //        continue;
                //    }
                //    double x;
                //    double y;

                //    if (!double.TryParse(paras[5], out x))
                //    {
                //        line = tr.ReadLine();
                //        continue;
                //    }

                //    if (!double.TryParse(paras[4], out y))
                //    {
                //        line = tr.ReadLine();
                //        continue;
                //    }
                //    double rotateAngle = 0;
                //    if (!double.TryParse(paras[15], out rotateAngle))
                //    {
                //        line = tr.ReadLine();
                //        continue;
                //    }
                //    string currentModelType = paras[6];
                //    if (currentModelType.Length == 0)
                //    {
                //        line = tr.ReadLine();
                //        continue;
                //    }

                //    int id = GeoScene.Data.GSOProjectManager.AddProject("+proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=-50000 +y_0=-4210000 +ellps=krass +units=m +no_defs");
                //    GeoScene.Data.GSOPoint2d pt2d = new GeoScene.Data.GSOPoint2d(x, y);
                //    GeoScene.Data.GSOPoint2d result = GeoScene.Data.GSOProjectManager.Inverse(pt2d, id);

                //double z = Convert.ToDouble(txtUpGround.Text);
                //GSOFeature feature = featdataset.CreateFeature();
                //double deep;
                //if (!double.TryParse(paras[8], out deep))
                //{
                //    line = tr.ReadLine();
                //    continue;
                //}

                //int index = -1;
                //double diff = double.MaxValue;
                //for (int i = 0; i < deeps.Count; i++)
                //{
                //    double tempdeep = Convert.ToDouble(deeps[i]);
                //    string modeltype = modeltypes[i].ToString();
                //    if (modeltype != currentModelType)
                //    {
                //        continue;
                //    }

                //    if (tempdeep > deep)
                //    {
                //        double chazhi = tempdeep - deep;
                //        if (diff > chazhi)
                //        {
                //            diff = chazhi;
                //            index = i;
                //        }
                //    }
                //}
                //if (index < 0)
                //{
                //    line = tr.ReadLine();
                //    continue;
                //}

                //GSOGeoModel model = new GSOGeoModel();
                //GSOPoint3d pt = new GSOPoint3d();
                //pt.X = result.X;
                //pt.Y = result.Y;
                //pt.Z = z;

                //model.Position = pt;
                //model.Align = EnumEntityAlign.TopCenter; //接口已修复作用
                //model.AltitudeMode = EnumAltitudeMode.RelativeToGround;


                //model.RotateZ = 0 - rotateAngle * 180 / Math.PI + 90;

                //model.FilePath = txtFolder.Text + "\\" + files[index];
                //model.Name = paras[0];
                //feature.Name = paras[0];
                //feature.Geometry = model;

                //    if (paras[9].Length > 0)
                //        feature.SetValue("图片编码", paras[9]);
                //  //  feature.SetValue("旋转角度", 0 - rotateAngle * 180 / Math.PI + 90);
                //    feature.SetValue("编号", paras[0]);
                //   // feature.SetValue("模型路径", txtFolder.Text + "\\" + files[index]);
                //    feature.SetValue("建设年代",paras[10]);
                //    feature.SetValue("建设单位", paras[12]);
                //    feature.SetValue("权属单位",paras[13]);
                //    feature.SetValue("备注",paras[14]);
                //    featdataset.AddFeature(feature);
                //    line = tr.ReadLine();
                //}
                //featdataset.Save();
                //this.Close();
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
Exemple #6
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            if (comboBoxDataSourceList.SelectedItem == null)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("请选择一个目标数据源!", "提示");
                return;
            }
            GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());

            if (ds == null)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("选择的目标数据源为空!", "提示");
                return;
            }
            if (comboBoxDBLayerList.SelectedItem == null)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("请选择要创建拓扑的图层!", "提示");
                return;
            }
            string topoName = textBoxTopoName.Text.Trim();

            if (topoName == "")
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("拓扑图层名称不能为空!");
                return;
            }
            GSODataset dataset = ds.GetDatasetByName(comboBoxDBLayerList.SelectedItem.ToString().Trim());

            if (dataset == null)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("选择的图层为空!", "提示");
                return;
            }
            GSOFeatureDataset featureDataset = dataset as GSOFeatureDataset;

            if (featureDataset == null)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("选择的图层不是矢量图层!", "提示");
                return;
            }
            if (checkBoxUnionValve.Checked == true)
            {
                if (comboBoxDBValveList.SelectedItem == null)
                {
                    this.Cursor = Cursors.Default;
                    MessageBox.Show("请选择一个阀门图层!", "提示");
                    return;
                }
            }
            try
            {
                GSODataset topoDataset = ds.GetDatasetByName(topoName);
                if (topoDataset != null)
                {
                    DialogResult result = MessageBox.Show("拓扑数据已经存在,是否重建?", "警告", MessageBoxButtons.OKCancel);
                    if (result == DialogResult.OK)
                    {
                        ds.DeleteDatasetByName(topoName);
                    }
                    else
                    {
                        this.Cursor = Cursors.Default;
                        return;
                    }
                }
                double dTolerance = 0;
                if (Double.TryParse(textBoxTolerance.Text.Trim(), out dTolerance) == false)
                {
                    this.Cursor = Cursors.Default;
                    MessageBox.Show("误差容限值不符合要求!", "提示");
                    return;
                }
                GSONetworkDataset newNetworkDataset = GSODataEngineUtility.GeneratePipelineNetwork(ds, featureDataset, topoName, true, dTolerance, "", "", checkBoxIgnoreZ.Checked, false);
                if (newNetworkDataset == null)
                {
                    this.Cursor = Cursors.Default;
                    MessageBox.Show("拓扑数据创建失败!");
                    return;
                }
                if (checkBoxUnionValve.Checked)
                {
                    //添加阀门信息
                    GSONetworkDataset networkDataset = ds.GetDatasetByName(topoName) as GSONetworkDataset;
                    if (networkDataset == null)
                    {
                        this.Cursor = Cursors.Default;
                        MessageBox.Show("要添加阀门信息的拓扑数据不存在!");
                        return;
                    }
                    GSODataset        valveDataset        = ds.GetDatasetByName(comboBoxDBValveList.SelectedItem.ToString().Trim());
                    GSOFeatureDataset valveFeatureDataset = valveDataset as GSOFeatureDataset;
                    if (valveFeatureDataset == null)
                    {
                        this.Cursor = Cursors.Default;
                        MessageBox.Show("选择的阀门图层不是矢量图层!", "提示");
                        return;
                    }
                    if (checkBoxClearValves.Checked == true)//清除掉以前关联的阀门信息
                    {
                        networkDataset.ClearValves();
                    }

                    double dVavleTolerance = 0;
                    if (Double.TryParse(textBoxValveTolerance.Text, out dVavleTolerance) == false)
                    {
                        this.Cursor = Cursors.Default;
                        MessageBox.Show("阀门图层的误差容限值不符合要求!", "提示");
                        return;
                    }

                    double dNearstDisLimit = 0;
                    if (Double.TryParse(textBoxNearestDistLimit.Text, out dNearstDisLimit) == false)
                    {
                        this.Cursor = Cursors.Default;
                        MessageBox.Show("最近点距离的容限值不符合要求!", "提示");
                        return;
                    }

                    Int32 nMatchNum = networkDataset.GenerateValves(valveFeatureDataset, dVavleTolerance, checkBoxValveIgnoreZ.Checked, checkBoxMatchNearest.Checked, dNearstDisLimit);

                    MessageBox.Show("拓扑数据创建成功,阀门匹配完成!共匹配了 " + nMatchNum + " 个阀门!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("拓扑数据创建成功!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                this.Cursor = Cursors.Default;
                this.Close();
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show(ex.Message);
                Log.PublishTxt(ex);
            }
        }
Exemple #7
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)
        {
            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 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 btn_Union_Click(object sender, EventArgs e)
        {
            if (comboBoxTargetDataSource.SelectedItem == null)
            {
                MessageBox.Show("请选择目标数据源!", "提示");
                return;
            }
            string newLayerName = textBoxUnionLayerName.Text.Trim();

            if (newLayerName == "")
            {
                MessageBox.Show("请输入目标数据集名称!", "提示");
                return;
            }
            if (comboBoxDataSourceList1.SelectedItem == null)
            {
                MessageBox.Show("请选择要合并的数据源1!", "提示");
                return;
            }
            if (comboBoxUnionLayerList1.SelectedItem == null)
            {
                MessageBox.Show("请选择要合并的要素集1!", "提示");
                return;
            }
            if (comboBoxDataSourceList2.SelectedItem == null)
            {
                MessageBox.Show("请选择要合并的数据源2!", "提示");
                return;
            }
            if (comboBoxUnionLayerList2.SelectedItem == null)
            {
                MessageBox.Show("请选择要合并的要素集2!", "提示");
                return;
            }
            GSODataSource dsTarget = Utility.getDataSourceByFullName(globeControl1, comboBoxTargetDataSource.SelectedItem.ToString().Trim());

            if (dsTarget != null)
            {
                GSODataset dataset = dsTarget.GetDatasetByName(newLayerName);
                if (dataset != null)
                {
                    MessageBox.Show("目标数据集名称已存在目标数据源中!", "提示");
                    return;
                }
                GSOFeatureDataset featureDatasetInTargetDs = dsTarget.CreateFeatureDataset(newLayerName);
                if (featureDatasetInTargetDs == null)
                {
                    MessageBox.Show("目标数据集名称不符合要求!", "提示");
                    return;
                }
                GSODataSource dsUnion1 = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList1.SelectedItem.ToString().Trim());
                GSODataSource dsUnion2 = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList2.SelectedItem.ToString().Trim());
                if (dsUnion1 != null && dsUnion2 != null)
                {
                    GSOFeatureDataset datasetInUnionDs1 = dsUnion1.GetDatasetByName(comboBoxUnionLayerList1.SelectedItem.ToString().Trim()) as GSOFeatureDataset;
                    GSOFeatureDataset datasetInUnionDs2 = dsUnion1.GetDatasetByName(comboBoxUnionLayerList2.SelectedItem.ToString().Trim()) as GSOFeatureDataset;
                    if (datasetInUnionDs1 != null && datasetInUnionDs2 != null)
                    {
                        //判断要合并的数据集结构是否相同
                        datasetInUnionDs1.Open();
                        datasetInUnionDs2.Open();
                        if (datasetInUnionDs1.FieldCount != datasetInUnionDs2.FieldCount)
                        {
                            MessageBox.Show("要合并的数据集结构不相同,无法合并!", "错误");
                            return;
                        }
                        for (int i = 0; i < datasetInUnionDs1.FieldCount; i++)
                        {
                            if (datasetInUnionDs1.GetField(i).Equals(datasetInUnionDs2.GetField(i)) == false)
                            {
                                MessageBox.Show("要合并的数据集结构不相同,无法合并!", "错误");
                                return;
                            }
                        }
                        featureDatasetInTargetDs.Open();
                        for (int i = 0; i < datasetInUnionDs1.FieldCount; i++)
                        {
                            GSOFieldAttr fieldInUnionDs = datasetInUnionDs1.GetField(i);
                            featureDatasetInTargetDs.AddField(fieldInUnionDs);
                        }
                        //向新的数据集写入数据
                        for (int i = 0; i < datasetInUnionDs1.GetAllFeatures().Length; i++) //循环添加第一个要素集的所有feature到新数据集中
                        {
                            GSOFeature featureInUnionDs1 = datasetInUnionDs1.GetFeatureAt(i);
                            GSOFeature featureInTargetDs = featureInUnionDs1.Clone();
                            featureDatasetInTargetDs.AddFeature(featureInTargetDs);
                        }
                        for (int i = 0; i < datasetInUnionDs2.GetAllFeatures().Length; i++) //循环添加第一个要素集的所有feature到新数据集中
                        {
                            GSOFeature featureInUnionDs2 = datasetInUnionDs2.GetFeatureAt(i);
                            GSOFeature featureInTargetDs = featureInUnionDs2.Clone();
                            featureDatasetInTargetDs.AddFeature(featureInTargetDs);
                        }
                        featureDatasetInTargetDs.Save();
                        featureDatasetInTargetDs.Close();
                        datasetInUnionDs1.Close();
                        datasetInUnionDs2.Close();
                        MessageBox.Show("数据集合并成功!", "提示");
                        this.Close();
                    }
                }
            }
        }
        private void btnCreateModel_Click(object sender, EventArgs e)
        {
            if (comboBoxDataSourceList.SelectedItem == null)
            {
                MessageBox.Show("请选择要复制的数据的源!");
                return;
            }
            if (commBoxModelLayerList.SelectedItem == null)
            {
                MessageBox.Show("请选择数据集模板!");
                return;
            }
            if (comboBoxTargetDataSource.SelectedItem == null)
            {
                MessageBox.Show("请选择目标数据源!");
                return;
            }
            string layerName = textBoxNewLayerName.Text.Trim();

            if (layerName == "")
            {
                MessageBox.Show("请输入数据集名称!");
                return;
            }
            int  num = -1;
            bool bl  = int.TryParse(layerName.Substring(0, 1), out num);

            if (!bl)
            {
                GSODataSource dsTarget = Utility.getDataSourceByFullName(globeControl1, comboBoxTargetDataSource.SelectedItem.ToString().Trim());
                if (dsTarget != null)
                {
                    GSODataset datasetInTargetDs = dsTarget.GetDatasetByName(layerName);
                    if (datasetInTargetDs != null)
                    {
                        MessageBox.Show("目标数据源中该数据集名称已存在!", "提示");
                        return;
                    }
                    else
                    {
                        GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());
                        if (ds != null)
                        {
                            GSODataset        datasetInDs        = ds.GetDatasetByName(commBoxModelLayerList.SelectedItem.ToString());
                            GSOFeatureDataset featureDatasetInDs = datasetInDs as GSOFeatureDataset;
                            if (featureDatasetInDs == null)
                            {
                                MessageBox.Show("选中的模板图层不符合要求!", "提示");
                                return;
                            }
                            featureDatasetInDs.Open();

                            GSOFeatureDataset featureDatasetTargetDs = dsTarget.CreateFeatureDataset(layerName);
                            if (featureDatasetTargetDs == null)
                            {
                                MessageBox.Show("输入的新数据集名称不符合要求!", "提示");
                                return;
                            }
                            featureDatasetTargetDs.Open();
                            for (int i = 0; i < featureDatasetInDs.FieldCount; i++)
                            {
                                GSOFieldAttr fieldFromSource         = featureDatasetInDs.GetField(i);
                                GSOFieldAttr fieldInTargetDataSource = new GSOFieldAttr();
                                fieldInTargetDataSource.Name      = fieldFromSource.Name;
                                fieldInTargetDataSource.Type      = fieldFromSource.Type;
                                fieldInTargetDataSource.Width     = fieldFromSource.Width;
                                fieldInTargetDataSource.Precision = fieldFromSource.Precision;
                                bool res = featureDatasetTargetDs.AddField(fieldInTargetDataSource);
                            }

                            featureDatasetTargetDs.Save();
                            featureDatasetTargetDs.Close();
                            featureDatasetInDs.Close();
                            MessageBox.Show("复制成功!", "提示");
                            this.Close();
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("数据集名称不能以数字开头!", "提示");
            }
        }