コード例 #1
0
        private void buttonDelAttribute_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要删除该属性字段?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    GSOFeatureLayer pFeatureLayer = geoLayer as GSOFeatureLayer;
                    if (pFeatureLayer == null)
                    {
                        return;
                    }
                    GSOFeatureDataset dataset = pFeatureLayer.Dataset as GSOFeatureDataset;

                    dataset.DeleteField(listBoxAttribute.SelectedItem.ToString());

                    if (listBoxAttribute.SelectedItem != null)
                    {
                        listBoxAttribute.Items.Remove(listBoxAttribute.SelectedItem);
                        dataset.SaveAs(@"F:\新建文件夹");
                        MessageBox.Show("删除字段成功!", "提示!");
                    }
                    if (m_globeControl != null)
                    {
                        m_globeControl.Refresh();
                    }
                }
                catch (System.Exception exp)
                {
                    Log.PublishTxt(exp);
                }
            }
        }
コード例 #2
0
        private void cbox_Layers_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbox_Layers.SelectedItem == null)
            {
                return;
            }
            GSOLayer m_layer = globeControl1.Globe.Layers.GetLayerByCaption(cbox_Layers.SelectedItem.ToString().Trim());//获取当前选择的layer图层

            if (m_layer == null)
            {
                return;
            }
            listBox_Field.Items.Clear();
            GSOFeatureLayer flayer = m_layer as GSOFeatureLayer;

            if (flayer == null)
            {
                return;
            }
            sourcefDataset = m_layer.Dataset as GSOFeatureDataset;
            if (sourcefDataset == null)
            {
                return;
            }
            sourcefDataset.Open();
            for (int j = 0; j < sourcefDataset.FieldCount; j++)
            {
                GSOFieldAttr fieldef = sourcefDataset.GetField(j);
                listBox_Field.Items.Add(fieldef.Name);
            }
            //设置当前选择字段为第一个
            listBox_Field.SelectedIndex = 0;
            //将描述信息修改
            label3.Text = "SELECT * FROM " + m_layer.Caption + " WHERE:";
        }
コード例 #3
0
        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);
        }
コード例 #4
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;
        }
コード例 #5
0
        private void buttonAddAttribute_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要添加该属性字段?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    GSOFeatureLayer pFeatureLayer = geoLayer as GSOFeatureLayer;
                    if (pFeatureLayer == null)
                    {
                        return;
                    }
                    GSOFeatures       feats     = pFeatureLayer.GetAllFeatures();
                    GSOFeatureDataset dateset   = pFeatureLayer.Dataset as GSOFeatureDataset;
                    GSOFieldAttr      fieldattr = new GSOFieldAttr();

                    fieldattr.Name = textBoxAddAttributeName.Text;
                    switch (comboBoxAddAttributeType.SelectedIndex)
                    {
                    case 0:
                        fieldattr.Type  = EnumFieldType.Text;
                        fieldattr.Width = 2000;
                        break;

                    case 1:
                        fieldattr.Type = EnumFieldType.Double;
                        break;

                    case 2:
                        //fieldattr.Type = EnumFieldType.INT16;
                        //fieldattr.Type = EnumFieldType.INT32;
                        fieldattr.Type = EnumFieldType.INT64;
                        break;

                    case 3:
                        fieldattr.Type = EnumFieldType.Date;
                        break;
                    }

                    dateset.AddField(fieldattr);
                    dateset.Save();
                    listBoxAttribute.Items.Add(fieldattr.Name);

                    MessageBox.Show("添加属性字段成功!", "提示!");

                    if (m_globeControl != null)
                    {
                        m_globeControl.Refresh();
                    }
                }
                catch (System.Exception exp)
                {
                    Log.PublishTxt(exp);
                }
            }
        }
