//判断用户输入数据的类型
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (geoLayer != null && m_features.Length >= e.RowIndex)
            {
                int        rowIndex    = e.RowIndex;
                int        columnIndex = e.ColumnIndex;
                string     cellValue   = dataGridView1.Rows[rowIndex].Cells[columnIndex].Value.ToString().Trim();
                GSOFeature featureEdit = dataGridView1.Rows[rowIndex].Tag as GSOFeature;// geoLayer.GetAt(rowIndex);
                if (featureEdit == null)
                {
                    MessageBox.Show("修改的对象不存在!", "提示");
                    return;
                }
                string       fieldName = dataGridView1.Columns[columnIndex].Name.Trim();
                GSOFieldDefn field     = (GSOFieldDefn)featureEdit.GetFieldDefn(fieldName);
                switch (field.Type)
                {
                case EnumFieldType.INT32:
                    int intValue = 0;
                    if (!Int32.TryParse(cellValue, out intValue))
                    {
                        MessageBox.Show("输入的数据格式不正确,请重新输入!", "提示");
                        dataGridView1.Rows[rowIndex].Cells[columnIndex].Value = cellValueBeginCellEdit;
                        return;
                    }
                    featureEdit.SetFieldValue(fieldName, intValue);
                    break;

                case EnumFieldType.Double:
                    double doubleValue = 0;
                    if (!double.TryParse(cellValue, out doubleValue))
                    {
                        MessageBox.Show("输入的数据格式不正确,请重新输入!", "提示");
                        dataGridView1.Rows[rowIndex].Cells[columnIndex].Value = cellValueBeginCellEdit;
                        return;
                    }
                    featureEdit.SetFieldValue(fieldName, doubleValue);
                    break;

                case EnumFieldType.Date:
                    DateTime dateTimeValue = DateTime.Now.Date;
                    if (!DateTime.TryParse(cellValue, out dateTimeValue))
                    {
                        MessageBox.Show("输入的数据格式不正确,请重新输入!", "提示");
                        dataGridView1.Rows[rowIndex].Cells[columnIndex].Value = cellValueBeginCellEdit;
                        return;
                    }
                    featureEdit.SetFieldValue(fieldName, dateTimeValue);
                    break;

                case EnumFieldType.Text:
                    featureEdit.SetFieldValue(fieldName, cellValue);
                    break;
                }
            }
        }
예제 #2
0
        private bool updateFeatures()
        {
            if (layer == null)
            {
                MessageBox.Show("请选择一个图层!");
                return(false);
            }
            if (comboBoxUpdateFieldName.Text == "")
            {
                MessageBox.Show("请选择一个字段!");
                return(false);
            }
            string fieldValue = textBoxFieldValue.Text;

            if (dataGridView1.Rows.Count <= 0)
            {
                MessageBox.Show("查询结果为空!");
                return(false);
            }
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                GSOFeature feat = dataGridView1.Rows[i].Tag as GSOFeature;
                if (feat != null)
                {
                    feat.SetFieldValue(comboBoxUpdateFieldName.Text, fieldValue);
                }
            }
            return(true);
        }
예제 #3
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (features != null)
     {
         if (features.Length > 0)
         {
             for (int i = 0; i < features.Length; i++)
             {
                 GSOFeature feature = features[i];
                 feature.SetFieldValue("编号", feature.Name);
             }
             this.Close();
         }
     }
 }
