C # Arcgis Engine Gets the features of the mouse down position

Source: Internet
Author: User
Tags ipoint

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.