Esempio n. 1
0
        private void cmbLayer_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxShpLayerList.SelectedItem == null)
            {
                return;
            }
            GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());

            if (layer == null)
            {
                return;
            }
            textBoxNewLayerName.Text = layer.Caption;

            GSOFeatures features = layer.GetAllFeatures();

            if (features.Length == 0)
            {
                return;
            }
            combCode.Items.Clear();
            combDeep.Items.Clear();
            combModelName.Items.Clear();

            for (int i = 0; i < features[0].GetFieldCount(); i++)
            {
                GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(features[0].GetFieldDefn(i));
                combCode.Items.Add(fielddef.Name);
                combDeep.Items.Add(fielddef.Name);
                combModelName.Items.Add(fielddef.Name);
            }
            combCode.SelectedItem      = "管线点编码";
            combDeep.SelectedItem      = "井深";
            combModelName.SelectedItem = "编号";
        }
        private void SetFields(GSOFeature oldfeat, GSOFeature newFeature)
        {
            for (int i = 0; i < oldfeat.GetFieldCount(); i++)
            {
                GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(oldfeat.GetFieldDefn(i));

                object fieldvalue = oldfeat.GetValue(fielddef.Name);
                if (fieldvalue == null)
                {
                    continue;
                }
                newFeature.SetValue(fielddef.Name, fieldvalue);
            }
        }
Esempio n. 3
0
        private void cmbLayer_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxShpLayerList.SelectedItem == null)
            {
                return;
            }
            GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());

            if (layer == null)
            {
                return;
            }
            textBoxNewLayerName.Text = layer.Caption;
            GSOFeatures features = layer.GetAllFeatures();

            if (features.Length == 0)
            {
                return;
            }
            cmbFrom.Items.Clear();
            cmbTo.Items.Clear();
            cmbRadius.Items.Clear();
            cmbID.Items.Clear();
            cmbMaiSheFangShi.Items.Clear();
            cmbWidth.Items.Clear();
            cmbHeight.Items.Clear();
            for (int i = 0; i < features[0].GetFieldCount(); i++)
            {
                GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(features[0].GetFieldDefn(i));

                cmbFrom.Items.Add(fielddef.Name);
                cmbTo.Items.Add(fielddef.Name);
                cmbRadius.Items.Add(fielddef.Name);
                cmbID.Items.Add(fielddef.Name);
                cmbMaiSheFangShi.Items.Add(fielddef.Name);
                cmbWidth.Items.Add(fielddef.Name);
                cmbHeight.Items.Add(fielddef.Name);
            }
            cmbFrom.SelectedItem          = "Deep1";
            cmbTo.SelectedItem            = "Deep2";
            cmbID.SelectedItem            = "Handle";
            cmbRadius.SelectedItem        = "Diameter";
            cmbMaiSheFangShi.SelectedItem = "D_Type";
            cmbWidth.SelectedItem         = "Weight";
            cmbHeight.SelectedItem        = "Height";
        }
Esempio n. 4
0
        private void cmbLayer_SelectedIndexChanged(object sender, EventArgs e)
        {
            GSOLayer    layer    = globeControl1.Globe.Layers[cmbLayer.SelectedIndex];
            GSOFeatures features = layer.GetAllFeatures();

            if (features.Length == 0)
            {
                return;
            }

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

                //cmbFrom.Items.Add(fielddef.Name);
                //cmbTo.Items.Add(fielddef.Name);
                //cmbRadius.Items.Add(fielddef.Name);
                //cmbID.Items.Add(fielddef.Name);
            }
        }
