1

嗨,我有以下代码,用于根据属性放大 arcGIS 对象,现在我需要的是能够使用选择功能突出显示该区域(您右键单击地图上的区域并选择的功能特征)。

目前我有一个可以进行缩放的事件。我也想将此选择添加到相同的属性中。

先感谢您!!!

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;

    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
    IQueryFilter pFilter = new QueryFilterClass();
    pFilter.WhereClause = "RightID = '" + selectedRightID.ToString() + "'";

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

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

    IApplication m_application = ArcMap.Application;
    IMxDocument pMxDoc = (IMxDocument)m_application.Document;
    IActiveView pActiveView = (IActiveView)pMxDoc.FocusMap;

    IEnvelope pEnv = pFeature.Shape.Envelope;
    pEnv.Expand(1.1, 1.1, true);

    pActiveView.Extent = pEnv;

    pActiveView.Refresh();

我尝试添加此代码,我认为这会将特定功能添加到选择中。但也没有运气。

IFeatureSelection pfeatSelect = pFeatureLayer as IFeatureSelection;
pfeatSelect.Add(pFeature);
4

2 回答 2

1

如果我理解正确,您所需要的只是:

IFeatureSelection featSelect = pFeatureLayer as IFeatureSelection;
featSelect.SelectFeatures(pFilter, esriSelectionResultEnum.esriSelectionResultNew, false);

这将选择与您的过滤器匹配的所有功能。

于 2013-11-05T15:53:05.617 回答
0

这个解决方案对我有用

            IFeatureLayer PFeaLayer = (IFeatureLayer)pLayer;
            IFeatureSelection PFeaSel = (IFeatureSelection)PFeaLayer;
            int OIDIndex = PFeature.Fields.FindField("OBJECTID");
            PFeaSel.SelectionSet.Add(Convert.ToInt32(PFeature.get_Value(OIDIndex)));
            ISelectionSet PFeaSelSet = PFeaSel.SelectionSet;
            IEnumGeometry pEnumGeom = new EnumFeatureGeometryClass();
            IEnumGeometryBind pEnumGeomBind = (IEnumGeometryBind)pEnumGeom;
            pEnumGeomBind.BindGeometrySource(null, PFeaSelSet);
            IGeometryFactory pGeomFactory = new GeometryEnvironmentClass();
            IGeometry pGeom = pGeomFactory.CreateGeometryFromEnumerator(pEnumGeom);
            IMxDocument pMxDoc = ArcMap.Document as IMxDocument;
            IActiveView activeView = pMxDoc.ActiveView;
            double midX = (pGeom.Envelope.XMax + pGeom.Envelope.XMin) / 2;
            double midY = (pGeom.Envelope.YMax + pGeom.Envelope.YMin) / 2;
            IPoint pPoint = new PointClass();
            pPoint.SpatialReference = pGeom.Envelope.SpatialReference;
            pPoint.PutCoords(midX, midY);
            pPoint.Project(activeView.Extent.SpatialReference);
            IEnvelope pCurrentEnvelope = activeView.Extent;
            pCurrentEnvelope.CenterAt(pPoint);
            activeView.Extent = pCurrentEnvelope;
            activeView.Refresh();
于 2020-05-06T04:35:30.523 回答