ArcGIS Engine Capture

Source: Internet
Author: User
Tags imap ipoint

Original ArcGIS Engine capture

BOOLBcreateelement =true;intInternaltime =5;//time intervalintSnaptime =Ten;//Initial valueIElement m_element =NULL;//interface Drawing point elementsIPoint Currentpoint =NewPointclass ();//Current Mouse PointIPoint Snappoint =NULL;//Snap to the pointImovepointfeedback Pfeedback =NewMovepointfeedbackclass (); Public voidDomousemove (Objectsender, Imapcontrolevents2_onmousemoveevent e) {Axmapcontrol AxMapControl1= Sender asAxmapcontrol;    Currentpoint.putcoords (E.MAPX, e.mapy); if(Action = =actiontype.createfeature) {snaptime++; Snaptime= Snaptime%Internaltime; ILayer Layer=getlayerbyname (Snaplayer, axMapControl1); Ifeaturelayer M_ifeaturelyr= Layer asIfeaturelayer; if(bcreateelement) {createmarkerelement (currentpoint,axmapcontrol1); Bcreateelement=false; }           if(Snappoint = =NULL) Elementmoveto (Currentpoint, axMapControl1); //Mouse Auto -capture vertex    if(Snaptime = =0) Snappoint=snapping (E.MAPX, e.mapy, M_ifeaturelyr, axMapControl1); if(Snappoint! =NULL&& Snaptime = =0) Elementmoveto (Snappoint, axMapControl1); }}/// <summary>///Capture/// </summary>/// <param name= "x" ></param>/// <param name= "y" ></param>/// <param name= "Ifeaturelyr" ></param>/// <param name= "axmapcontrol1″></param>/// <returns></returns> PublicIPoint Snapping (DoubleXDoubley, Ifeaturelayer Ifeaturelyr, Axmapcontrol axMapControl1) {IPoint Ihitpoint=NULL; IMAP IMAP=Axmapcontrol1.map; Iactiveview IView=Axmapcontrol1.activeview; Ifeatureclass IFCLSS=Ifeaturelyr.featureclass; IPoint Point=NewPointclass (); Point.    Putcoords (x, y); DoubleLength = Convertpixelstomapunits (Axmapcontrol1.activeview,8); Itopologicaloperator Ptopo= Point asItopologicaloperator; Igeometry Pgeometry= Ptopo.buffer (length). Envelope asIgeometry; Ispatialfilter Spatialfilter=NewSpatialfilterclass (); Spatialfilter.geometryfield=IFeatureLyr.FeatureClass.ShapeFieldName; Spatialfilter.spatialrel=esrispatialrelenum.esrispatialrelcrosses; Spatialfilter.geometry=Pgeometry; Ifeaturecursor cursor= Ifclss.search (Spatialfilter,false); IFeature IF=cursor.    Nextfeature (); if(IF = =NULL)return NULL; IPoint ihitpt=NewESRI.    ArcGIS.Geometry.Point (); Ihittest ihittest= If.shape asihittest; DoubleHitdist =0; intPartindex =0; intVertexindex =0; BOOLBvertexhit =false; //tolerance in pixels for line hits    DoubleTol = Convertpixelstomapunits (IView,8); if(Ihittest.hittest (Point, Tol, Esrigeometryhitparttype.esrigeometrypartboundary, IHITPT,refHitdist,refPartindex,refVertexindex,refbvertexhit)) {Ihitpoint=ihitpt;    } AxMapControl1.ActiveView.Refresh (); returnIhitpoint;}/// <summary>///creates a new element for displaying/// </summary>/// <param name= "point" ></param>/// <param name= "axmapcontrol1″></param> Public voidcreatemarkerelement (IPoint point, Axmapcontrol axMapControl1) {Iactiveview IView=Axmapcontrol1.activeview; Igraphicscontainer Igraphcontainer= Axmapcontrol1.map asIgraphicscontainer; //Create a marker elementImarkerelement imarkerelement =NewMarkerelement () asimarkerelement; Isimplemarkersymbol Isym=NewSimplemarkersymbol (); //symbolizing elementsIrgbcolor icolor =NewRgbColor (); Icolor.red=0; Icolor.blue= -; Icolor.green=255; Isym.color=Icolor; Irgbcolor IColor2=NewRgbColor (); Icolor2.red=0; Icolor2.blue=0; Icolor2.green=0; Isym.outline=true; Isym.outlinecolor= IColor2 asIcolor; Isym.outlinesize=1; Isym.size=5; Isym.style.=esrisimplemarkerstyle.esrismscircle; Isymbol symbol= Isym asIsymbol; Symbol. ROP2=Esrirasteropcode.esriropnotxorpen; Imarkerelement.symbol=Isym; M_element= Imarkerelement asielement; M_element. Geometry= Point asIgeometry; Igraphcontainer.addelement (M_element,0); Iview.partialrefresh (Esriviewdrawphase.esriviewgraphics, M_element,NULL); Igeometry Igeo=m_element.    Geometry; Pfeedback.display=Iview.screendisplay; Pfeedback.symbol= Isym asIsymbol; Pfeedback.start (Igeo asIPoint, point);}/// <summary>///Moving Elements/// </summary>/// <param name= "iPt" ></param>/// <param name= "axmapcontrol1″></param> Public voidElementmoveto (IPoint iPt, Axmapcontrol axMapControl1) {//Moving ElementsPfeedback.moveto (iPt); Igeometry IGeo1=NULL;    Igeometry Igeoresult; if(M_element! =NULL) {IGeo1=m_element.  Geometry; Igeoresult=Pfeedback.stop (); //map. Activeview.refresh ();M_element. Geometry =Igeoresult; //Update the location of the element    axMapControl1.ActiveView.GraphicsContainer.UpdateElement (m_element); //re-move elementsPfeedback.start (iGeo1 asIPoint, iPt); //map. Activeview.refresh ();AxMapControl1.ActiveView.PartialRefresh (Esriviewdrawphase.esriviewgraphics,NULL,NULL); }} PublicILayer Getlayerbyname (stringLayerName, Axmapcontrol axMapControl1) {     for(inti =0; i < Axmapcontrol1.layercount; i++) {if(Axmapcontrol1.get_layer (i). Name.equals (layername))returnAxmapcontrol1.get_layer (i); }    return NULL;} Public DoubleConvertpixelstomapunits (Iactiveview Pactiveview,Doublepixelunits) {    Doublerealworlddisplayextent; intpixelextent; DoubleSizeofonepixel; Pixelextent=pActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame (). right–    PActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame (). Left; Realworlddisplayextent=PActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width; Sizeofonepixel= Realworlddisplayextent/pixelextent; returnPixelunits *Sizeofonepixel;}

ArcGIS Engine capture

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.