选择多个要素时如何设置视图范围

时间:2013-12-02 17:12:23

标签: c# arcgis feature-extraction arcobjects arcmap

我想弄清楚设置活动视图范围的最佳方法是什么,以便能够在Arc Map上查看所有选定的要素。

1.地图只有一层。 2.功能使用属性进行过滤。

下面是我尝试的代码,卡在我可以遍历功能选择集中的功能但不能将活动视图范围设置为缩放以显示所有选定功能的部分。

P.S:这类似于右键单击属性表并选择多行并执行缩放选择。

private void ZoomToMultipleDGVSelection(List<int> selectedRightIDs)
{

    IMxDocument pMxDoc = ArcMap.Document;
    IMap pMap = (IMap)pMxDoc.ActiveView;

    ESRI.ArcGIS.Carto.ILayer layer = GetLayersClass.GetFieldBoundaryLayer;
    if (layer is ESRI.ArcGIS.Carto.IGroupLayer)
    {

        ESRI.ArcGIS.Carto.IGroupLayer groupLayer = layer as    ESRI.ArcGIS.Carto.IGroupLayer;
        ICompositeLayer pCompositeLayer = layer as ICompositeLayer;
        int layers = pCompositeLayer.Count;
        ILayer pLayer = pCompositeLayer.Layer[0];
        IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;

        IFeatureSelection pFeatureSelection = (IFeatureSelection)pLayer;
        ISelectionSet pSelectionSet = pFeatureSelection.SelectionSet;

        IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
        IQueryFilter pFilter = new QueryFilterClass();

        foreach(int ID  in selectedRightIDs)
        {
        pFilter.WhereClause = "RightID = " + ID.ToString();

        IFeatureCursor pFeatureCursor = pFeatureClass.Search(pFilter, false);
        IFeature pFeature = pFeatureCursor.NextFeature();

        pFeatureSelection.Add(pFeature);

        }


        //if (pFeature == null)
        //{
        //    System.Windows.Forms.MessageBox.Show("This section doesn't exist");
        //    return;
        //}


        IGeometry pgeom = (IGeometry)pFeature.Shape;
        pMap.SelectByShape(pgeom, null, false);
        IEnvelope pEnv = pgeom.Envelope;
        pMxDoc.ActiveView.Extent = pEnv;
        pMxDoc.ActiveView.Refresh();
    }
}

提前谢谢!

2 个答案:

答案 0 :(得分:1)

将几何对象添加到geometrybag,然后调用

pMxDoc.ActiveView.Extent = pGeometryBag.envelope

编辑:刚注意到之前的答案已经暗示过,傻傻的我!

答案 1 :(得分:0)

更简单的方法可能是

IDocument d = ArcMap.Document as IDocument;
IUID ud = new UIDClass();
ud.Value = "esriArcMapUI.ZoomToSelectedCommand";
ICommandItem ci = d.CommandBars.Find(ud);
ci.Execute();

否则,您可以将所有Shape添加到GeometryBag并获取要传递给ActiveView的范围(包络)。