예제 #4
0
        private void AddPolygon()
        {
            GSOGeoPolygon3D geoPolygon = new GSOGeoPolygon3D(); //创建多边形对象

            //创建节点对象
            GSOPoint3ds polygonPnts = new GSOPoint3ds();

            polygonPnts.Add(new GSOPoint3d(116.7, 39.8, 0));
            polygonPnts.Add(new GSOPoint3d(116.8, 39.9, 0));
            polygonPnts.Add(new GSOPoint3d(116.8, 39.7, 0));
            polygonPnts.Add(new GSOPoint3d(116.7, 39.7, 0));

            geoPolygon.AddPart(polygonPnts);                                      //把节点添加到多边形对象上

            GSOSimplePolygonStyle3D stylePolygon = new GSOSimplePolygonStyle3D(); //创建风格

            stylePolygon.OutLineVisible = true;                                   //显示多边形的边缘线
            //设置多边形的填充颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255
            stylePolygon.FillColor = Color.FromArgb(100, 255, 255, 0);
            geoPolygon.Style       = stylePolygon; //把风格添加到多边形上

            //创建几何对象并设置属性
            GSOFeature f = new GSOFeature();

            f.Geometry = geoPolygon;
            f.Name     = "多边形 01";
            f.SetFieldValue("description", "a demo polygon");

            #region 属性设置

            f.Description = "<html>\r\n<head>\r\n<style>\r\n#tab-list {\r\nborder-collapse:collapse;\r\nfont-size:15px;\r\nmargin:20px;\r\ntext-align:left;\r\nwidth:280px;\r\n}\r\n\r\n#tab-list th {\r\nborder-bottom:2px solid #6678B1;\r\ncolor:#003399;\r\nfont-size:14px;\r\nfont-weight:normal;\r\npadding:10px 8px;\r\n}\r\n#tab-list td {\r\nborder-bottom:1px solid #CCCCCC;\r\ncolor:#666699;\r\npadding:6px 8px;\r\n}\r\n</style>\r\n</head>\r\n<body style=\"border:none\">\r\n<center>\r\n<table id=\"tab-list\">\r\n<thead><tr><th>属性名称</th><th>属性值</th></tr></thead>\r\n<tbody>$tablecontent</tbody></table>\r\n</center>\r\n</body>\r\n</html>\r\n";

            GSOGeoPolyline3D line = new GSOGeoPolyline3D();
            line.AddPart((f.Geometry as GSOGeoPolygon3D)[0]);
            double length = line.GetSpaceLength(true, 6378137) / 1000;

            Dictionary <string, string> property = new Dictionary <string, string>();
            property.Add("面积", ((f.Geometry as GSOGeoPolygon3D).Area / 1000000).ToString("f4") + "平方千米");
            property.Add("周长", length.ToString("f2") + "千米");

            f.Description = f.Description.Replace("$tablecontent", maketable(property));

            #endregion

            globeControl1.Globe.MemoryLayer.AddFeature(f);  //把几何要素添加到内存图层中
        }
예제 #5
0
        /// <summary>
        /// 创建面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddPolygon_Click(object sender, EventArgs e)
        {
            GSOGeoPolygon3D geoPolygon = new GSOGeoPolygon3D(); //创建多边形对象

            //创建节点对象
            GSOPoint3ds polygonPnts = new GSOPoint3ds();

            polygonPnts.Add(new GSOPoint3d(116.7, 39.8, 0));
            polygonPnts.Add(new GSOPoint3d(116.8, 39.9, 0));
            polygonPnts.Add(new GSOPoint3d(116.8, 39.7, 0));
            polygonPnts.Add(new GSOPoint3d(116.7, 39.7, 0));

            geoPolygon.AddPart(polygonPnts);                                      //把节点添加到多边形对象上

            GSOSimplePolygonStyle3D stylePolygon = new GSOSimplePolygonStyle3D(); //创建风格

            stylePolygon.OutLineVisible = true;                                   //显示多边形的边缘线
            //设置多边形的填充颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255
            stylePolygon.FillColor = Color.FromArgb(100, 255, 255, 0);
            geoPolygon.Style       = stylePolygon; //把风格添加到多边形上

            //创建几何对象并设置属性
            GSOFeature f = new GSOFeature();

            f.Geometry = geoPolygon;
            f.Name     = "多边形 01";
            f.SetFieldValue("description", "a demo polygon");

            //绑定数据
            btnRemovePolygon.Tag = f;

            globeControl1.Globe.MemoryLayer.AddFeature(f);  //把几何要素添加到内存图层中

            //下面不属于工程内容,只是飞到点的位置
            GSOCameraState cs = new GSOCameraState();

            cs.Longitude = 116.75;
            cs.Latitude  = 39.8;
            cs.Altitude  = 50000;
            globeControl1.Globe.FlyToCameraState(cs);
        }
