Arcengine method of realizing feature selection (reproduced)

Source: Internet
Author: User
Tags imap ipoint

the method of realizing the selection of elements from the original Arcengine (reproduced)

There are many ways to select a feature or a feature set (Featureselection), such as Imap::selectbyshape, Ilayer::search, Ifeaturesection::selectfeature, and so on.

The main method to use:

IMAP interface Selectfeature (layer, Feature) (method, select a Feature from a layer);

IMAP interface Selectbyshape (shape, env, Justone) (method that relies on a graph's range shape and a selected environment env to select features from the layer, And in all layers, select only from the Ifeaturelayer layer)

Ifeatureselection Interface Selectfeatures (filter, method, Justone) (methods, according to the standard filter filter and method specified, select features, the first parameter is a variable of type queryfilter, The second argument is a variable of type Esriselectionresultenum, the third argument is a Boolean variable, usually false)

Ifeaturelayer Interface Search (Iqueryfilter, book) (method, create a cursor to query the corresponding set of filters)

1-point selection to get features

Cut the crap and read the code first:

Private DoubleConvertpixelstomapunits (Iactiveview Pactiveview,Doublepixelunits) {    //Uses the ratio of the size of the map in pixels to map units to do the conversionIPoint P1 =PActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperLeft; IPoint P2=PActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperRight; intx1, x2, y1, y2; PActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint (P1, outX1, outy1); PActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint (P2, outX2, outy2); DoublePixelextent = x2-X1; DoubleRealworlddisplayextent =PActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width; DoubleSizeofonepixel = realworlddisplayextent/pixelextent; returnPixelunits *Sizeofonepixel;} IMap PMap=Axmapcontrol1.map;iactiveview Pactiveview= PMap asIactiveview;ifeaturelayer Pfeaturelayer= Pmap.get_layer (0) asIfeaturelayer;ifeatureclass Pfeatureclass=Pfeaturelayer.featureclass;//set the location of the click PointIPoint point =PActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint (e.x, e.y); Itopologicaloperator Ptopo= Point asItopologicaloperator;DoubleLength;length= Convertpixelstomapunits (Pactiveview,4); Igeometry pbuffer=ptopo.buffer (length); Igeometry pgeomentry=Pbuffer.envelope;//Space FilterIspatialfilter Pspatialfilter =NewSpatialfilterclass ();p spatialfilter.geometry=Pgeomentry;//set different spatial filtering relationships depending on the selected featureSwitch(pfeatureclass.shapetype) { CaseEsriGeometryType.esriGeometryPoint:pSpatialFilter.SpatialRel=Esrispatialrelenum.esrispatialrelcontains;  Break;  CaseEsriGeometryType.esriGeometryPolyline:pSpatialFilter.SpatialRel=esrispatialrelenum.esrispatialrelcrosses;  Break;  CaseEsriGeometryType.esriGeometryPolygon:pSpatialFilter.SpatialRel=esrispatialrelenum.esrispatialrelintersects;  Break;} Ifeatureselection pfselection=pfeaturelayer asIfeatureselection;pfselection.selectfeatures (pspatialfilter,esriselectionresultenum.esriselectionresultnew ,false); Iselectionset Pselectionset=pfselection.selectionset;icursor Pcursor;pselectionset.search (NULL,true, outpcursor); Ifeaturecursor pfeatcursor=pcursor asifeaturecursor;ifeature pfeature=pfeatcursor.nextfeature (); while(pfeature!=NULL) {pmap.selectfeature (pfeaturelayer,pfeature); Pfeature=pfeatcursor.nextfeature ();} Pactiveview.partialrefresh (Esriviewdrawphase.esriviewgraphicselection,NULL,NULL);//Additional rewriting:Pspatialfilter.geometryfield =Pfeatureclass.shapefieldname;iqueryfilter PFilter=Pspatialfilter; Ifeaturecursor Pfeatcursor= Pfeaturelayer.search (PFilter,false); IFeature pfeature=pfeatcursor.nextfeature ();  while(pfeature!=NULL) {pmap.selectfeature (pfeaturelayer,pfeature); Pfeature=pfeatcursor.nextfeature (); } pactiveview.partialrefresh (Esriviewdrawphase.esriviewgraphicselection,NULL,NULL);

There is also a relatively simple point selection method:

Igeometry g =NULL; Ienvelope Penv;iactiveview Pactiveview=Axmapcontrol1.activeview;imap PMap=axmapcontrol1.map;penv=Axmapcontrol1.trackrectangle ();if(Penv.isempty = =true) {ESRI.    ArcGIS.Display.tagRECT R; R.bottom= E.y +5; R.top= E.y-5; R.left= e.x-5; R.right= e.x +5; PActiveView.ScreenDisplay.DisplayTransformation.TransformRect (Penv,refR4); Penv.spatialreference=pActiveView.FocusMap.SpatialReference;} G= Penv asIgeometry;axmapcontrol1.map.selectbyshape (g,NULL,false); Axmapcontrol1.refresh (Esriviewdrawphase.esriviewgeoselection,NULL,NULL);

2 Drop Box Selection

IMap pMap = axmapcontrol1.map;
Iactiveview Pactiveview = pMap as Iactiveview;
Ienvelope penv = axmapcontrol1.trackrectangle ();
Pmap.selectbyshape (penv, null, false);
Pactiveview.partialrefresh (esriviewdrawphase.esriviewgeoselection,null, null);

Arcengine method of realizing feature selection (reproduced)

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.