ArcGIS Engine中如何获取Map中已经选择的要素呢

1、使用IEnumFeturea对象获取map中的FeatureSelection,该方法可以获取所有图层的选择要素。IMap中的FeatureSelection可不是IFeatureSelection,而是ISelection

 

2、使用ISelectionSetIEnumIDsFeatureClass.GetFeature()方法获取某个图层中的选择要素

 

在map中获取要素时,这样是可以的,不过不能得到要素的完整属性信息,貌似只能拿到ID值。

ISelection pSelection = pMap.FeatureSelection;

           IEnumFeature enumFeature = pSelection asIEnumFeature;

           IFeature feature = enumFeature.Next();

            while (feature != null)

            {

               array.Add(feature);

               feature=enumFeature.Next();

            }

那如果要得到完整的属性信息怎么办呢?IEnumFeatureSetup起到大作用了。如下所示:

ISelection selection = pMap.FeatureSelection;

IEnumFeatureSetup enumFeatureSetup = selection as IEnumFeatureSetup;    //这里很必要

enumFeatureSetup.AllFields = true;                                      //这里很必要

IEnumFeature enumFeature = enumFeatureSetup as IEnumFeature;

enumFeature.Reset(); 

IFeature feature = enumFeature.Next();

while (feature != null)

      {

        stringvalue = feature.get_Value(index).ToString();//就可以得到任意字段的值了 

        feature = enumFeature.Next();

       }

 

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
ArcGIS Engine编辑面要素可以使用以下代码实现: 1. 首先,创建一个编辑工具栏并添加面编辑工具: ```csharp // 创建编辑工具栏 ICommandPool cmdPool = new CommandPoolClass(); UID uid = new UIDClass(); uid.Value = "esriControls.ControlsEditingToolbar"; ICommandItem cmdItem = cmdPool.Find(uid, false); ICommandBar cmdBar = cmdItem.CommandBar; cmdBar.Dock(esriDockFlags.esriDockRight); // 添加面编辑工具 UID editUID = new UIDClass(); editUID.Value = "esriControls.ControlsEditingSketchToolControl"; ICommandItem editCmd = cmdPool.Find(editUID, false); cmdBar.Add(editCmd); ``` 2. 在地图控件上启用编辑模式: ```csharp axMapControl1.CurrentTool = null; axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; axMapControl1.Enabled = true; axMapControl1.ShowEditor(true); axMapControl1.CurrentTool = editCmd.Command; ``` 3. 实现面要素的创建和编辑: ```csharp // 创建新面要素 IWorkspaceEdit workspaceEdit = ((IDataset)featureLayer.FeatureClass).Workspace as IWorkspaceEdit; workspaceEdit.StartEditing(false); workspaceEdit.StartEditOperation(); IFeature newFeature = featureLayer.FeatureClass.CreateFeature(); newFeature.Shape = new PolygonClass(); IPointCollection pointCollection = newFeature.Shape as IPointCollection; pointCollection.AddPoint(new PointClass() { X = x1, Y = y1 }); pointCollection.AddPoint(new PointClass() { X = x2, Y = y2 }); // ... 添加更多点 newFeature.Store(); workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); // 编辑现有面要素 IEditor editor = axMapControl1.Map as IEditor; editor.StartEditing(featureLayer.FeatureClass.Workspace); editor.StartOperation(); editor.ModifyFeature(newFeature, pointCollection as IGeometry); editor.StopOperation("Edit Polygon"); ``` 注意,以上代码仅为示例,需要根据具体情况进行修改和完善。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值