Esempio n. 5
0
        private void cmbLayer_SelectedIndexChanged(object sender, EventArgs e)
        {
            GSOLayer    layer    = globeControl1.Globe.Layers[cmbLayer.SelectedIndex];
            GSOFeatures features = layer.GetAllFeatures();

            if (features.Length == 0)
            {
                return;
            }

            combCode.Items.Clear();
            combDeep.Items.Clear();
            combModelName.Items.Clear();
            combAngle.Items.Clear();
            for (int i = 0; i < features[0].GetFieldCount(); i++)
            {
                GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(features[0].GetFieldDefn(i));
                combCode.Items.Add(fielddef.Name);
                combDeep.Items.Add(fielddef.Name);
                combModelName.Items.Add(fielddef.Name);
                combAngle.Items.Add(fielddef.Name);
            }
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        //导入数据库

        /*     private void button3_Click(object sender, EventArgs e)
         *   {
         *       if (txtFolder.Text == "")
         *           return;
         *
         *       if (txtPath.Text == "")
         *           return;
         *
         *
         *       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);
         *       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;
         *           }
         *
         *           //model.FilePath = txtFolder.Text + "\\" + files[index];
         *           //model.Position = new GSOPoint3d(result.X, result.Y, z);
         *
         *           //model.Rotate(0, 0-rotateAngle*180/Math.PI + 90,0);  //旋转的轴,yz 调换了, 有bug
         *
         *           //model.Align = EnumEntityAlign.TopCenter; //接口已修复作用
         *           //model.AltitudeMode = EnumAltitudeMode.RelativeToGround;
         *
         *           GSOGeoPoint3D pt = new GSOGeoPoint3D(result.X, result.Y, z);
         *
         *           //model.FilePath = Path.GetDirectoryName(Application.ExecutablePath) + "/Resource/model/tank.3ds";
         *           feature.Geometry = pt;
         *
         *           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]);
         *
         *           featdataset.AddFeature(feature);
         *
         *           line = tr.ReadLine();
         *       }
         *       featdataset.Save();
         *       this.Close();
         *   }
         */
        private GSOFeatureDataset CreateDBFeatureDataset(string name)
        {
            //GSOFeatureDataset featDs = ds.CreateFeatureDataset(name);

            //GSOFieldAttr field = new GSOFieldAttr();

            //ICollection ic = en_cns.Keys;
            //IDictionaryEnumerator ie = en_cns.GetEnumerator();
            //while (ie.MoveNext())
            //{
            //    object en_name = ie.Key;
            //    object ch_name = ie.Value;
            //    object field_type = fields_types[en_name];

            //    field.Name = ch_name.ToString();
            //    switch (field_type.ToString())
            //    {
            //        case "string":
            //            field.Type = EnumFieldType.Text;
            //            field.Width = 100;
            //            break;
            //        case "int":
            //            field.Type = EnumFieldType.INT32;
            //            field.Width = 4;
            //            break;
            //        case "double":
            //            field.Type = EnumFieldType.Double;
            //            field.Width = 8;
            //            break;
            //        case "date":
            //            field.Type = EnumFieldType.Date;
            //            field.Width = 10;
            //            break;
            //    }
            //    bool res = featDs.AddField(field);
            //}
            //featDs.Save();
            //return featDs;

            GSOLayer    layer    = globeControl1.Globe.Layers[cmbLayer.SelectedIndex];
            GSOFeatures features = layer.GetAllFeatures();

            if (features.Length == 0)
            {
                MessageBox.Show("图层要素个数为0!", "提示");
                return(null);
            }

            GSOFeatureDataset featDs = ds.CreateFeatureDataset(name);

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

                GSOFieldAttr field = new GSOFieldAttr();

                field.Name = en_cns[fielddef.Name].ToString();
                switch (fields_types[fielddef.Name].ToString())
                {
                case "string":
                    field.Type  = EnumFieldType.Text;
                    field.Width = 8000;
                    break;

                case "int":
                    field.Type  = EnumFieldType.INT32;
                    field.Width = 4;
                    break;

                case "double":
                    field.Type  = EnumFieldType.Double;
                    field.Width = 8;
                    break;

                case "date":
                    field.Type  = EnumFieldType.Date;
                    field.Width = 10;
                    break;
                }
                bool res = featDs.AddField(field);
            }

            featDs.Save();
            return(featDs);
        }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (txtFolder.Text == "")
            {
                return;
            }

            if (cmbLayer.SelectedIndex < 0)
            {
                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));
                        }
                    }
                }
                GSOFeatureDataset featdataset = CreateDBFeatureDataset(txtLayerName.Text);
                featdataset.Open();

                GSOLayer shpLayer = globeControl1.Globe.Layers[cmbLayer.SelectedIndex];
                if (shpLayer == null)
                {
                    return;
                }

                GSOFeatures features = shpLayer.GetAllFeatures(true);

                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;
                    rotateAngle = (double)f.GetValue(combAngle.SelectedItem.ToString());

                    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)
                    {
                        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   = txtFolder.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 < feature.GetFieldCount(); i++)
                    {
                        GeoScene.Data.GSOFieldDefn fielddef = (GeoScene.Data.GSOFieldDefn)(f.GetFieldDefn(i));
                        //if (!en_cns.ContainsKey(fielddef.Name))
                        //    continue;
                        //  object fieldvalue = convertFieldValue(fielddef.Name, f.GetValue(fielddef.Name));
                        if (fielddef == null)
                        {
                            continue;
                        }
                        feature.SetValue(fielddef.Name, f.GetValue(fielddef.Name));
                    }
                    featdataset.AddFeature(feature);
                }

                featdataset.Save();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 11
