# How to find intersecting features from inside a drawn polygon

I have drawn a polygon and I want to get all the intersecting features. But here I got stuck and not able to proceed.When I run the code it allows me to draw the polygon in the map. But I am not very sure how to get all the intersecting features from that geometry. Can you please help me. Here is what I did.

IMxApplication pMxApp = null;
IActiveView activeView = default(IActiveView);

pMxApp = (IMxApplication)m_application;

IMxDocument m_MxDoc = (IMxDocument)m_application.Document;
activeView = (IActiveView)(Map)m_MxDoc.FocusMap;

IMap pMap = default(IMap);
ISpatialReference pSpatialRef = default(ISpatialReference);

pMap = m_MxDoc.FocusMap;
pSpatialRef = pMap.SpatialReference;

IScreenDisplay m_pDisplay = activeView.ScreenDisplay;

ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;

screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)
ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
ESRI.ArcGIS.Display.IRgbColor rgbColor = new
ESRI.ArcGIS.Display.RgbColorClass();
rgbColor.Transparency = 000;

ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit cast.
ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new
ESRI.ArcGIS.Display.SimpleFillSymbolClass();
simpleFillSymbol.Color = color;

ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as
ESRI.ArcGIS.Display.ISymbol; // Dynamic cast.
ESRI.ArcGIS.Display.IRubberBand rubberBand = new
ESRI.ArcGIS.Display.RubberPolygonClass();
ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay,
symbol);
screenDisplay.SetSymbol(symbol);
screenDisplay.DrawPolygon(geometry);

m_pDisplay.FinishDrawing();
geometry.SnapToSpatialReference();

ISpatialFilter spatialFilter = new SpatialFilter();
spatialFilter.Geometry = geometry;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

IElement element = new PolygonElementClass();
element.Geometry = geometry;

• where are you stuck? What happens when you run the code? Please edit the question to provide more information – nmtoken Jun 14 '17 at 4:56
• hey nmtoken, When I run the code it allows me to draw the polygon on the map but not sure how to get all the intersecting features from that geometry. I am going to edit the post with this. – royan Jun 14 '17 at 5:00
• If you want to search all layers you need to enumerate your layers with IMap.Layers() cast to IFeatureLayer and then Search(spatialFilter,Recycling) depending on what you want to do with the features recycling can be true or false. If you already have a layer in mind as an ILayer object then cast that to IFeatureLayer and Search. BTW it's a really good idea to set the geometry spatial reference before putting it onto the spatial filter. – Michael Stimson Jun 14 '17 at 5:31
• Have a look at your previous post Check out gis.stackexchange.com/questions/243336/… where I already answered a similar question. – Michael Stimson Jun 14 '17 at 5:34
• Thanks Michael your suggestion worked. Thanks a lot for the guide. – royan Jun 14 '17 at 9:09