C# 如何使用C语言在ArcGIS中选择要素和高亮显示#
您好,下面是基于属性放大arcGIS对象的代码,现在我需要的是能够使用选择功能(在地图上的区域上单击鼠标右键并选择功能)高亮显示该区域 目前,我有一个事件将进行缩放。我想将此选择添加到同一属性 提前谢谢你C# 如何使用C语言在ArcGIS中选择要素和高亮显示#,c#,arcgis,esri,arcobjects,C#,Arcgis,Esri,Arcobjects,您好,下面是基于属性放大arcGIS对象的代码,现在我需要的是能够使用选择功能(在地图上的区域上单击鼠标右键并选择功能)高亮显示该区域 目前,我有一个事件将进行缩放。我想将此选择添加到同一属性 提前谢谢你 ESRI.ArcGIS.Carto.ILayer layer = GetLayersClass.GetFieldBoundaryLayer; if (layer is ESRI.ArcGIS.Carto.IGroupLayer) { ESRI.ArcGIS.Carto.IGroupLa
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);
如果我理解正确,您所需要的就是:
IFeatureSelection featSelect = pFeatureLayer as IFeatureSelection;
featSelect.SelectFeatures(pFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
这将选择与您的过滤器匹配的所有功能。如果我理解正确,您所需要的就是:
IFeatureSelection featSelect = pFeatureLayer as IFeatureSelection;
featSelect.SelectFeatures(pFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
这将选择与您的过滤器匹配的所有功能。此解决方案适用于我
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();
这个解决方案对我有效
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();
我确实尝试过这段代码,在“if”条件之前进行了IFeatureSelection,但仍然无法将其高亮显示(当我使用鼠标右键进行交互时,它会以蓝色边框高亮显示)。是否有其他方法可以实现这一点???@sss111,下面是使用“spatialfilter”解决问题的方法在上,我确实尝试了这段代码,并在“if”条件之前进行了IFeatureSelection,但仍然无法将其高亮显示(当我使用鼠标右键进行交互时,它会以蓝色边框高亮显示)。是否有其他方法来实现这一点???@sss111,下面是使用IMap上的“spatialfilter”解决问题的方法。SelectFeature(播放器,pFeature)或IMap.FeatureSelection=(ISelection)pFeatureSelect;IMap.SelectFeature(播放器,pFeature)或IMap.FeatureSelection=(ISelection)pfeatSelect;感谢您对社区的贡献。这可能是一个正确的答案,但为您的代码提供额外的解释,以便开发人员能够理解您的推理是非常有用的。这对于可能不熟悉语法的新开发人员尤其有用。此外,它还可以帮助减少后续问题的需要ons。感谢您对社区的贡献。这可能是一个正确的答案,但为您的代码提供额外的解释会很有用,这样开发人员就可以理解您的推理。这对于可能不熟悉语法的新开发人员来说尤其有用。此外,它还可以帮助减少后续问题的需要。