public void getFeature(IActiveView activeView, int button, int shift, int X, int Y)
{
IMap map;
IPoint ClickedPoint = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
if (activeView is IMap)
{
map = activeView.HitTestMap(ClickedPoint);
if (map == null) return;
IRubberBand rubberEnv = new RubberEnvelopeClass();
IGeometry geom = rubberEnv.TrackNew(activeView.ScreenDisplay, null);
IArea area = (IArea)geom;
if (geom.IsEmpty == true)
{
IEnvelope tempEnv = new EnvelopeClass();
tagRECT RECT = new tagRECT();
RECT.bottom = 0;
RECT.left = 0;
RECT.right = 5;
RECT.top = 5;
IDisplayTransformation dispTrans = activeView.ScreenDisplay.DisplayTransformation;
dispTrans.TransformRect(tempEnv, ref RECT, 4);
tempEnv.CenterAt(ClickedPoint);
geom = (IGeometry)tempEnv;
}
if (geom.IsEmpty == true) return;
@ HERE I NEED SPATIAL FILTER @
}
}http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//000100000240000000
public void getFeature(IActiveView activeView, int button, int shift, int X, int Y)
{
IMap map;
IPoint ClickedPoint = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
if (activeView is IMap)
{
map = activeView.HitTestMap(ClickedPoint);
if (map == null) return;
IRubberBand rubberEnv = new RubberEnvelopeClass();
IGeometry geom = rubberEnv.TrackNew(activeView.ScreenDisplay, null);
IArea area = (IArea)geom;
if (geom.IsEmpty == true)
{
IEnvelope tempEnv = new EnvelopeClass();
tagRECT RECT = new tagRECT();
RECT.bottom = 0;
RECT.left = 0;
RECT.right = 5;
RECT.top = 5;
IDisplayTransformation dispTrans = activeView.ScreenDisplay.DisplayTransformation;
dispTrans.TransformRect(tempEnv, ref RECT, 4);
tempEnv.CenterAt(ClickedPoint);
geom = (IGeometry)tempEnv;
}
if (geom.IsEmpty == true) return;
ISpatialFilter spatialFilter = new SpatialFilterClass();
IFeatureLayer schoolLayer = (IFeatureLayer)axMapControl1.get_Layer(0);
IFeatureClass schoolFeature = schoolLayer.FeatureClass;
spatialFilter.Geometry = geom;
spatialFilter.GeometryField = schoolFeature.ShapeFieldName;
spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
spatialFilter.SubFields = "SCHOOL";
int nameFieldPosition = schoolFeature.FindField("SCHOOL");
using (ComReleaser comReleaser = new ComReleaser())
{
IFeatureCursor schoolCursor = schoolFeature.Search(spatialFilter, false);
comReleaser.ManageLifetime(schoolCursor);
IFeature schoolFeat = null;
while ((schoolFeat = schoolCursor.NextFeature()) != null)
{
string name = Convert.ToString(schoolFeat.get_Value(nameFieldPosition));
MessageBox.Show(name);
}
}
}
}