private void buttonAddAttribute_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要添加该属性字段?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    GSOFeatureLayer pFeatureLayer = geoLayer as GSOFeatureLayer;
                    if (pFeatureLayer == null)
                    {
                        return;
                    }
                    GSOFeatures       feats     = pFeatureLayer.GetAllFeatures();
                    GSOFeatureDataset dateset   = pFeatureLayer.Dataset as GSOFeatureDataset;
                    GSOFieldAttr      fieldattr = new GSOFieldAttr();

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

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

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

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

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

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

                    if (m_globeControl != null)
                    {
                        m_globeControl.Refresh();
                    }
                }
                catch (System.Exception exp)
                {
                    Log.PublishTxt(exp);
                }
            }
        }
Пример #2
0
        private void buttonGetFieldValue_Click(object sender, EventArgs e)
        {
            string fieldName = comboBoxFieldNames.Text.Trim();

            if (fieldName == "")
            {
                MessageBox.Show("请选择字段名称!", "提示");
                return;
            }
            GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(cmbLayers.Text.Trim());

            if (layer == null)
            {
                MessageBox.Show("请选择图层", "提示");
                return;
            }
            if (layer.Type != EnumLayerType.FeatureLayer)
            {
                MessageBox.Show("当前选中的图层不是模型图层!", "提示");
                return;
            }
            GSOFeatureLayer featureLayer = layer as GSOFeatureLayer;
            List <string>   listValues   = new List <string>();

            for (int i = 0; i < featureLayer.GetAllFeatures().Length; i++)
            {
                GSOFeature feature = featureLayer.GetAt(i);
                if (feature != null)
                {
                    object value = feature.GetValue(fieldName);
                    if (value == null || value.ToString() == "")
                    {
                        continue;
                    }
                    if (listValues.Contains(value.ToString()) == false)
                    {
                        listValues.Add(value.ToString());
                    }
                }
            }
            listViewFieldValues.Items.Clear();
            if (listValues.Count <= 0)
            {
                MessageBox.Show("没有找到不为空的字段值!", "提示");
                return;
            }
            for (int i = 0; i < listValues.Count; i++)
            {
                listViewFieldValues.Items.Add(listValues[i]);
            }
        }
Пример #3
0
        private void btn_OK_Click(object sender, System.EventArgs e)
        {
            if (string.IsNullOrEmpty(this.textBox1.Text))
            {
                errorProvider1.SetError(this.textBox1, "请输入升降高度");
                return;
            }
            if (!double.TryParse(this.textBox1.Text, out double height))
            {
                errorProvider1.SetError(this.textBox1, "输入高度不合法,请重新输入数字。");
                return;
            }
            GSOFeatureLayer flayer = _layer as GSOFeatureLayer;
            //获得图层中的所有要素
            GSOFeatures features = flayer.GetAllFeatures();

            for (int i = 0; i < features.Length; i++)
            {
                //遍历所有要素
                GSOFeature feature = features[i];
                if (feature is GSOFeatureFolder)
                {
                    MoveEachFeature(feature as GSOFeatureFolder, height);
                }
                else
                {
                    GSOGeometry geometry = feature.Geometry;
                    if (geometry != null)
                    {
                        //为了显示升降效果,
                        //需要将ClampToGround模式修改为RelativeToGround模式
                        if (geometry.AltitudeMode == EnumAltitudeMode.ClampToGround)
                        {
                            geometry.AltitudeMode = EnumAltitudeMode.RelativeToGround;
                        }
                        //将z轴移动height米
                        geometry.MoveZ(height);
                    }
                }
            }
            _glbControl.Refresh();
        }
