Example #1
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);
            }
        }
        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:";
        }
        private GSOFeatureDataset CreateDBFeatureDataset(string name)
        {
            if (comboBoxShpLayerList.SelectedItem == null)
            {
                MessageBox.Show("请选择一个Shp图层!", "提示");
                return(null);
            }
            GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(comboBoxShpLayerList.SelectedItem.ToString().Trim());

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

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

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

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

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

                    GSOFieldAttr field = new GSOFieldAttr();
                    field.Name      = fielddef.Name;
                    field.Type      = fielddef.Type;
                    field.Width     = fielddef.Width;
                    field.Precision = fielddef.Precision;
                    bool res = newFeatureDataset.AddField(field);
                }
                newFeatureDataset.Save();
            }
            return(newFeatureDataset);
        }
Example #4
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);
                }
            }
        }
Example #5
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);
            }
        }
        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() + " 类型";
            }
        }
        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() + "类型";
            }
        }
        private void btn_GetValue_Click(object sender, EventArgs e)
        {
            if (connectParams == null)
            {
                return;
            }
            try
            {
                listBox_Value.Items.Clear();

                for (int j = 0; j < sourcefDataset.FieldCount; j++)
                {
                    GSOFieldAttr fieldef = sourcefDataset.GetField(j);
                    if (listBox_Field.SelectedItem.ToString() == fieldef.Name && fieldef.Type == EnumFieldType.Text)
                    {
                        str1 = "'";
                        str2 = "'";
                    }
                }

                string sqltype = "select distinct " + listBox_Field.SelectedItem.ToString() + " from " + sourcefDataset.Name + " order by " + listBox_Field.SelectedItem.ToString() + "";

                DataTable table = OledbHelper.QueryTable(sqltype, connectParams);

                for (int i = 0; i < table.Rows.Count; i++)
                {
                    DataRow dr         = table.Rows[i];
                    string  colString1 = dr[0].ToString();
                    if (colString1 == null || colString1.Trim() == "")
                    {
                        continue;
                    }
                    string col = str1 + colString1 + str2;
                    listBox_Value.Items.Add(col);
                }
                str1 = "";
                str2 = "";
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
        //获取唯一值添加到listbox_Value中
        private void btn_GetValue_Click(object sender, EventArgs e)
        {
            if (listBox_Field.SelectedItem == null)
            {
                MessageBox.Show("请先选中一个字段!", "提示");
                return;
            }
            listBox_Value.Items.Clear();
            string       strSepratorOfString = "";
            GSOFieldAttr fieldef             = sourcefDataset.GetField(listBox_Field.SelectedItem.ToString().Trim());

            if (fieldef == null)
            {
                return;
            }
            if (fieldef.Type == EnumFieldType.Text)
            {
                strSepratorOfString = "'";
            }

            try
            {
                for (int i = 0; i < sourcefDataset.GetAllFeatures().Length; i++)
                {
                    GSOFeature feature = sourcefDataset.GetFeatureAt(i);
                    if (feature != null)
                    {
                        object fieldValue = feature.GetValue(listBox_Field.SelectedItem.ToString().Trim());
                        if (fieldValue != null && listBox_Value.Items.Contains(strSepratorOfString + fieldValue.ToString() + strSepratorOfString) == false)
                        {
                            listBox_Value.Items.Add(strSepratorOfString + fieldValue.ToString() + strSepratorOfString);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message);
            }
        }
Example #10
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);
            }
        }
        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:";
            }
        }
        private void Set()
        {
            if (listBoxCopyLayerList.SelectedItems.Count <= 0)
            {
                MessageBox.Show("请选择要复制的数据集!", "提示");
                return;
            }
            if (comboBoxTargetDataSource.SelectedItem == null)
            {
                MessageBox.Show("请选择目标数据源!", "提示");
                return;
            }
            if (checkBoxCopyOne.Checked == true && textboxNewLayerName.Text.Trim() == "")
            {
                MessageBox.Show("请给要复制的数据集命名!", "提示");
                return;
            }
            if (checkBoxCopyOne.Checked == true)
            {
                GSODataSource dsTarget = Utility.getDataSourceByFullName(globeControl1, comboBoxTargetDataSource.SelectedItem.ToString().Trim());
                if (dsTarget != null)
                {
                    GSODataset newDataset = dsTarget.GetDatasetByName(textboxNewLayerName.Text.Trim());
                    if (newDataset != null)
                    {
                        MessageBox.Show("输入的新的数据集的名称已存在目标数据源中!", "提示");
                        return;
                    }
                    GSOFeatureDataset newFeatureDataset = dsTarget.CreateFeatureDataset(textboxNewLayerName.Text.Trim());
                    if (newFeatureDataset == null)
                    {
                        MessageBox.Show("输入的新数据集的名称不符合要求!", "提示");
                        return;
                    }
                    GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());
                    if (ds != null)
                    {
                        GSODataset        dataset        = ds.GetDatasetByName(listBoxCopyLayerList.SelectedItem.ToString().Trim());
                        GSOFeatureDataset featureDataset = dataset as GSOFeatureDataset;
                        if (featureDataset != null)
                        {
                            try
                            {
                                featureDataset.Open();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "提示");
                                if (featureDataset.IsOpened == true)
                                {
                                    featureDataset.Close();
                                }
                                return;
                            }
                            //向新数据集写入字段
                            for (int i = 0; i < featureDataset.FieldCount; i++)
                            {
                                GSOFieldAttr fieldFromDs = featureDataset.GetField(i);
                                newFeatureDataset.AddField(fieldFromDs);
                            }

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

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

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

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

                            progressBar1.Value = j;
                        }
                        progressBar1.Visible = false;
                        MessageBox.Show("数据复制成功!", "提示");
                    }
                }
            }
        }
