Arcengine cliasic code) Use ArcGIS Engine + C # to customize dynamic power symbols.

Source: Internet
Author: User
Tags ipoint

Based onArcGIS Engine + C #Implement User-Defined dynamic power symbol

Huawei grid Beijing R & D center awen

The second development of ArcGIS Engine generally requires the production of these symbols through the desktop product, and then the conversion through a dedicated Conversion Tool for AE to use. In the application of power GIS, there are many types of power equipment, and the status of the equipment is complex. Different symbols are required to express the status of power equipment. In addition, power technology is updated rapidly, new Device types are constantly being introduced. Users often require symbolic definition tools to meet these requirements. This article uses distribution transformer as an example to introduce a method that allows you to define device symbols by yourself using ArcGIS Engine + C # secondary development mode.

I. symbol Definition

Shows the distribution transformer symbol:

The image of this topic is as follows:

This symbol can be divided into four elements, two segment segments, and two circles (ARCs ). Use the following structure to describe elements:

Public struct metadata


Public int typ; // graphical Type 3: arc, 0: Line Segment

Public double scale; // scale

Public int offsx; // offset (X)

Public int offsy; // offset (y)

Public double angle; // rotate

Public int x1; // position of the first vertex of the element (X)

Public int Y1; // position of the first vertex of the element (y)

Public int X2; // The second position of the element (X)

Public int Y2; // The second position of the element (y)

Public int X3; // The third position of the element (X)

Public int Y3; // The third position of the element (y)

Public int X4; // position of the fourth vertex of the element (X)

Public int Y4; // position of the fourth vertex of the element (y)


// Line segment: First point: Start Point coordinate, second point: End Point coordinate, third point, fourth point is empty

// Arc: The first point is the upper left corner of the rectangle to which the arc belongs,

// Second point: the left and right sides of the rectangle to which the arc belongs,

// Point 3: Arc Start Point

// Point 4: arc end point

// The Arc direction is counter-clockwise. For circle X3, Y3, X4, and Y4

The coordinates of each element are as follows:










First point










Second point




















Point 4










You can write a drawing tool to draw simple elements, so that you can easily draw these elements. The drawn elements are saved in the above format and saved to the database for easy system reading.

2nd floor

TanhwPosted on: 10:49:00

1. Custom and implemented symbol class mymarkersymbol:

1. Class Definition:

Custom symbols must implement the following four interfaces:





The mymarkersymbol class is defined:

Public class mymarkersymbol: imarkersymbol, isymbol, iclone, ipersistvariant


Public mymarkersymbol ()


// Base. New ();

Class_initialize_renamed ();



Constructor. The angle of the symbol must be passed in.

Public mymarkersymbol (double Ange)


// Base. New ();

Class_initialize_renamed ();

M_angle = Ange;


// Member variable

Private int m_lpen;

Private int m_loldpen;

Private int m_lhdc;

Private double m_angle;

Private int m_symbolindex;

Private ESRI. ArcGIS. display. idisplaytransformation m_pdisptrans;

Private int m_lsize;

2. Implementation of interface functions:

To implement custom symbols, You need to implement multiple functions of these four interfaces. The most important is the three functions of imarkersymbol: setupdc, draw, and resetdc.

Setupdc is used to set the paint brush, color, and other information.

Public void setupdc (int hdc, itransformation transformation)


// Todo: Add mymarkersymbol. setupdc implementation

M_lpen = createpen (0, 2, system. Convert. toint32 (m_pcolor.rgb ));

M_loldpen = SelectObject (HDC, m_lpen );

M_lhdc = HDC;

M_pdisptrans = (idisplaytransformation) transformation;


HDC is the canvas handle.

Resetdc function. After the rendering is complete, release the resource and return the status.

Public void resetdc ()


// Todo: Add mymarkersymbol. resetdc implementation

SelectObject (m_lhdc, m_loldpen );

Deleteobject (m_lpen );

M_pdisptrans = NULL;

M_lhdc = 0;


The draw function is used to draw symbols:

Public void draw (igeometry geometry)


// Todo: Add mymarkersymbol. Draw implementation

If (geometry = NULL)




ESRI. ArcGIS. Geometry. ipoint PPT;

PPT = (ipoint) geometry;

Int X;

Int y;

If (m_pdisptrans = NULL)


X = (INT) PPT. X;

Y = (INT) PPT. Y;




M_pdisptrans.frommappoint (PPT, out X, out y );


Drawmetas (x, y );


3. Implementation of drawmetas:

You need to draw two straight lines and combine two circles on the canvas, which can be achieved by calling the Windows API function:

[System. runtime. interopservices. dllimport ("GDI32")]

Private Static extern bool lineto (int hdc, int X, int y );

[System. runtime. interopservices. dllimport ("GDI32")]

Public static extern bool movetoex (int hdc, int X, int y, lppoint );

[System. runtime. interopservices. dllimport ("GDI32")]

Public static extern bool arc

(Int hdc, int X1, int Y1, int X2, int Y2, int X3, int Y3, int X4, int Y4 );

Third floor

TanhwPosted on: 10:53:00

4. Element Rotation

The custom symbol must be rotated at the specified angle. The method for rotating a straight line is relatively simple. The following describes the method for rotating an arc:

Take the upper left corner of the rectangle where the arc is located as an example:

The image of this topic is as follows:

The coordinates before rotation are (x0, y0), the coordinates after rotation are (x1, Y1), and the rotation radius R and alpha are calculated. Then:

X1 = r * Math. Cos (alpha-mangle );

Y1 = r * Math. Sin (alpha-mangle );

Other fixed points can also be calculated using the same method.

After calculating each vertex, call the following method to draw an arc:

ARC (m_lhdc, (INT) (X1), (INT) (Y1), (INT) (X2), (INT) (Y2), (INT) (X3 ), (INT) (Y3), (INT) (X4), (INT) (Y4 ));

You can use the following method to draw a line segment:

Lppoint prepos = new lppoint ();

Movetoex (m_lhdc, (INT) x1, (INT) Y1, prepos );

Lineto (m_lhdc, (INT) x2, (INT) Y2 );

Iii. Call symbols

1. Use the isimplerenderer interface for rendering:

// Define render

Isimplerenderer psimplerenderer = new simplerendererclass ();

// Define custom symbols

Mymarkersymbol mmymarkersymbol = new mymarkersymbol ();

// Rendering

Igeofeaturelayer m_pgeofeaturelayer;

Psimplerenderer. symbol = (isymbol) mmymarkersymbol;

M_pgeofeaturelayer = (igeofeaturelayer) ly;

M_pgeofeaturelayer.renderer = (ifeaturerenderer) psimplerenderer;

2. Use the iuniquevaluerenderer interface for rendering:

Iuniquevaluerenderer Prender = new uniquevaluerendererclass ();

Ianglefield = pfields. findfield ("angle ");

For (INT I = 0; I <pfeatcls. featurecount (pqueryfilter); I ++)


Pfeat = pfeatcursor. nextfeature ();

String x = NULL;

X = pfeat. get_value (ifield). tostring ();

Dangle = (double) pfeat. get_value (ianglefield );

Symbolindex = int. parse (pfeat. get_value (isymindexfield). tostring ());

Mymarkersymbol sym = new mymarkersymbol (dangle );

Prender. addvalue (x, x, (isymbol) MSY );


Plyr. Renderer = (ifeaturerenderer) Prender;

The above introduction can only implement relatively simple dynamic symbols, but as long as the functions are improved, various complex power symbols can be implemented and applied to the application development of ArcGIS Engine, the system automatically renders the device symbols. If you have a better way please enlighten me (

Related Article

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: 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.