Пример #4
0
        private void btnMove_Click(object sender, EventArgs e)
        {
            GSOLayer layer = ctl.Globe.Layers[cmbLayers.SelectedIndex];

            if (layer != null)
            {
                if (layer.Type != EnumLayerType.FeatureLayer)
                {
                    MessageBox.Show("当前选中的图层不是模型图层!", "提示");
                    return;
                }
                if (txtOldLat.Text == "")
                {
                    MessageBox.Show("请选择起点");
                }
                else if (txtNewLat.Text == "")
                {
                    MessageBox.Show("请选择目标点");
                }
                else
                {
                    double daltX = Convert.ToDouble(txtNewLon.Text) - Convert.ToDouble(txtOldLon.Text);
                    double daltY = Convert.ToDouble(txtNewLat.Text) - Convert.ToDouble(txtOldLat.Text);


                    GSOFeatureLayer flayer = layer as GSOFeatureLayer;

                    GSOFeatures features = flayer.GetAllFeatures();
                    for (int i = 0; i < features.Length; i++)
                    {
                        GSOFeature feature = features[i];
                        if (feature is GSOFeatureFolder)
                        {
                            MoveEachFeature(feature as GSOFeatureFolder, daltX, daltY);
                        }
                        else
                        {
                            GSOGeometry g = feature.Geometry;
                            if (g != null)
                            {
                                g.MoveXY(daltX, daltY);
                            }



                            //    switch (feature.Geometry.Type)
                            //    {
                            //        case EnumGeometryType.GeoPolyline3D:
                            //            GSOGeoPolyline3D line = feature.Geometry as GSOGeoPolyline3D;
                            //            for (int m = 0; m < line.PartCount; m++)
                            //            {
                            //                for (int j = 0; j < line[m].Count; j++)
                            //                {
                            //                    GSOPoint3d line0 = line[m][j];
                            //                    line0.X += daltX;
                            //                    line0.Y += daltY;
                            //                    line[m][j] = line0;
                            //                }
                            //            }
                            //            break;
                            //        case EnumGeometryType.GeoPolygon3D:
                            //            GSOGeoPolygon3D polygon = feature.Geometry as GSOGeoPolygon3D;
                            //            if (polygon != null)
                            //            {
                            //                polygon.MoveXY(daltX, daltY);
                            //            }
                            //            break;
                            //        case EnumGeometryType.GeoModel:
                            //            GSOGeoModel model = feature.Geometry as GSOGeoModel;
                            //            if (model != null)
                            //            {
                            //                GSOPoint3d pt = model.Position;
                            //                pt.X += daltX;
                            //                pt.Y += daltY;
                            //                model.Position = pt;
                            //            }
                            //            break;
                            //        case EnumGeometryType.GeoFrameAnimation:
                            //            GSOGeoFrameAnimation frameAnimation = feature.Geometry as GSOGeoFrameAnimation;
                            //            if (frameAnimation != null)
                            //            {
                            //                GSOPoint3d pt = frameAnimation.Position;
                            //                pt.X += daltX;
                            //                pt.Y += daltY;
                            //                frameAnimation.Position = pt;
                            //            }
                            //            break;
                            //        default:
                            //            GSOGeometry g = feature.Geometry;
                            //            if (g != null)
                            //            {
                            //                g.MoveXY(daltX, daltY);
                            //            }
                            //            break;
                            //    }
                        }
                    }
                    if (startFeat != null)
                    {
                        startFeat.Delete();
                    }
                    if (endFeat != null)
                    {
                        endFeat.Delete();
                    }
                    ctl.Refresh();
                    //this.Close();
                }
            }
            else
            {
                MessageBox.Show("请选择图层");
            }
        }