예제 #6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            #region 创建面要素和飞到面
            GSOGeoPolygon3D geoPolygon = new GSOGeoPolygon3D(); //创建多边形对象

            //创建节点对象
            GSOPoint3ds polygonPnts = new GSOPoint3ds();
            polygonPnts.Add(new GSOPoint3d(116.7, 39.8, 0));
            polygonPnts.Add(new GSOPoint3d(116.8, 39.9, 0));
            polygonPnts.Add(new GSOPoint3d(116.8, 39.7, 0));
            polygonPnts.Add(new GSOPoint3d(116.7, 39.7, 0));

            geoPolygon.AddPart(polygonPnts);                                      //把节点添加到多边形对象上

            GSOSimplePolygonStyle3D stylePolygon = new GSOSimplePolygonStyle3D(); //创建风格
            stylePolygon.OutLineVisible = true;                                   //显示多边形的边缘线
            //设置多边形的填充颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255
            stylePolygon.FillColor = Color.FromArgb(100, 255, 255, 0);
            geoPolygon.Style       = stylePolygon; //把风格添加到多边形上

            //下面不属于工程内容,只是飞到点的位置
            GSOCameraState cs = new GSOCameraState();
            cs.Longitude = 116.75;
            cs.Latitude  = 39.8;
            cs.Altitude  = 50000;
            globeControl1.Globe.FlyToCameraState(cs);

            #endregion

            //创建几何对象并设置属性
            GSOFeature f = new GSOFeature();
            f.Geometry = geoPolygon;
            f.Name     = "多边形 01";
            f.CustomID = 1;
            f.SetFieldValue("description", "a demo polygon");
            f.Description = "这是一个多边形";

            //将面添加到球中
            feature = globeControl1.Globe.MemoryLayer.AddFeature(f);  //添加的时候获取要素
        }
예제 #7
0
        private GSOFeature makeLine()
        {
            GSOGeoPolyline3D line = new GSOGeoPolyline3D(); //创建线对象
            GSOPoint3ds      pnts = new GSOPoint3ds();      //创建节点对象

            pnts.Add(new GSOPoint3d(116.6, 39.9, 1000));    //把各节点添加到节点对象上
            pnts.Add(new GSOPoint3d(116.61, 39.91, 3000));
            pnts.Add(new GSOPoint3d(116.62, 39.92, 2000));
            pnts.Add(new GSOPoint3d(116.63, 39.90, 2500));
            pnts.Add(new GSOPoint3d(116.64, 39.94, 4000));
            line.AddPart(pnts);                                      //把节点添加到线上

            GSOSimpleLineStyle3D style = new GSOSimpleLineStyle3D(); //创建线的风格

            //设置透明度及颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255
            style.LineColor     = Color.FromArgb(150, 0, 255, 0);
            style.LineWidth     = 3;     //设置线的宽度为3
            style.VertexVisible = true;  //显示线的节点
            line.Style          = style; //把风格添加到线上

            //创建几何对象并设置属性
            GSOFeature f = new GSOFeature();

            f.Geometry = line;                        //把线对象添加到几何对象上
            f.Name     = "线 01";                      //设置几何对象的名称
            f.SetFieldValue("description", "这是线的属性"); //设置几何对象的字段值
            //把几何要素添加到内存图层中
            globeControl1.Globe.MemoryLayer.AddFeature(f);

            //下面不属于工程内容,只是飞到点的位置
            GSOCameraState cs = new GSOCameraState();

            cs.Longitude = 116.62;
            cs.Latitude  = 39.92;
            cs.Altitude  = 9000;
            globeControl1.Globe.FlyToCameraState(cs);

            return(f);
        }