0
        //导入数据库

        /*     private void button3_Click(object sender, EventArgs e)
         *   {
         *       if (txtFolder.Text == "")
         *           return;
         *
         *       if (txtPath.Text == "")
         *           return;
         *
         *
         *       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);
         *       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;
         *           }
         *
         *           //model.FilePath = txtFolder.Text + "\\" + files[index];
         *           //model.Position = new GSOPoint3d(result.X, result.Y, z);
         *
         *           //model.Rotate(0, 0-rotateAngle*180/Math.PI + 90,0);  //旋转的轴,yz 调换了, 有bug
         *
         *           //model.Align = EnumEntityAlign.TopCenter; //接口已修复作用
         *           //model.AltitudeMode = EnumAltitudeMode.RelativeToGround;
         *
         *           GSOGeoPoint3D pt = new GSOGeoPoint3D(result.X, result.Y, z);
         *
         *           //model.FilePath = Path.GetDirectoryName(Application.ExecutablePath) + "/Resource/model/tank.3ds";
         *           feature.Geometry = pt;
         *
         *           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]);
         *
         *           featdataset.AddFeature(feature);
         *
         *           line = tr.ReadLine();
         *       }
         *       featdataset.Save();
         *       this.Close();
         *   }
         */
        private GSOFeatureDataset CreateDBFeatureDataset(string name)
        {
            //GSOFeatureDataset featDs = ds.CreateFeatureDataset(name);

            //GSOFieldAttr field = new GSOFieldAttr();
            //field.Name = "编号";
            //field.Type = EnumFieldType.Text;
            //field.Width = 30;
            //featDs.AddField(field);

            //field = new GSOFieldAttr();
            //field.Name = "井深";
            //field.Type = EnumFieldType.Double;
            //field.Width = 8;
            //featDs.AddField(field);

            //field = new GSOFieldAttr();
            //field.Name = "图片编码";
            //field.Type = EnumFieldType.Text;
            //field.Width = 150;
            //featDs.AddField(field);

            //field = new GSOFieldAttr();
            //field.Name = "建设年代";
            //field.Type = EnumFieldType.Text;
            //field.Width = 30;
            //featDs.AddField(field);

            //field = new GSOFieldAttr();
            //field.Name = "建设单位";
            //field.Type = EnumFieldType.Text;
            //field.Width = 60;
            //featDs.AddField(field);

            //field = new GSOFieldAttr();
            //field.Name = "权属单位";
            //field.Type = EnumFieldType.Text;
            //field.Width = 30;
            //featDs.AddField(field);

            //field = new GSOFieldAttr();
            //field.Name = "备注";
            //field.Type = EnumFieldType.Text;
            //field.Width = 30;
            //featDs.AddField(field);

            //field = new GSOFieldAttr();
            //field.Name = "旋转角度";
            //field.Type = EnumFieldType.Double;
            //field.Width = 8;
            //featDs.AddField(field);

            //field = new GSOFieldAttr();
            //field.Name = "模型路径";
            //field.Type = EnumFieldType.Text;
            //field.Width = 150;
            //featDs.AddField(field);

            GSOLayer    layer    = globeControl1.Globe.Layers[cmbLayer.SelectedIndex];
            GSOFeatures features = layer.GetAllFeatures();

            if (features.Length == 0)
            {
                MessageBox.Show("图层要素个数为0!", "提示");
                return(null);
            }

            GSOFeatureDataset featDs = ds.CreateFeatureDataset(name);

            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;

                GSOFieldAttr field = new GSOFieldAttr();

                field.Name = fielddef.Name;  //en_cns[fielddef.Name].ToString();
                switch (fielddef.Type)
                {
                case EnumFieldType.Text:
                    field.Type  = EnumFieldType.Text;
                    field.Width = 100;
                    break;

                case EnumFieldType.INT32:
                    field.Type  = EnumFieldType.INT32;
                    field.Width = 4;
                    break;

                case EnumFieldType.Double:
                    field.Type  = EnumFieldType.Double;
                    field.Width = 8;
                    break;

                case EnumFieldType.Date:
                    field.Type  = EnumFieldType.Date;
                    field.Width = 10;
                    break;
                }
                bool res = featDs.AddField(field);
            }

            featDs.Save();
            return(featDs);

            //featDs.Save();
            //return featDs;
        }
        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 (comboBoxShpLayerList.SelectedIndex < 0)
            {
                return;
            }
            try
            {
                if (valiValvedata())
                {
                    GSOFeatureDataset featdataset = CreateDBFeatureDataset(textBoxNewLayerName.Text);
                    if (featdataset == null)
                    {
                        return;
                    }
                    featdataset.Open();
                    GSOLayer shpLayer = globeControl1.Globe.Layers[comboBoxShpLayerList.SelectedIndex];
                    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        z        = f.GetFieldAsDouble(combZ.SelectedItem.ToString());
                        double        deep     = f.GetFieldAsDouble(combZ.SelectedItem.ToString());

                        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.AltitudeMode = EnumAltitudeMode.RelativeToGround;
                        string modelPath = f.GetFieldAsString(combPath.SelectedItem.ToString());
                        model.FilePath   = Application.StartupPath + "\\" + modelPath;
                        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 (!fm_cns.ContainsKey(fielddef.Name))
                            {
                                continue;
                            }

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

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