Пример #5
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(cmbLayers.Text.Trim());

            if (layer == null)
            {
                MessageBox.Show("请选择图层", "提示");
                return;
            }
            if (layer.Type != EnumLayerType.FeatureLayer)
            {
                MessageBox.Show("当前选中的图层不是模型图层!", "提示");
                return;
            }
            GSOFeatureLayer flayer   = layer as GSOFeatureLayer;
            GSOFeatures     features = new GSOFeatures();

            if (radioButtonElevateAllFeature.Checked == true)
            {
                features = flayer.GetAllFeatures();
            }
            else if (radioButtonElevatePartFeature.Checked == true)
            {
                string fieldName = comboBoxFieldNames.Text.Trim();
                if (fieldName == "")
                {
                    MessageBox.Show("请选择字段名称!", "提示");
                    return;
                }
                if (listViewFieldValues.SelectedItems.Count <= 0)
                {
                    MessageBox.Show("请选中一个字段值!", "提示");
                    return;
                }
                string fieldValue = listViewFieldValues.SelectedItems[0].Text.Trim();
                features = flayer.GetFeatureByFieldValue(fieldName, fieldValue, true);
            }

            string elevateHeight = txtHeight.Text.Trim();
            double height        = 0;

            if (txtHeight.Text == "" || double.TryParse(elevateHeight, out height) == false)
            {
                MessageBox.Show("请输入正确的调整高度", "提示");
                return;
            }

            for (int i = 0; i < features.Length; i++)
            {
                GSOFeature feature = features[i];
                if (feature is GSOFeatureFolder)
                {
                    MoveEachFeature(feature as GSOFeatureFolder, height);
                }
                else if (feature.Geometry is GSOGeoModel)
                {
                    GSOGeoModel model = feature.Geometry as GSOGeoModel;
                    if (model != null)
                    {
                        GSOPoint3d pt = model.Position;
                        pt.Z          += height;
                        model.Position = pt;
                    }
                }
                else if (feature.Geometry is GSOGeoPolyline3D)
                {
                    GSOGeoPolyline3D templine = feature.Geometry as GSOGeoPolyline3D;
                    if (templine != null)
                    {
                        templine.MoveZ(height);
                        feature.Geometry = templine;
                    }
                }
            }
            ctl.Refresh();
            MessageBox.Show("抬升成功", "提示");
        }
Пример #6
0
        private void radioButtonElevatePartFeature_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButtonElevatePartFeature.Checked == true)
            {
                string layerCaption = cmbLayers.Text.Trim();
                if (layerCaption == "")
                {
                    radioButtonElevateAllFeature.Checked = true;
                    MessageBox.Show("请先选择图层!", "提示");
                    return;
                }
                GSOLayer layer = ctl.Globe.Layers.GetLayerByCaption(layerCaption);
                if (layer == null)
                {
                    radioButtonElevateAllFeature.Checked = true;
                    MessageBox.Show("请先选择图层!", "提示");
                    return;
                }

                GSOFeatureLayer featureLayer = layer as GSOFeatureLayer;
                if (featureLayer == null)
                {
                    radioButtonElevateAllFeature.Checked = true;
                    MessageBox.Show("图层不是矢量图层!", "提示");
                    return;
                }
                if (featureLayer.GetAllFeatures().Length <= 0)
                {
                    radioButtonElevateAllFeature.Checked = true;
                    MessageBox.Show("图层中的要素个数为0个!", "提示");
                    return;
                }
                for (int i = 0; i < featureLayer.GetAllFeatures().Length; i++)
                {
                    GSOFeature feature = featureLayer.GetAt(i);
                    if (feature != null)
                    {
                        if (feature.GetFieldCount() <= 0)
                        {
                            radioButtonElevateAllFeature.Checked = true;
                            MessageBox.Show("图层中的字段个数为0个!", "提示");
                            return;
                        }
                        for (int j = 0; j < feature.GetFieldCount(); j++)
                        {
                            GSOFieldDefn field = (GSOFieldDefn)feature.GetFieldDefn(j);
                            if (field != null)
                            {
                                comboBoxFieldNames.Items.Add(field.Name);
                            }
                        }
                        break;
                    }
                }

                radioButtonElevateAllFeature.Checked = false;
                panel1.Enabled = true;
            }
            else
            {
                panel1.Enabled = false;
                radioButtonElevateAllFeature.Checked = true;
            }
        }