Example #13
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";
                    }
                }
            }
        }
Example #14
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";
                            }
                        }
                    }
                }
            }
        }
Example #15
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:";
            }
        }
 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;
     }
 }
Example #17
0
        private void button1_Click(object sender, EventArgs e)
        {
            GSOLayer          l1      = ctl.Globe.Layers[comboBoxLayerSource.SelectedIndex];
            GSOFeatureDataset flayer1 = l1.Dataset as GSOFeatureDataset;
            GSOLayer          l2      = ctl.Globe.Layers[comboBoxLayerTarget.SelectedIndex];
            GSOFeatureDataset flayer2 = l2.Dataset as GSOFeatureDataset;

            string sourceIDFieldName = comboBoxFieldSource.SelectedItem.ToString().Trim();
            string targetIDFieldName = comboBoxFiledTarget.SelectedItem.ToString().Trim();

            if (sourceIDFieldName == null || targetIDFieldName == null)
            {
                MessageBox.Show("请选择唯一标识字段!", "提示");
                return;
            }
            if (isSameType(flayer1, sourceIDFieldName, flayer2, targetIDFieldName) == false)
            {
                MessageBox.Show("请选择类型相同的唯一标识字段!", "提示");
                return;
            }
            //for (int i = 1; i <= changeCount; i++)
            {
                string sourceChangeFieldName = comboBoxChangeSource1.SelectedItem == null ? "" : comboBoxChangeSource1.SelectedItem.ToString().Trim();
                string targetChangeFieldName = comboBoxChangeTarget1.SelectedItem == null ? "" : comboBoxChangeTarget1.SelectedItem.ToString().Trim();
                if (sourceChangeFieldName == "" || targetChangeFieldName == "")
                {
                    MessageBox.Show("请选择要修改的字段!", "提示");
                    return;
                }
                if (isSameType(flayer1, sourceChangeFieldName, flayer2, targetChangeFieldName) == false)
                {
                    MessageBox.Show("请选择类型相同的要修改的字段!", "提示");
                    return;
                }
                for (int j = 0; j < flayer1.GetAllFeatures().Length; j++)
                {
                    if (flayer1.GetFeatureAt(j) == null)
                    {
                        continue;
                    }
                    object      fieldValue          = flayer1.GetFeatureAt(j).GetValue(sourceIDFieldName);
                    GSOFeatures targetLayerFeatures = flayer2.GetFeatureByFieldValue(targetIDFieldName, fieldValue.ToString().Trim(), true);
                    if (targetLayerFeatures != null)
                    {
                        for (int m = 0; m < targetLayerFeatures.Length; m++)
                        {
                            GSOFeature targetLayerFeature = targetLayerFeatures[m];
                            if (targetLayerFeature != null)
                            {
                                fieldValue = flayer1.GetFeatureAt(j).GetValue(sourceChangeFieldName);
                                if (flayer1.GetField(sourceChangeFieldName) != null)
                                {
                                    switch (flayer1.GetField(sourceChangeFieldName).Type)
                                    {
                                    case EnumFieldType.Double:
                                        double dFieldValue = 0.0;
                                        if (double.TryParse(fieldValue.ToString(), out dFieldValue) == true)
                                        {
                                            targetLayerFeature.SetFieldValue(targetChangeFieldName, dFieldValue);
                                        }
                                        break;

                                    case EnumFieldType.INT32:
                                        int intFieldValue = 0;
                                        if (int.TryParse(fieldValue.ToString(), out intFieldValue) == true)
                                        {
                                            targetLayerFeature.SetFieldValue(targetChangeFieldName, intFieldValue);
                                        }
                                        break;

                                    case EnumFieldType.DateTime:
                                        DateTime datatimeFieldValue = DateTime.Now;
                                        if (DateTime.TryParse(fieldValue.ToString(), out datatimeFieldValue) == true)
                                        {
                                            targetLayerFeature.SetFieldValue(targetChangeFieldName, datatimeFieldValue);
                                        }
                                        break;

                                    case EnumFieldType.Text:
                                        targetLayerFeature.SetFieldValue(targetChangeFieldName, fieldValue.ToString());
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            MessageBox.Show("修改成功!", "提示");
        }
Example #18
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);
        }
        private void btnCreateModel_Click(object sender, EventArgs e)
        {
            if (comboBoxDataSourceList.SelectedItem == null)
            {
                MessageBox.Show("请选择一个数据源!", "提示");
                return;
            }
            GSODataSource ds = Utility.getDataSourceByFullName(globeControl1, comboBoxDataSourceList.SelectedItem.ToString().Trim());

            if (ds == null)
            {
                MessageBox.Show("数据源不能为空!", "提示");
                return;
            }
            string newLayerName = textboxNewLayerName.Text.Trim();

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

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

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

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


                    GSOFieldAttr field = new GSOFieldAttr();
                    field.Name  = fieldName;
                    field.Type  = enumFieldType;
                    field.Width = intFieldWidth;
                    if (field.Type == EnumFieldType.Double)
                    {
                        field.Precision = intFieldPrecision;
                    }
                    bool res = newFeatureDataset.AddField(field);
                }
                newFeatureDataset.Save();
                MessageBox.Show("图层创建成功!", "提示");
            }
        }
 private void 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:";
 }
        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);
            }
        }
        public void SetDataTable()
        {
            this.Shown += new EventHandler(Frm_TableAttribute_Shown);
            GSOFeatureLayer   pFeatureLayer   = geoLayer as GSOFeatureLayer;
            GSOFeatureDataset pFeatureDataset = pFeatureLayer.Dataset as GSOFeatureDataset;

            if (pFeatureLayer == null || pFeatureDataset == null)
            {
                MessageBox.Show("该数据不是属性数据,属性表为空!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                isShow = false;
                return;
            }
            else
            {
                GSOFeatures feats = m_features;// pFeatureLayer.GetAllFeatures();
                GSOFeature  feat  = feats[0];

                countLog = 0;
                GetReallyFeature(feats);
                try
                {
                    dataGridView1.Columns.Clear();
                    dataGridView1.Rows.Clear();
                    for (int j = 0; j < pFeatureDataset.FieldCount; j++)
                    {
                        GSOFieldAttr field = pFeatureDataset.GetField(j);
                        dataGridView1.Columns.Add(field.Name, field.Name);
                    }
                    for (int i = 0; i < feats.Length; i++)
                    {
                        feat = feats[i];
                        if (feat == null)
                        {
                            continue;
                        }
                        int rowIndex = dataGridView1.Rows.Add();
                        dataGridView1.Rows[rowIndex].Tag = feat;
                        for (int j = 0; j < feat.GetFieldCount(); j++)
                        {
                            GSOFieldDefn field      = (GSOFieldDefn)feat.GetFieldDefn(j);
                            object       fieldValue = feat.GetValue(j);
                            if (fieldValue != null)
                            {
                                dataGridView1.Rows[rowIndex].Cells[j].Value = fieldValue.ToString();
                            }
                        }
                    }

                    dataGridView1.ReadOnly             = !pFeatureLayer.Editable;
                    this.编辑ToolStripMenuItem.BackColor = geoLayer.Editable == true ? Color.Orange : Color.Transparent;

                    if (statusStrip1.Items.Count > 0)
                    {
                        if (dataGridView1.Rows.Count >= countLog)
                        {
                            statusStrip1.Items[0].Text = " 共有 " + dataGridView1.Rows.Count + " 条记录";
                        }
                        else
                        {
                            statusStrip1.Items[0].Text = " 共有 " + countLog + " 条记录";
                        }
                    }
                }
                catch (System.Exception exp)
                {
                    Log.PublishTxt(exp);
                    if (statusStrip1.Items.Count > 0)
                    {
                        statusStrip1.Items[0].Text = " 共有 " + 0 + " 条记录";
                    }
                }
            }
        }
        private void btn_Union_Click(object sender, EventArgs e)
        {
            if (comboBoxTargetDataSource.SelectedItem == null)
            {
                MessageBox.Show("请选择目标数据源!", "提示");
                return;
            }
            string newLayerName = textBoxUnionLayerName.Text.Trim();

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

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

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

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

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

                            featureDatasetTargetDs.Save();
                            featureDatasetTargetDs.Close();
                            featureDatasetInDs.Close();
                            MessageBox.Show("复制成功!", "提示");
                            this.Close();
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("数据集名称不能以数字开头!", "提示");
            }
        }