예제 #8
0
        private void AddLine()
        {
            GSOGeoPolyline3D line = new GSOGeoPolyline3D(); //创建线对象
            GSOPoint3ds      pnts = new GSOPoint3ds();      //创建节点对象

            pnts.Add(new GSOPoint3d(116.6, 39.9, 1000));    //把各节点添加到节点对象上
            pnts.Add(new GSOPoint3d(116.61, 39.91, 3000));
            pnts.Add(new GSOPoint3d(116.62, 39.92, 2000));
            pnts.Add(new GSOPoint3d(116.63, 39.90, 2500));
            pnts.Add(new GSOPoint3d(116.64, 39.94, 4000));
            line.AddPart(pnts);                                      //把节点添加到线上

            GSOSimpleLineStyle3D style = new GSOSimpleLineStyle3D(); //创建线的风格

            //设置透明度及颜色,FromArgb()中的四个参数分别为alpha、red、green、blue,取值范围为0到255
            style.LineColor     = Color.FromArgb(150, 0, 255, 0);
            style.LineWidth     = 3;     //设置线的宽度为3
            style.VertexVisible = true;  //显示线的节点
            line.Style          = style; //把风格添加到线上

            //创建几何对象并设置属性
            GSOFeature lineFeature = new GSOFeature();

            lineFeature.Geometry = line;                        //把线对象添加到几何对象上
            lineFeature.Name     = "线 01";                      //设置几何对象的名称
            lineFeature.SetFieldValue("description", "这是线的属性"); //设置几何对象的字段值

            lineFeature.Description = "<html>\r\n<head>\r\n<style>\r\n#tab-list {\r\nborder-collapse:collapse;\r\nfont-size:15px;\r\nmargin:20px;\r\ntext-align:left;\r\nwidth:280px;\r\n}\r\n\r\n#tab-list th {\r\nborder-bottom:2px solid #6678B1;\r\ncolor:#003399;\r\nfont-size:14px;\r\nfont-weight:normal;\r\npadding:10px 8px;\r\n}\r\n#tab-list td {\r\nborder-bottom:1px solid #CCCCCC;\r\ncolor:#666699;\r\npadding:6px 8px;\r\n}\r\n</style>\r\n</head>\r\n<body style=\"border:none\">\r\n<center>\r\n<table id=\"tab-list\">\r\n<thead><tr><th>属性名称</th><th>属性值</th></tr></thead>\r\n<tbody>$tablecontent</tbody></table>\r\n</center>\r\n</body>\r\n</html>\r\n";
            double lineLength = line.GetSpaceLength(true, 6378137);
            Dictionary <string, string> property = new Dictionary <string, string>();

            property.Add("长度", (lineLength / 1000).ToString("0.00") + "KM");

            lineFeature.Description = lineFeature.Description.Replace("$tablecontent", maketable(property));

            //把几何要素添加到内存图层中
            globeControl1.Globe.MemoryLayer.AddFeature(lineFeature);
        }