Пример #7
0
        private List <DataTable> CollisionAnalysis()
        {
            List <DataTable> listTable = new List <DataTable>();
            GSOPoint3d       pntIntersect1;
            GSOPoint3d       pntIntersect2;
            int layerCount = listBox1.SelectedItems.Count;

            for (int i = 0; i < layerCount; i++)//遍历所有的图层
            {
                GSOLayer layer1 = globeControl1.Globe.Layers.GetLayerByCaption(listBox1.SelectedItems[i].ToString().Trim());
                if (layer1 != null)
                {
                    DataTable dt = new DataTable();
                    if (layer1.GetAllFeatures().Length > 0)
                    {
                        for (int fieldName = 0; fieldName < layer1.GetAt(0).GetFieldCount(); fieldName++)
                        {
                            GSOFieldDefn field = (GSOFieldDefn)layer1.GetAt(0).GetFieldDefn(fieldName);
                            dt.Columns.Add(field.Name);
                        }
                    }
                    listTable.Add(dt);
                }
            }

            if (listTable.Count > 0 && listTable.Count == layerCount)
            {
                for (int i = 0; i < layerCount; i++)//遍历所有的图层
                {
                    GSOLayer layer = globeControl1.Globe.Layers.GetLayerByCaption(listBox1.SelectedItems[i].ToString().Trim());
                    if (layer.Caption.Contains("管线")) //过滤出管线图层
                    {
                        GSOFeatureLayer   flayer   = layer as GSOFeatureLayer;
                        GSOFeatureDataset fdataset = flayer.Dataset as GSOFeatureDataset;
                        GSOFeatures       feats    = flayer.GetAllFeatures();


                        for (int m = 0; m < feats.Length; m++) //遍历图层中的所有管线
                        {
                            GSOFeature feat = feats[m];

                            GSOGeoPolyline3D line1 = feat.Geometry as GSOGeoPolyline3D;
                            if (line1 == null)
                            {
                                continue;
                            }
                            GSOPipeLineStyle3D pipeStyle1 = line1.Style as GSOPipeLineStyle3D;
                            if (pipeStyle1 == null)
                            {
                                continue;
                            }
                            for (int j = i; j < layerCount; j++)
                            {
                                GSOLayer        layer2  = globeControl1.Globe.Layers.GetLayerByCaption(listBox1.SelectedItems[j].ToString().Trim());
                                GSOFeatureLayer flayer2 = layer2 as GSOFeatureLayer;
                                if (layer2.Caption.Contains("管线"))
                                {
                                    GSOFeatureDataset fdataset2 = flayer2.Dataset as GSOFeatureDataset;
                                    GSOFeatures       feats2    = flayer2.GetAllFeatures();
                                    for (int n = 0; n < feats2.Length; n++)//遍历图层中的所有管线
                                    {
                                        if (i == j)
                                        {
                                            if (m >= n)
                                            {
                                                continue;
                                            }
                                        }
                                        GSOFeature       feat2 = feats2[n];
                                        GSOGeoPolyline3D line2 = feat2.Geometry as GSOGeoPolyline3D;
                                        if (line2 == null)
                                        {
                                            continue;
                                        }
                                        GSOPipeLineStyle3D pipeStyle2 = line2.Style as GSOPipeLineStyle3D;
                                        if (pipeStyle2 == null)
                                        {
                                            continue;
                                        }
                                        double dHonLen;
                                        double dVerLen;
                                        double dNoIntersectStartRatio = 0;
                                        // 计算两条线的距离和交点,若果失败返回-1
                                        // 若在同一直线上,并且有交点,返回0
                                        // 若不在同一平面,返回最近两点的距离,并且计算最近两点
                                        double dDist = globeControl1.Globe.Analysis3D.ComputeTwoGeoPolylineDistance(line1, line2, out pntIntersect1, out pntIntersect2, out dHonLen, out dVerLen, false, false, dNoIntersectStartRatio);
                                        if (dDist > -1)
                                        {
                                            if (dDist != 0)
                                            {
                                                dDist = dDist - pipeStyle1.Radius - pipeStyle2.Radius;
                                                if (dDist < 0) //发生碰撞,把发生碰撞的管线名称添加到DataTable里
                                                {
                                                    DataRow newRow = listTable[i].NewRow();
                                                    for (int fieldName = 0; fieldName < feats[m].GetFieldCount(); fieldName++)
                                                    {
                                                        newRow[fieldName] = feats[m].GetValue(fieldName);
                                                    }
                                                    if (newRow != null)
                                                    {
                                                        listTable[i].Rows.Add(newRow);
                                                    }

                                                    DataRow newRow1 = listTable[j].NewRow();
                                                    for (int fieldName = 0; fieldName < feats2[n].GetFieldCount(); fieldName++)
                                                    {
                                                        newRow1[fieldName] = feats2[n].GetValue(fieldName);
                                                    }
                                                    if (newRow != null)
                                                    {
                                                        listTable[j].Rows.Add(newRow1);
                                                    }
                                                    //newRow["编号1"] = layer.Caption + "-" + feats[m].ID;
                                                    //newRow["编号2"] = layer2.Caption + "-" + feats2[n].ID;
                                                    //dt.Rows.Add(newRow);
                                                }
                                            }
                                        }
                                        line2.ReleaseInnerPointer();
                                        feat2.ReleaseInnerPointer();
                                    }
                                    feats2.ReleaseInnerPointer();
                                }
                            }
                            line1.ReleaseInnerPointer();
                            feat.ReleaseInnerPointer();
                        }
                        feats.ReleaseInnerPointer();
                    }
                }
            }
            return(listTable);
        }