Example #25
0
        //查询
        private void buttonConditionSelect_Click(object sender, EventArgs e)
        {
            if (layer == null)
            {
                MessageBox.Show("请选择一个图层!");
                return;
            }
            if (comboBoxConditionFieldName.Text == "" || comboBoxConditionFieldValue.Text == "" || comboBoxCondition.Text == "")
            {
                MessageBox.Show("请输入完整的查询条件!", "提示");
                return;
            }
            GSOFeatureDataset featureDataset   = layer.Dataset as GSOFeatureDataset;
            EnumFieldType     currentFieldType = EnumFieldType.Text;

            if (featureDataset != null)
            {
                GSOFieldAttr field = featureDataset.GetField(comboBoxConditionFieldName.Text);
                if (field != null)
                {
                    switch (field.Type)
                    {
                    case EnumFieldType.Double:
                    case EnumFieldType.INT32:
                        currentFieldType = EnumFieldType.Double;
                        break;

                    case EnumFieldType.Date:
                        currentFieldType = EnumFieldType.Date;
                        break;
                    }
                }
            }

            try
            {
                switch (comboBoxCondition.Text)
                {
                case "=":
                    for (int i = 0; i < layer.GetAllFeatures().Length; i++)
                    {
                        GSOFeature feature = layer.GetAt(i);
                        if (feature != null && feature.GetValue(comboBoxConditionFieldName.Text).ToString() == comboBoxConditionFieldValue.Text)
                        {
                            features.Add(feature);
                        }
                    }
                    break;

                case ">=":
                    for (int i = 0; i < layer.GetAllFeatures().Length; i++)
                    {
                        GSOFeature feature = layer.GetAt(i);
                        if (currentFieldType == EnumFieldType.Double)
                        {
                            if (feature != null && Double.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) >= Double.Parse(comboBoxConditionFieldValue.Text))
                            {
                                features.Add(feature);
                            }
                        }
                        else if (currentFieldType == EnumFieldType.Date)
                        {
                            if (feature != null && DateTime.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) >= DateTime.Parse(comboBoxConditionFieldValue.Text))
                            {
                                features.Add(feature);
                            }
                        }
                    }
                    break;

                case "<=":
                    for (int i = 0; i < layer.GetAllFeatures().Length; i++)
                    {
                        GSOFeature feature = layer.GetAt(i);
                        if (currentFieldType == EnumFieldType.Double)
                        {
                            if (feature != null && Double.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) <= Double.Parse(comboBoxConditionFieldValue.Text))
                            {
                                features.Add(feature);
                            }
                        }
                        else if (currentFieldType == EnumFieldType.Date)
                        {
                            if (feature != null && DateTime.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) <= DateTime.Parse(comboBoxConditionFieldValue.Text))
                            {
                                features.Add(feature);
                            }
                        }
                    }
                    break;

                case ">":
                    for (int i = 0; i < layer.GetAllFeatures().Length; i++)
                    {
                        GSOFeature feature = layer.GetAt(i);
                        if (currentFieldType == EnumFieldType.Double)
                        {
                            if (feature != null && Double.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) > Double.Parse(comboBoxConditionFieldValue.Text))
                            {
                                features.Add(feature);
                            }
                        }
                        else if (currentFieldType == EnumFieldType.Date)
                        {
                            if (feature != null && DateTime.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) > DateTime.Parse(comboBoxConditionFieldValue.Text))
                            {
                                features.Add(feature);
                            }
                        }
                    }
                    break;

                case "<":
                    for (int i = 0; i < layer.GetAllFeatures().Length; i++)
                    {
                        GSOFeature feature = layer.GetAt(i);
                        if (currentFieldType == EnumFieldType.Double)
                        {
                            if (feature != null && Double.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) < Double.Parse(comboBoxConditionFieldValue.Text))
                            {
                                features.Add(feature);
                            }
                        }
                        else if (currentFieldType == EnumFieldType.Date)
                        {
                            if (feature != null && DateTime.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) < DateTime.Parse(comboBoxConditionFieldValue.Text))
                            {
                                features.Add(feature);
                            }
                        }
                    }
                    break;
                }
                if (features == null)
                {
                    MessageBox.Show("请重新输入查询条件!", "提示");
                    return;
                }
                if (features.Length == 0)
                {
                    MessageBox.Show("没有找到符合查询条件的对象!", "提示");
                    return;
                }
                SetDataTable(features);
            }
            catch (Exception ex)
            {
                Log.PublishTxt(ex);
                MessageBox.Show(ex.Message, "提示");
                return;
            }
        }