private GSOFeatureDataset CreateDBFeatureDataset(string name)
        {
            if (comboBoxShpLayerList.SelectedItem == null)
            {
                MessageBox.Show("请选择一个Shp图层!", "提示");
                return(null);
            }
            GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());

            if (layer == null)
            {
                MessageBox.Show("Shp图层为空!", "提示");
                return(null);
            }
            GSOFeatures features = layer.GetAllFeatures();

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

            if (featureDataset == null)
            {
                MessageBox.Show("Shp图层不是矢量图层!", "提示");
                return(null);
            }
            if (comboBoxDataSourceList.SelectedItem == null)
            {
                MessageBox.Show("请选择一个目标数据源!", "提示");
                return(null);
            }
            GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());

            if (ds == null)
            {
                MessageBox.Show("选择的目标数据源为空!", "提示");
                return(null);
            }
            GSOFeatureDataset newFeatureDataset = ds.CreateFeatureDataset(name);

            if (newFeatureDataset != null)
            {
                for (int i = 0; i < featureDataset.FieldCount; i++)
                {
                    GeoScene.Data.GSOFieldAttr fielddef = featureDataset.GetField(i);

                    GSOFieldAttr field = new GSOFieldAttr();
                    field.Name      = fielddef.Name;
                    field.Type      = fielddef.Type;
                    field.Width     = fielddef.Width;
                    field.Precision = fielddef.Precision;
                    bool res = newFeatureDataset.AddField(field);
                }
                newFeatureDataset.Save();
            }
            return(newFeatureDataset);
        }
Example #2
0
        /// <summary>
        /// 向LDB中新建图层数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_EditLayer_Click(object sender, EventArgs e)
        {
            //添加名为Test的图层数据
            GSOFeatureDataset dataset = _ldbDataSource.CreateFeatureDataset("Test");
            //将新建的图层数据添加到Globe控件中
            GSOLayer featureLayer = _glbControl.Globe.Layers.Add(dataset);

            btn_EditFeature.Enabled = true;
        }
        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("数据复制成功!", "提示");
                    }
                }
            }
        }
Example #4
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);
        }
Example #5
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 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 newLayerName = textboxNewLayerName.Text.Trim();

            if (newLayerName == "")
            {
                MessageBox.Show("新建图层的名称不能为空!", "提示");
                return;
            }
            GSOFeatureDataset newFeatureDataset = ds.CreateFeatureDataset(newLayerName);

            if (newFeatureDataset == null)
            {
                MessageBox.Show("新建图层的名称不符合要求!", "提示");
                return;
            }
            if (radioButtonUseTemplate.Checked == true)
            {
                string   shpLayerName = comboBoxShpLayerList.Text;
                GSOLayer shpLayer     = globeControl1.Globe.Layers.GetLayerByCaption(shpLayerName);
                if (shpLayer == null)
                {
                    MessageBox.Show("您选择的图层模板不存在!", "提示");
                    return;
                }
                if (shpLayer.Dataset != null && shpLayer.Dataset is GSOFeatureDataset)
                {
                    GSOFeatureDataset shpFeatureDataset = shpLayer.Dataset as GSOFeatureDataset;
                    for (int i = 0; i < shpFeatureDataset.FieldCount; i++)
                    {
                        GSOFieldAttr fielddef = shpFeatureDataset.GetField(i);

                        GSOFieldAttr field = new GSOFieldAttr();
                        field.Name      = fielddef.Name;
                        field.Type      = fielddef.Type;
                        field.Width     = fielddef.Width;
                        field.Precision = fielddef.Precision;
                        bool res = newFeatureDataset.AddField(field);
                    }

                    newFeatureDataset.Save();
                    MessageBox.Show("图层创建成功!", "提示");
                }
                else
                {
                    MessageBox.Show("您选择的图层模板不是矢量图层!", "提示");
                    return;
                }
            }
            else if (radioButtonUseCustom.Checked == true)
            {
                int rowCount = dataGridView1.Rows.Count;
                for (int i = 0; i < rowCount; i++)
                {
                    string        fieldName         = dataGridView1.Rows[i].Cells[0].Value.ToString();
                    string        fieldType         = dataGridView1.Rows[i].Cells[1].Value.ToString();
                    string        fieldWidth        = dataGridView1.Rows[i].Cells[2].Value.ToString();
                    string        fieldPrecision    = dataGridView1.Rows[i].Cells[3].Value.ToString();
                    EnumFieldType enumFieldType     = EnumFieldType.Text;
                    int           intFieldWidth     = 2000;
                    int           intFieldPrecision = 0;
                    if (fieldType == "Double")
                    {
                        enumFieldType = EnumFieldType.Double;
                        intFieldWidth = 8;
                        if (int.TryParse(fieldPrecision, out intFieldPrecision) == false)
                        {
                            intFieldPrecision = 2;
                        }
                    }
                    else if (fieldType == "Int32")
                    {
                        enumFieldType = EnumFieldType.INT32;
                        intFieldWidth = 4;
                    }
                    else if (fieldType == "Date")
                    {
                        enumFieldType = EnumFieldType.Date;
                        intFieldWidth = 7;
                    }
                    else
                    {
                        int.TryParse(fieldWidth, out intFieldWidth);
                    }


                    GSOFieldAttr field = new GSOFieldAttr();
                    field.Name  = fieldName;
                    field.Type  = enumFieldType;
                    field.Width = intFieldWidth;
                    if (field.Type == EnumFieldType.Double)
                    {
                        field.Precision = intFieldPrecision;
                    }
                    bool res = newFeatureDataset.AddField(field);
                }
                newFeatureDataset.Save();
                MessageBox.Show("图层创建成功!", "提示");
            }
        }
        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("数据集名称不能以数字开头!", "提示");
            }
        }