コード例 #6
0
        //获取字段值
        private void comboBoxConditionFieldName_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (layer == null)
            {
                MessageBox.Show("请先选择一个图层!");
                return;
            }
            comboBoxConditionFieldValue.Items.Clear();
            try
            {
                for (int i = 0; i < layer.GetAllFeatures().Length; i++)
                {
                    GSOFeature f = layer.GetAt(i);
                    if (f != null)
                    {
                        object fieldValue = f.GetValue(comboBoxConditionFieldName.Text);
                        if (f != null && fieldValue != null && comboBoxConditionFieldValue.Items.Contains(fieldValue) == false)
                        {
                            comboBoxConditionFieldValue.Items.Add(fieldValue);
                        }
                    }
                }
                GSOFeatureDataset featureDataset = layer.Dataset as GSOFeatureDataset;
                if (featureDataset != null)
                {
                    GSOFieldAttr field = featureDataset.GetField(comboBoxConditionFieldName.Text);
                    if (field != null)
                    {
                        switch (field.Type)
                        {
                        case EnumFieldType.Text:
                            comboBoxCondition.Items.Clear();
                            comboBoxCondition.Items.Add("=");
                            break;

                        case EnumFieldType.Double:
                        case EnumFieldType.INT32:
                        case EnumFieldType.Date:
                            comboBoxCondition.Items.Clear();
                            comboBoxCondition.Items.Add("=");
                            comboBoxCondition.Items.Add(">=");
                            comboBoxCondition.Items.Add("<=");
                            comboBoxCondition.Items.Add(">");
                            comboBoxCondition.Items.Add("<");
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
コード例 #7
0
ファイル: Utility.cs プロジェクト: StarU/qkKL6Dgf12
 public static GSOFeature FindFeatureByUserID(GSOFeatureDataset featdataset,string fieldname,string value)
 {
     GSOFeatures feats = featdataset.GetAllFeatures();
     for (int i = 0; i < feats.Length; i++)
     {
         GSOFeature feat = feats[i];
         if (feat.GetFieldAsString(fieldname) == value)
         {
             return feat;
         }
     }
     return null;
 }
コード例 #8
0
        private void comboBoxLayer2_SelectedIndexChanged(object sender, EventArgs e)
        {
            GSOLayer          l      = ctl.Globe.Layers[comboBoxLayerTarget.SelectedIndex];
            GSOFeatureDataset flayer = l.Dataset as GSOFeatureDataset;

            comboBoxFiledTarget.Items.Clear();
            comboBoxChangeTarget1.Items.Clear();
            for (int j = 0; j < flayer.FieldCount; j++)
            {
                comboBoxFiledTarget.Items.Add(flayer.GetField(j).Name);
                comboBoxChangeTarget1.Items.Add(flayer.GetField(j).Name);
            }
        }
コード例 #9
0
ファイル: Utility.cs プロジェクト: zhongketuxin/qkKL6Dgf12
        public static GSOFeature FindFeatureByUserID(GSOFeatureDataset featdataset, string fieldname, string value)
        {
            GSOFeatures feats = featdataset.GetAllFeatures();

            for (int i = 0; i < feats.Length; i++)
            {
                GSOFeature feat = feats[i];
                if (feat.GetFieldAsString(fieldname) == value)
                {
                    return(feat);
                }
            }
            return(null);
        }
コード例 #10
0
        void mGlobeControl_MouseUp(object sender, MouseEventArgs e)//单击添加模型
        {
            if (e.Button == MouseButtons.Left)
            {
                GSOPoint3d newpoint;
                GSOLayer   templayer;
                GSOFeature feature1 = mGlobeControl.Globe.HitTest(e.X, e.Y, out templayer, out newpoint, false, true, 0);
                if (newpoint.X == 0 && newpoint.Y == 0 && newpoint.Z == 0)
                {
                    newpoint = mGlobeControl.Globe.ScreenToScene(e.X, e.Y);
                }
                if (newpoint == point)
                {
                    GSOPoint3d pt = new GSOPoint3d();
                    pt.X = newpoint.X;
                    pt.Y = newpoint.Y;
                    pt.Z = newpoint.Z;

                    if (filePath != null && filePath != "")
                    {
                        if (mGlobeControl.Globe.Action == EnumAction3D.SelectObject)
                        {
                            GSOFeature newfeature = null;
                            if (mGlobeControl.Globe.DestLayerFeatureAdd.Dataset != null && mGlobeControl.Globe.DestLayerFeatureAdd.Dataset.IsFeatureDataset == true)
                            {
                                GSOFeatureDataset featureDataset = mGlobeControl.Globe.DestLayerFeatureAdd.Dataset as GSOFeatureDataset;
                                newfeature = featureDataset.CreateFeature();
                            }
                            else
                            {
                                newfeature = new GSOFeature();
                            }
                            newfeature.Name = Path.GetFileNameWithoutExtension(filePath) + "_" + iModelCount.ToString();
                            GSOGeoModel model = new GSOGeoModel();

                            model.FilePath = filePath;

                            model.Position      = pt;
                            newfeature.Geometry = model;
                            mGlobeControl.Globe.DestLayerFeatureAdd.AddFeature(newfeature);

                            iModelCount++;
                        }
                    }
                }
            }
        }
コード例 #11
0
        private void Frm_EditorAttributes_Load(object sender, EventArgs e)
        {
            GSOFeatureLayer gsoFeatureLayer = geoLayer as GSOFeatureLayer;

            if (gsoFeatureLayer == null)
            {
                MessageBox.Show("该数据不是属性数据,属性值为空!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            GSOFeatureDataset flayer = gsoFeatureLayer.Dataset as GSOFeatureDataset;

            for (int i = 0; i < flayer.FieldCount; i++)
            {
                GSOFieldAttr field = flayer.GetField(i);
                listBoxAttribute.Items.Add(field.Name);
                //labelAttributeType.Text = "图层属性类型为:" + field.Type.ToString() + "类型";
            }
        }
コード例 #12
0
        private void listBoxAttribute_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBoxAttribute.SelectedItem != null)
            {
                GSOFeatureLayer gsoFeatureLayer = geoLayer as GSOFeatureLayer;
                if (gsoFeatureLayer == null)
                {
                    MessageBox.Show("该数据不是属性数据,属性值为空!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                GSOFeatureDataset flayer = gsoFeatureLayer.Dataset as GSOFeatureDataset;

                GSOFieldAttr field = flayer.GetField(listBoxAttribute.SelectedItem.ToString());


                labelAttributeType.Text = "图层属性类型为:" + field.Type.ToString() + " 类型";
            }
        }
コード例 #13
0
        private void comboBoxLayers_SelectedIndexChanged(object sender, EventArgs e)
        {
            string layerCaption = comboBoxLayers.Text;

            layer = globeControl1.Globe.Layers.GetLayerByCaption(layerCaption);
            if (layer.Dataset.IsFeatureDataset)
            {
                GSOFeatureDataset data = (GSOFeatureDataset)layer.Dataset;
                if (data.FieldCount <= 0)
                {
                    return;
                }
                for (int i = 0; i < data.FieldCount; i++)
                {
                    comboBoxUpdateFieldName.Items.Add(data.GetField(i).Name); //绑定图层中的字段
                    comboBoxConditionFieldName.Items.Add(data.GetField(i).Name);
                }
            }
        }
コード例 #14
0
 //删除
 private void buttonDelete_Click(object sender, EventArgs e)
 {
     if (listViewFields.CheckedItems.Count <= 0)
     {
         MessageBox.Show("请选择要删除的字段!", "提示");
         return;
     }
     if (layer != null)
     {
         GSOFeatureDataset dataset = layer.Dataset as GSOFeatureDataset;
         if (dataset != null)
         {
             for (int i = 0; i < listViewFields.CheckedItems.Count; i++)
             {
                 string fieldName = listViewFields.CheckedItems[i].Text;
                 dataset.DeleteField(fieldName.Trim());
                 dataGridView1.Columns.Remove(fieldName.Trim());
             }
         }
     }
     this.Close();
 }
コード例 #15
0
        private bool isSameType(GSOFeatureDataset sourceDataset, string fieldSourceName, GSOFeatureDataset targetDataset, string fieldTargetName)
        {
            if (sourceDataset == null || targetDataset == null)
            {
                return(false);
            }
            GSOFieldAttr sourceField = sourceDataset.GetField(fieldSourceName);
            GSOFieldAttr targetField = targetDataset.GetField(fieldTargetName);

            if (sourceField == null || targetField == null)
            {
                return(false);
            }
            if (sourceField.Type == targetField.Type)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #16
0
        private void FrmBatchUpdateFieldValue_Load(object sender, EventArgs e)
        {
            GSOLayers layers = globeControl1.Globe.Layers;

            for (int i = 0; i < layers.Count; i++)
            {
                GSOLayer lay = layers[i];
                if (lay.Dataset.IsFeatureDataset)
                {
                    GSOFeatureDataset data = (GSOFeatureDataset)lay.Dataset;
                    if (data.FieldCount <= 0)
                    {
                        continue;
                    }
                    comboBoxLayers.Items.Add(lay.Caption); //绑定图层
                }
            }
            if (comboBoxLayers.Items.Count > 0)
            {
                comboBoxLayers.SelectedIndex = 0;
            }
            panel1.Enabled = false;
        }
コード例 #17
0
        private void cbox_Layers_SelectedIndexChanged(object sender, EventArgs e)
        {
            GSOLayer m_layer = globeControl1.Globe.Layers.GetLayerByCaption(cbox_Layers.SelectedItem.ToString().Trim());//获取当前选择的layer图层

            if (m_layer == null || m_layer.Dataset == null || m_layer.Dataset.DataSource == null)
            {
                return;
            }
            connectParams = Utility.getConnectParamsByDatasourceName(globeControl1, m_layer.Dataset.DataSource.Name);
            if (connectParams == null)
            {
                return;
            }

            listBox_Field.Items.Clear();
            GSOFeatureLayer flayer = m_layer as GSOFeatureLayer;

            sourcefDataset = m_layer.Dataset as GSOFeatureDataset;
            if (sourcefDataset != null)
            {
                sourcefDataset.Open();

                for (int j = 0; j < sourcefDataset.FieldCount; j++)
                {
                    GSOFieldAttr fieldef = sourcefDataset.GetField(j);
                    listBox_Field.Items.Add(fieldef.Name);
                }
                //设置当前选择字段为第一个
                if (listBox_Field.Items.Count > 0)
                {
                    listBox_Field.SelectedIndex = 0;
                }
                //将描述信息修改
                label3.Text = "SELECT * FROM " + sourcefDataset.Name + " WHERE:";
            }
        }
コード例 #18
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 (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);
            }
        }
コード例 #19
0
ファイル: FrmAddWell.cs プロジェクト: zhongketuxin/qkKL6Dgf12
        //导入数据库

        /*     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);
        }
コード例 #20
0
 private bool isSameType(GSOFeatureDataset sourceDataset, string fieldSourceName,GSOFeatureDataset targetDataset, string fieldTargetName)
 {
     if (sourceDataset == null || targetDataset == null)
     {
         return false;
     }
     GSOFieldAttr sourceField = sourceDataset.GetField(fieldSourceName);
     GSOFieldAttr targetField = targetDataset.GetField(fieldTargetName);
     if (sourceField == null || targetField == null)
     {
         return false;
     }
     if (sourceField.Type == targetField.Type)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
コード例 #21
0
 private void cbox_Layers_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cbox_Layers.SelectedItem == null)
     {
         return;
     }
     GSOLayer m_layer = globeControl1.Globe.Layers.GetLayerByCaption(cbox_Layers.SelectedItem.ToString().Trim());//获取当前选择的layer图层
     if (m_layer == null)
     {
         return;
     }
     listBox_Field.Items.Clear();
     GSOFeatureLayer flayer = m_layer as GSOFeatureLayer;
     if (flayer == null)
     {
         return;
     }
     sourcefDataset = m_layer.Dataset as GSOFeatureDataset;
     if (sourcefDataset == null)
     {
         return;
     }
     sourcefDataset.Open();
     for (int j = 0; j < sourcefDataset.FieldCount; j++)
     {
         GSOFieldAttr fieldef = sourcefDataset.GetField(j);
         listBox_Field.Items.Add(fieldef.Name);
     }
     //设置当前选择字段为第一个
     listBox_Field.SelectedIndex = 0;
     //将描述信息修改
     label3.Text = "SELECT * FROM " + m_layer.Caption + " WHERE:";
 }
コード例 #22
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            if (comboBoxDataSourceList.SelectedItem == null)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("请选择一个目标数据源!", "提示");
                return;
            }
            GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());

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

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

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

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

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

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

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

                    MessageBox.Show("拓扑数据创建成功,阀门匹配完成!共匹配了 " + nMatchNum + " 个阀门!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("拓扑数据创建成功!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                this.Cursor = Cursors.Default;
                this.Close();
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show(ex.Message);
                Log.PublishTxt(ex);
            }
        }
コード例 #23
0
        private void one2Multi(GSOGeoPolyline3D line, int num_width, int num_height, double interval, GSOPipeLineStyle3D style, GSOFeatureDataset layer, string name, GSOFeature oldfeat)
        {
            line = LatLon2Coord_Line(line);

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

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

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

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

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

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

            line.MoveZ(height_all / -2);

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

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

                    templine = Coord2LatLon_Line(templine);

                    templine.MoveZ(interval * j);

                    GSOFeature feat = layer.CreateFeature();
                    feat.Geometry       = templine;
                    feat.Geometry.Style = style;
                    feat.Name           = name;
                    SetFields(oldfeat, feat);
                    layer.AddFeature(feat);
                }
            }
        }
コード例 #24
0
        private bool valiPipeData()
        {
            if (comboBoxShpLayerList.SelectedItem == null)
            {
                MessageBox.Show("请选择一个shp图层!");
                return(false);
            }
            GSOLayer sourceLayer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());

            if (sourceLayer == null)
            {
                MessageBox.Show("选择的图层为空!");
                return(false);
            }
            GSOFeatures       features    = sourceLayer.GetAllFeatures(true);
            GSOFeatureDataset featDataSet = sourceLayer.Dataset as GSOFeatureDataset;

            if (featDataSet == null)
            {
                MessageBox.Show("选择的图层不是矢量图层!");
                return(false);
            }
            if (featDataSet.FieldCount <= 0)
            {
                MessageBox.Show("图层中字段数必须大于0");
                return(false);
            }
            GSOFieldAttr fieldDeep1 = featDataSet.GetField("Deep1");

            if (fieldDeep1 == null)
            {
                MessageBox.Show("Deep1字段不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            if (fieldDeep1.Type != EnumFieldType.Double && fieldDeep1.Type != EnumFieldType.Float && fieldDeep1.Type != EnumFieldType.INT16 && fieldDeep1.Type != EnumFieldType.INT32)
            {
                MessageBox.Show("Deep1必须为数值类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            GSOFieldAttr fieldDeep2 = featDataSet.GetField("Deep2");

            if (fieldDeep2 == null)
            {
                MessageBox.Show("Deep2字段不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            if (fieldDeep2.Type != EnumFieldType.Double && fieldDeep2.Type != EnumFieldType.Float && fieldDeep2.Type != EnumFieldType.INT16 && fieldDeep2.Type != EnumFieldType.INT32)
            {
                MessageBox.Show("Deep2必须为数值类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            List <string> lst = new List <string>();

            for (int j = 0; j < features.Length; j++)
            {
                if (!lst.Contains(features[j].GetFieldAsString("Handle")))
                {
                    lst.Add(features[j].GetFieldAsString("Handle"));
                }
                else
                {
                    MessageBox.Show("Handle字段必须唯一!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(false);
                }
            }
            return(true);
        }
コード例 #25
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));
                        }
                    }
                }
                GSOFeatureDataset featdataset = CreateDBFeatureDataset(textBoxNewLayerName.Text);
                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;
                    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)
                    {
                        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 (!yb_cns.ContainsKey(fielddef.Name))
                        {
                            continue;
                        }
                        if (f.GetValue(fielddef.Name) == null)
                        {
                            continue;
                        }
                        string fieldName = yb_cns.ContainsKey(fielddef.Name) == true ? yb_cns[fielddef.Name].ToString() : fielddef.Name;
                        feature.SetValue(fieldName, f.GetValue(fielddef.Name));
                    }
                    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);
            }
        }
コード例 #26
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("请先添加数据!", "提示");
                return;
            }

            panel_NoValue.Enabled              = false;
            panel_PolygonRestric.Enabled       = false;
            panel_thread.Enabled               = false;
            checkBoxNoValue.Enabled            = false;
            checkBox_MulThread.Enabled         = false;
            checkBox_polygonRestricted.Enabled = false;

            rasterImporter = new GSOBatchRasterImporter();
            //0:处理影像   1:处理地形
            rasterImporter.ImportType(Enum_ImportType.IT_Image);
            //无效值过滤
            bool useNoValueFilter = checkBoxNoValue.Checked;
            int  R = 0, G = 0, B = 0;
            int  valueYuZhi = 0;

            if (useNoValueFilter == true)
            {
                valueYuZhi = int.Parse(textBox_ThresholdValue.Text);
                try
                {
                    R = int.Parse(textBox_R.Text);
                    G = int.Parse(textBox_G.Text);
                    B = int.Parse(textBox_B.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("无效值输入有误,请重新输入!", "提示");
                    return;
                }
                rasterImporter.NoValueFilterUsed = true;
                rasterImporter.SetFilterParament(Color.FromArgb(R, G, B), 0, valueYuZhi);
            }

            //多边形过滤

            bool polygonRes = checkBox_polygonRestricted.Checked;

            if (polygonRes == true)
            {
                if (comboBox_Model.SelectedIndex == 1)
                {
                    rasterImporter.RestricMode(Enum_RestricMode.RM_RougnFilter);
                }
                else
                {
                    rasterImporter.RestricMode(Enum_RestricMode.RM_PrecisionFilter);
                }
                string            polygonPath = textBox_polygonPath.Text;
                GSODataManager    dManager    = new GSODataManager();
                GSOFeatureDataset dataset     = dManager.AddFileDataset(polygonPath) as GSOFeatureDataset;
                GSOFeatures       feature     = dataset.GetAllFeatures();
                rasterImporter.SetRestrictedRegions(feature);//多边形范围
            }
            else
            {
                rasterImporter.RestricMode(Enum_RestricMode.RM_NoFilter);
            }

            //多线程
            bool useMulThread = checkBox_MulThread.Checked;
            int  maxThreadNum = 30;  //线程的个数
            int  maxCacheSize = 100; //单个文件的缓存,单位M

            if (useMulThread == true)
            {
                maxThreadNum = int.Parse(textBox_threadNum.Text);
                maxCacheSize = int.Parse(textBox_maxCacheSize.Text);
                rasterImporter.MutiThread      = true;         //多线程
                rasterImporter.MaxThreadNum    = maxThreadNum; //最大线程数
                rasterImporter.ThreadCacheSize = maxCacheSize; //最大缓存
            }

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string strSrcDataPath  = dt.Rows[i][0].ToString();
                string strDestDataPath = dt.Rows[i][2].ToString();
                rasterImporter.AddProcessData(strSrcDataPath, strDestDataPath, "", null);//添加数据
            }

            //单个进度条
            rasterImporter.BIDGetSubProgressInfoEvent -= rasterImporter_BIDGetSubProgressInfoEvent;
            rasterImporter.BIDGetSubProgressInfoEvent += rasterImporter_BIDGetSubProgressInfoEvent;
            //总进度条
            rasterImporter.BIDGetProgressInfoEvent -= rasterImporter_BIDGetProgressInfoEvent;
            rasterImporter.BIDGetProgressInfoEvent += rasterImporter_BIDGetProgressInfoEvent;

            subCurrentValue                = 0;
            indexFile                      = 1;
            dtStart                        = DateTime.Now;
            dtStartSub                     = dtStart;
            label_AllProcess.Text          = "总进度(" + 0 + "s)";
            label_CurrentProcess.Text      = "当前进度(" + 1 + "/" + dt.Rows.Count + ")";
            this.progressBar_All.Value     = 0;
            this.progressBar_Current.Value = 0;
            this.Cursor                    = Cursors.WaitCursor;
            button_OK.Enabled              = false;

            //在单独的线程中执行操作
            workThread = new Thread(this.ProcessDataThreadFunc);
            workThread.Start();

            //更新进度条
            uithread = new Thread(new ThreadStart(this.UpdateProgressThreadFunc));
            uithread.Start();
        }
コード例 #27
0
        private void valiPipedata(GSOLayer layer)
        {
            txtMessage.Text = "";
            if (layer != null)
            {
                GSOFeatureDataset featDataSet        = layer.Dataset as GSOFeatureDataset;
                List <string>     lstField           = new List <string>();
                List <string>     listFieldType_Text = new List <string>();
                for (int i = 0; i < featDataSet.FieldCount; i++)
                {
                    string fieldName = featDataSet.GetField(i).Name;
                    lstField.Add(fieldName);
                    if (fields_types.ContainsKey(fieldName))
                    {
                        string fieldType = fields_types[fieldName].ToString().ToUpper();
                        switch (featDataSet.GetField(i).Type)
                        {
                        case EnumFieldType.Text:
                            if (fieldType != "string".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            listFieldType_Text.Add(fieldName);
                            break;

                        case EnumFieldType.INT32:
                            if (fieldType != "int".ToUpper() && fieldType != "double".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            break;

                        case EnumFieldType.INT16:
                            if (fieldType != "int".ToUpper() && fieldType != "double".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            break;

                        case EnumFieldType.Double:
                            if (fieldType != "double".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            break;

                        case EnumFieldType.Date:
                            if (fieldType != "date".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            break;
                        }
                    }
                    else
                    {
                        txtMessage.Text += "警告:配置文件中不包含\"" + fieldName + "\"字段\r\n";
                    }
                }
                if (!lstField.Contains("Deep1"))
                {
                    txtMessage.Text += "Deep1字段不存在!\r\n";
                }
                else
                {
                    GSOFieldAttr fieldDeep1 = featDataSet.GetField("Deep1");
                    if (fieldDeep1.Type != EnumFieldType.Double && fieldDeep1.Type != EnumFieldType.Float && fieldDeep1.Type != EnumFieldType.INT16 && fieldDeep1.Type != EnumFieldType.INT32)
                    {
                        txtMessage.Text += "Deep1字段必须为数值类型\r\n";
                    }
                }
                if (!lstField.Contains("Deep2"))
                {
                    txtMessage.Text += "Deep2字段不存在!\r\n";
                }
                else
                {
                    GSOFieldAttr fieldDeep1 = featDataSet.GetField("Deep2");
                    if (fieldDeep1.Type != EnumFieldType.Double && fieldDeep1.Type != EnumFieldType.Float && fieldDeep1.Type != EnumFieldType.INT16 && fieldDeep1.Type != EnumFieldType.INT32)
                    {
                        txtMessage.Text += "Deep2字段必须为数值类型\r\n";
                    }
                }
                if (!lstField.Contains("Diameter"))
                {
                    txtMessage.Text += "Diameter字段不存在!\r\n";
                }
                else
                {
                    GSOFieldAttr fieldDeep1 = featDataSet.GetField("Diameter");
                    if (fieldDeep1.Type != EnumFieldType.Double && fieldDeep1.Type != EnumFieldType.Float && fieldDeep1.Type != EnumFieldType.INT16 && fieldDeep1.Type != EnumFieldType.INT32)
                    {
                        txtMessage.Text += "Diameter字段必须为数值类型\r\n";
                    }
                }
                if (!lstField.Contains("Handle"))
                {
                    txtMessage.Text += "Handle字段不存在!\r\n";
                }
                List <string> lstHandle = new List <string>();
                for (int i = 0; i < layer.GetAllFeatures().Length; i++)
                {
                    GSOFeature f = layer.GetAt(i);
                    for (int j = 0; j < listFieldType_Text.Count; j++)
                    {
                        string fieldName = listFieldType_Text[j];
                        if (fields_types.ContainsKey(fieldName))
                        {
                            if (f.GetValue(fieldName).ToString().Trim().Length > 8000)
                            {
                                txtMessage.Text += "ID为" + f.ID + "的要素的字段" + fieldName + "的长度大于8000 !\r\n";
                            }
                        }
                    }
                    if (f.GetFieldAsFloat("Diameter") <= 0)
                    {
                        txtMessage.Text += "ID为" + f.ID + "\"Diameter\"字段中的值必须大于0 \r\n";
                    }
                    if (!lstHandle.Contains(f.GetFieldAsString("Handle")))
                    {
                        lstHandle.Add(f.GetFieldAsString("Handle"));
                    }
                    else
                    {
                        txtMessage.Text += "ID为" + f.ID + "的\"Handle\"字段中的值重复\r\n";
                    }
                }
            }
        }
コード例 #28
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);
            }
        }
コード例 #29
0
        private void one2Multi(GSOGeoPolyline3D line, int num_width, int num_height, double interval, GSOPipeLineStyle3D style, GSOFeatureDataset layer,string name,GSOFeature oldfeat)
        {
            line = LatLon2Coord_Line(line);

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

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

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

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

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

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

            line.MoveZ(height_all / -2);

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

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

                    templine = Coord2LatLon_Line(templine);

                    templine.MoveZ(interval*j);

                    GSOFeature feat = layer.CreateFeature();
                    feat.Geometry = templine;
                    feat.Geometry.Style = style;
                    feat.Name = name;
                    SetFields(oldfeat, feat);
                    layer.AddFeature(feat);
                }
            }
        }
コード例 #30
0
        private void cbox_Layers_SelectedIndexChanged(object sender, EventArgs e)
        {
            GSOLayer m_layer = globeControl1.Globe.Layers.GetLayerByCaption(cbox_Layers.SelectedItem.ToString().Trim());//获取当前选择的layer图层
            if (m_layer == null || m_layer.Dataset == null || m_layer.Dataset.DataSource == null)
                return;
            connectParams = Utility.getConnectParamsByDatasourceName(globeControl1, m_layer.Dataset.DataSource.Name);
            if (connectParams == null)
            {
                return;
            }

            listBox_Field.Items.Clear();
            GSOFeatureLayer flayer = m_layer as GSOFeatureLayer;
            sourcefDataset = m_layer.Dataset as GSOFeatureDataset;
            if (sourcefDataset != null)
            {
                sourcefDataset.Open();

                for (int j = 0; j < sourcefDataset.FieldCount; j++)
                {
                    GSOFieldAttr fieldef = sourcefDataset.GetField(j);
                    listBox_Field.Items.Add(fieldef.Name);
                }
                //设置当前选择字段为第一个
                if (listBox_Field.Items.Count > 0)
                {
                    listBox_Field.SelectedIndex = 0;
                }
                //将描述信息修改
                label3.Text = "SELECT * FROM " + sourcefDataset.Name + " WHERE:";
            }
        }
コード例 #31
0
        private bool valiValvedata()
        {
            if (comboBoxShpLayerList.SelectedItem == null)
            {
                MessageBox.Show("请选择一个shp图层!");
                return(false);
            }
            GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());

            if (layer == null)
            {
                MessageBox.Show("选择的图层为空!");
                return(false);
            }
            if (layer != null)
            {
                GSOFeatureDataset featDataSet = layer.Dataset as GSOFeatureDataset;

                if (featDataSet.FieldCount <= 0)
                {
                    MessageBox.Show("图层中字段数必须大于0");
                    return(false);
                }
                GSOFieldAttr fieldID = featDataSet.GetField("编号");
                if (fieldID == null)
                {
                    MessageBox.Show("编号 字段不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(false);
                }
                GSOFieldAttr fieldModelPath = featDataSet.GetField("模型路径");
                if (fieldModelPath == null)
                {
                    MessageBox.Show("模型路径 字段不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(false);
                }
                GSOFieldAttr fieldZ = featDataSet.GetField("Z坐标");
                if (fieldZ.Type != EnumFieldType.Double && fieldZ.Type != EnumFieldType.Float && fieldZ.Type != EnumFieldType.INT16 && fieldZ.Type != EnumFieldType.INT32)
                {
                    MessageBox.Show("Z坐标 必须为数值类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(false);
                }

                for (int i = 0; i < layer.GetAllFeatures().Length; i++)
                {
                    GSOFeature f = layer.GetAt(i);
                    for (int j = 0; j < featDataSet.FieldCount; j++)
                    {
                        GSOFieldAttr field = featDataSet.GetField(j);
                        if (field.Type == EnumFieldType.Text)
                        {
                            if (f.GetValue(j).ToString().Trim().Length > 5000)
                            {
                                MessageBox.Show("ID为" + f.ID + "的要素的字段" + field.Name + "的长度大于5000 !\r\n", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                return(false);
                            }
                        }
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #32
0
        private void valiGongJingdata(GSOLayer layer)
        {
            txtMessage.Text = "";
            if (layer != null)
            {
                GSOFeatureDataset featDataSet        = layer.Dataset as GSOFeatureDataset;
                List <string>     lstField           = new List <string>();
                List <string>     listFieldType_Text = new List <string>();
                for (int i = 0; i < featDataSet.FieldCount; i++)
                {
                    string fieldName = featDataSet.GetField(i).Name;
                    lstField.Add(fieldName);
                    if (gj_types.ContainsKey(fieldName))
                    {
                        string fieldType = gj_types[fieldName].ToString().ToUpper();
                        switch (featDataSet.GetField(i).Type)
                        {
                        case EnumFieldType.Text:
                            if (fieldType != "string".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            listFieldType_Text.Add(fieldName);
                            break;

                        case EnumFieldType.INT32:
                            if (fieldType != "int".ToUpper() && fieldType != "double".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            break;

                        case EnumFieldType.INT16:
                            if (fieldType != "int".ToUpper() && fieldType != "double".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            break;

                        case EnumFieldType.Double:
                            if (fieldType != "double".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            break;

                        case EnumFieldType.Date:
                            if (fieldType != "date".ToUpper())
                            {
                                txtMessage.Text += "" + fieldName + "数据类型不正确\r\n";
                            }
                            break;
                        }
                    }
                    else
                    {
                        txtMessage.Text += "警告:配置文件中不包含\"" + fieldName + "\"字段\r\n";
                    }
                    //if (fieldName == "井深")
                    //{
                    //    if (featDataSet.GetField(i).Type != EnumFieldType.Double)
                    //    {
                    //        txtMessage.Text += "井深字段数据类型不正确!\r\n";
                    //    }
                    //}
                    //if (fieldName == "管线点编码")
                    //{
                    //    if (featDataSet.GetField(i).Type != EnumFieldType.Double)
                    //    {
                    //        txtMessage.Text += "管线点编码字段数据类型不正确!\r\n";
                    //    }
                    //}
                }
                if (!lstField.Contains("编号"))
                {
                    txtMessage.Text += "编号字段不存在!\r\n";
                }
                if (!lstField.Contains("管线点编码"))
                {
                    txtMessage.Text += "管线点编码字段不存在!\r\n";
                }
                if (!lstField.Contains("井深"))
                {
                    txtMessage.Text += "井深字段不存在!\r\n";
                }
                else
                {
                    GSOFieldAttr fieldZ = featDataSet.GetField("井深");
                    if (fieldZ.Type != EnumFieldType.Double && fieldZ.Type != EnumFieldType.Float && fieldZ.Type != EnumFieldType.INT16 && fieldZ.Type != EnumFieldType.INT32)
                    {
                        txtMessage.Text += "\"井深\"字段必须为数值类型 \r\n";
                    }
                }
                for (int i = 0; i < layer.GetAllFeatures().Length; i++)
                {
                    GSOFeature f = layer.GetAt(i);
                    for (int j = 0; j < listFieldType_Text.Count; j++)
                    {
                        string fieldName = listFieldType_Text[j];
                        if (gj_types.ContainsKey(fieldName))
                        {
                            if (f.GetValue(fieldName).ToString().Trim().Length > 8000)
                            {
                                txtMessage.Text += "名称为" + f.Name + "的要素的字段" + fieldName + "的长度大于8000 !\r\n";
                            }
                        }
                    }
                }
            }
        }
コード例 #33
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;
            }
            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("图层创建成功!", "提示");
            }
        }
コード例 #34
0
        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("数据复制成功!", "提示");
                    }
                }
            }
        }
コード例 #35
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;
        }