예제 #9
0
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            //行索引
            int rowIndex = e.RowIndex;
            //列索引
            int columnIndex = e.ColumnIndex;
            //获得修改的要素
            GSOFeature featureEdit = (_layer.Dataset as GSOFeatureDataset).GetFeatureAt(rowIndex);
            //获得修改的字段名称
            string fieldName = dataGridView1.Columns[columnIndex].Name.Trim();
            //获得修改过的字段定义
            GSOFieldDefn field = featureEdit.GetFieldDefn(fieldName);
            //获得修改过的值
            string cellValue = dataGridView1.Rows[rowIndex].Cells[columnIndex].Value.ToString().Trim();

            if (featureEdit == null || field == null)
            {
                MessageBox.Show("修改的对象不存在!", "提示");
                return;
            }
            //进行输入值类型的判断
            switch (field.Type)
            {
            case EnumFieldType.INT32:
                int intValue = 0;
                if (!Int32.TryParse(cellValue, out intValue))
                {
                    MessageBox.Show("输入的数据格式不正确,请重新输入!", "提示");
                    dataGridView1.Rows[rowIndex].Cells[columnIndex].Value = _cellValueBeginCellEdit;
                    return;
                }
                //值设置
                featureEdit.SetFieldValue(fieldName, intValue);
                break;

            case EnumFieldType.Double:
                double doubleValue = 0;
                if (!double.TryParse(cellValue, out doubleValue))
                {
                    MessageBox.Show("输入的数据格式不正确,请重新输入!", "提示");
                    dataGridView1.Rows[rowIndex].Cells[columnIndex].Value = _cellValueBeginCellEdit;
                    return;
                }
                //值设置
                featureEdit.SetFieldValue(fieldName, doubleValue);
                break;

            case EnumFieldType.Date:
                DateTime dateTimeValue = DateTime.Now.Date;
                if (!DateTime.TryParse(cellValue, out dateTimeValue))
                {
                    MessageBox.Show("输入的数据格式不正确,请重新输入!", "提示");
                    dataGridView1.Rows[rowIndex].Cells[columnIndex].Value = _cellValueBeginCellEdit;
                    return;
                }
                //值设置
                featureEdit.SetFieldValue(fieldName, dateTimeValue);
                break;

            case EnumFieldType.Text:
                //值设置
                featureEdit.SetFieldValue(fieldName, cellValue);
                break;

            default:
                throw new Exception("字段类型不符合条件。");
            }
            _layer.Save();
        }
        private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dataGridView1.ReadOnly)
            {
                MessageBox.Show("表格当前为不可编辑状态!", "提示");
                return;
            }
            if (Clipboard.GetData(DataFormats.Text) == null)
            {
                return;
            }
            string strCellValue = Clipboard.GetData(DataFormats.Text).ToString();

            string[] separator = { "\r\n" };
            if (strCellValue.EndsWith(separator[0]))
            {
                strCellValue = strCellValue.Remove(strCellValue.LastIndexOf(separator[0]));
            }
            string[] arrayCells = strCellValue.Split(separator, StringSplitOptions.None);
            if (arrayCells.Length <= 0 || dataGridView1.SelectedCells.Count <= 0)
            {
                return;
            }
            int count = arrayCells.Length > dataGridView1.SelectedCells.Count ? dataGridView1.SelectedCells.Count : arrayCells.Length;

            List <DataGridViewCell> listSelectCells = sortAllSelectCells(dataGridView1);

            for (int i = 0; i < count; i++)
            {
                string     cellValue   = arrayCells[i].Trim();
                GSOFeature featureEdit = dataGridView1.Rows[listSelectCells[i].RowIndex].Tag as GSOFeature;// geoLayer.GetAt(listSelectCells[i].RowIndex);
                if (featureEdit == null)
                {
                    MessageBox.Show("修改的对象不存在!", "提示");
                    return;
                }
                string       fieldName = dataGridView1.Columns[listSelectCells[i].ColumnIndex].Name.Trim();
                GSOFieldDefn field     = (GSOFieldDefn)featureEdit.GetFieldDefn(fieldName);
                if (field == null)
                {
                    continue;
                }
                switch (field.Type)
                {
                case EnumFieldType.INT32:
                    int intValue = 0;
                    if (!Int32.TryParse(cellValue, out intValue))
                    {
                        MessageBox.Show("数据格式不正确!", "提示");
                        return;
                    }
                    featureEdit.SetFieldValue(fieldName, intValue);
                    break;

                case EnumFieldType.Double:
                    double doubleValue = 0;
                    if (!double.TryParse(cellValue, out doubleValue))
                    {
                        MessageBox.Show("数据格式不正确!", "提示");
                        return;
                    }
                    featureEdit.SetFieldValue(fieldName, doubleValue);
                    break;

                case EnumFieldType.Date:
                    DateTime dateTimeValue = DateTime.Now.Date;
                    if (!DateTime.TryParse(cellValue, out dateTimeValue))
                    {
                        MessageBox.Show("数据格式不正确!", "提示");
                        return;
                    }
                    featureEdit.SetFieldValue(fieldName, dateTimeValue);
                    break;

                case EnumFieldType.Text:
                    featureEdit.SetFieldValue(fieldName, cellValue);
                    break;
                }

                dataGridView1.Rows[listSelectCells[i].RowIndex].Cells[listSelectCells[i].ColumnIndex].Value = cellValue;
            }
        }
예제 #11
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("修改成功!", "提示");
        }