Пример #8
0
        private void btnEnter_Click(object sender, EventArgs e)
        {
            int n = 0;

            layer = globeControl1.Globe.Layers.GetLayerByCaption(cmbPipeShow.Text.Trim());
            GSOFeatureLayer flayer = layer as GSOFeatureLayer;

            if (flayer == null)
            {
                return;
            }
            GSOFeatureDataset fdataset = flayer.Dataset as GSOFeatureDataset;

            if (fdataset == null || fdataset.DataSource == null)
            {
                return;
            }
            connectParams = Utility.getConnectParamsByDatasourceName(globeControl1, fdataset.DataSource.Name);
            if (connectParams == null)
            {
                return;
            }
            GSOFeatures feats = flayer.GetAllFeatures();
            string      type  = layer.Caption.Substring(0, 2);
            string      sql   = "select * " + " from " + layer.Caption + "  where";

            for (int i = 0; i < feats.Length; i++)
            {
                GSOFeature f = feats[i];
                if (f.Geometry.Type == EnumGeometryType.GeoPolyline3D)
                {
                    GSOGeoPolyline3D   line  = f.Geometry as GSOGeoPolyline3D;
                    GSOPipeLineStyle3D style = line.Style as GSOPipeLineStyle3D;
                    if (style != null)
                    {
                        GSOPoint3ds pnts = getAllPointInPipeline(line);
                        for (int j = 0; j < pnts.Count; j++)
                        {
                            GSOPoint3d pt = pnts[j];
                            if (Math.Abs(pt.Z) < style.Radius)
                            {
                                n++;
                                sql += "  编号='" + f.Name + "' or ";
                                break;
                            }
                        }
                    }
                }
            }
            if (n > 0)
            {
                sql = sql.Substring(0, sql.Length - 3);
                DataTable dt = new DataTable();
                dt = OledbHelper.QueryTable(sql, connectParams);

                if (dt == null)
                {
                    MessageBox.Show("没有地上管线!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    if (dt.Columns.Count > 3)
                    {
                        dt.Columns.RemoveAt(0);
                        dt.Columns.RemoveAt(0);
                        dt.Columns.RemoveAt(0);
                    }
                    dataGridView1.ReadOnly   = !layer.Editable;
                    dataGridView1.DataSource = dt;
                    if (statusStrip1.Items.Count > 0)
                    {
                        statusStrip1.Items[0].Text = " 共有 " + dt.Rows.Count + " 条记录";
                    }
                    globeControl1.Globe.Refresh();
                }
            }
            else
            {
                MessageBox.Show("没有地上管线!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                dataGridView1.DataSource = null;
                if (statusStrip1.Items.Count > 0)
                {
                    statusStrip1.Items[0].Text = " 共有 " + 0 + " 条记录";
                }
            }
        }