PublicIFeature Getfeatureonmousedown (IPoint point) {Try{ILayer layer= Common.getlayerbyname (MMap,"plots"); if(Layer = =NULL) {MessageBox.Show ("please load parcel layers! ","Tips"); return NULL; } //Ifeaturelayer flayer = layer as Ifeaturelayer; //ifeatureselection featureselection = Flayer as ifeatureselection; //featureselection.clear (); //if (featureselection = = null)//{ //return null; //}Ifeaturelayer Featurelayer= Layer asIfeaturelayer; if(Featurelayer = =NULL) return NULL; Ifeatureclass Featureclass=Featurelayer.featureclass; if(Featureclass = =NULL) return NULL; //IPoint point = AxMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint (x, y);Igeometry geometry = Point asIgeometry; DoubleLength = Convertpixelstomapunits (Axmapcontrol1.activeview,4); Itopologicaloperator Ptopo= Geometry asItopologicaloperator; Igeometry Buffer=ptopo.buffer (length); Geometry= buffer. Envelope asIgeometry; Ispatialfilter Spatialfilter=NewSpatialfilterclass (); Spatialfilter.geometry=geometry; Switch(featureclass.shapetype) { CaseEsriGeometryType.esriGeometryPoint:spatialFilter.SpatialRel=Esrispatialrelenum.esrispatialrelcontains; Break; CaseEsriGeometryType.esriGeometryPolygon:spatialFilter.SpatialRel=esrispatialrelenum.esrispatialrelintersects; Break; CaseEsriGeometryType.esriGeometryPolyline:spatialFilter.SpatialRel=esrispatialrelenum.esrispatialrelcrosses; Break; } Spatialfilter.geometryfield=Featureclass.shapefieldname; Iqueryfilter Filter= Spatialfilter asIqueryfilter; Ifeaturecursor cursor= Featureclass.search (Filter,false); IFeature pfeature=cursor. Nextfeature (); if(Pfeature! =NULL) { returnpfeature; //Featureselection.add (pfeature); //pfeature = cursor. Nextfeature (); } Else { return NULL; } } Catch { return NULL; } }
You can change my code and change the layer to the layer you need. Can also be written as classes. A variable can be a bit more if it is written as a class.
if NULL ) { return pfeature; // Featureselection.add (pfeature); // pfeature = cursor. Nextfeature (); }
If you select multiple features, you can also change the if to while. You can select multiple features by opening the code that I commented out.
C # Arcgis Engine Gets the features of the mouse down position