【问题标题】:How to Select feature and highlight in ArcGIS using C#如何使用 C# 在 ArcGIS 中选择要素并突出显示
【发布时间】:2013-11-16 13:22:17
【问题描述】:

您好,我在下面有以下代码,用于根据属性放大 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);

【问题讨论】:

标签: c# arcgis esri arcobjects


【解决方案1】:

这个解决方案对我有用

            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();

【讨论】:

  • 感谢您对社区的贡献。这可能是一个正确的答案,但对您的代码提供额外的解释会很有用,以便开发人员能够理解您的推理。这对于可能不熟悉语法的新开发人员特别有用。此外,它可以帮助减少对后续问题的需求。
【解决方案2】:

如果我理解正确的话,你只需要这样:

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

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

【讨论】:

  • 我确实尝试过这段代码,并在“if”条件之前做了一个 IFeatureSelection,但仍然无法突出显示(当我通过右键单击交互执行此操作时,它以蓝色边框突出显示) .
  • 还有其他方法可以实现吗?
  • @sss111,这是在gisremotesensing.com/2017/04/…上使用“spatialfilter”解决问题的方法
猜你喜欢
  • 2016-05-06
  • 2016-01-18
  • 2020-06-08
  • 1970-01-01
  • 2015-04-05
  • 2014-09-18
  • 2014-12-26
  • 1970-01-01
  • 2021-09-22
相关资源
最近更新 更多