MapObjects map filling Symbol Library Extension

Source: Internet
Author: User
Tags dotnet ole

MapObjects map filling Symbol Library Extension

07-11-12 16:08:52 Author: Daji Source: China GIS Information Network
 
In ing, All map symbols are divided into three categories: point, line, and surface symbols.

Each GIS platform has its own symbol library for the presentation of ground features. The ArcMap of ESRI provides a rich Map Symbol Library. You will find many strings in the Bin \ Styles directory under the installation directory. style files, which store some symbolic information. In addition, the Styles directory under the installation directory contains many files with the. ServerStyle extension, which are also the symbol library files provided by ESRI, but these files are specially provided for ArcGis Engine. For more information about. Style and. ServerStyle, visit www.esri.com. With these symbol libraries, you can create a variety of thematic maps In ArcMap. ArcMap provides a rich array of symbolic information, which basically meets your needs. Of course, you can add symbols in the symbol library and even create a set of your own symbol library if you are not enough.

MapObjects is a set of graphical and GIS functional components provided by ESRI for developers. It consists of an OLE control and a series of programmable OLE objects. With MapObjects, developers can add plotting and GIS functions to applications. Because MapObjects components are used to develop systems with low overhead and shorter development cycle, many application systems use them. ArcGIS Engine is an advanced map application component released in the ESRI ArcGIS 9 series. It has powerful functions and is easy to develop. For MapObjects and ArcGIS Engine ESRI, it is recommended that you use ArcGIS Engine for Development, however, ArcGIS Engine accounts for a large amount of system resources, and the system developed by normal configuration machines running ArcGIS Engine is relatively slow.

Back to the symbol, MapObjects provides the corresponding symbols for the point, line, and surface geographical elements.

1. Point Symbol: MapObjects provides four basic point symbols. However, you can use the TrueType font to expand the Point Symbol. For example, the symbol with the Wingdings index 81 is a small airplane. You can use the character creation Program to create your own TrueType Font symbol library. Font Creator Program is a TrueType Font character creation Program that is very useful. In addition, ICustomMarker can be expanded. However, using TrueType fonts is more effective and convenient than implementing ICustomMarker.

2. Line Symbol: MapObjects only provides five basic line symbols. More line types can only be expanded by implementing the ICustomLine interface.

3. Face Symbol: MapObjects contains the characters filled in 11. Similar to dot and line symbols, ICustomFill can be expanded.

The following describes how to expand the MapObjects surface symbol in Dotnet C. We know that win api provides bitmap painter, which supports color-related bitmaps and non-device-related bitmaps. Therefore, we can use BITMAP to build a paint brush to fill the area. If we use the underlying win api to create a BITMAP filled paint brush from the image, it is difficult for people who do not know much about APIs. However, the Dotnet framework requires only a few APIs, and these symbols can be organized well, such as adding, deleting, editing, and archiving.

The following WINAPI functions are required:

# Region calls the Windows API's GDI Function
[Dllimport ("gdi32.dll", entrypoint = "polypolygon")]
Public static extern int polypolygon (
Int HDC,
Ref int lppoint,
Ref int lppolycounts,
Int ncount
); // Draw a polygon
[Dllimport ("gdi32.dll", entrypoint = "createpen")]
Public static extern int CreatePen (
Int nPenStyle,
Int nWidth,
Int crColor
); // Create a paint brush
[DllImport ("gdi32.dll", EntryPoint = "SelectObject")]
Public static extern int SelectObject (
Int hdc,
Int hObject
); // Select the object [paint brush, paint brush, bitmap, etc.] into the specified device description table.
[DllImport ("gdi32.dll", EntryPoint = "DeleteObject")]
Public static extern int DeleteObject (
Int hObject
); // Delete an object to release resources
[DllImport ("gdi32.dll", EntryPoint = "CreatePatternBrush")]
Public static extern int CreatePatternBrush (
Int hBitmap
); // Creates a paint brush through a bitmap
# Endregion

To better organize symbol information and facilitate reuse, You can compile two classes that can serialize [Serializable]: Fill Symbol: PatternStyle and Symbol Set: StyleContainer.

Patternstyle: Basic information of the description symbol: The symbol content is image, symbol name [patternname], and symbol description [patterndescription].

Stylecontainer: A collection of patternstyles, including some methods for adding, deleting, and modifying patternstyle, as well as static methods for saving and opening the binary filling style file [*. Pattern. Classes marked with [serializable] can be serialized and stored as local files in DOTNET. Access to classes marked with [serializable:

/// <Summary>
/// Read to fill the Style File
/// </Summary>
/// <Param name = "FILENAME"> Style File Path </param>
Public static stylecontainer loadstyles (string filename)
{
Try
{
Stream streamread = file. openread (filename );
Binaryformatter binaryread = new binaryformatter ();
Stylecontainer stylecontainerobj = binaryread. deserialize (streamread) as stylecontainer;
Streamread. Close ();
Return stylecontainerobj;
}
Catch
{
Return NULL;
}
}
/// <Summary>
/// Save the fill Style File
/// </Summary>
/// <Param name = "styles"> stylecontainer object </param>
/// <Param name = "FILENAME"> storage file name </param>
Public static void SaveStyles (StyleContainer styles, string filename)
{
Stream StreamWrite = File. Create (filename );
BinaryFormatter BinaryWrite = new BinaryFormatter ();
BinaryWrite. Serialize (StreamWrite, styles );
StreamWrite. Close ();
}

 

The icustomfill interface is used to implement the setupdc, resetdc, and draw functions.

Private int g_hOldPen;
Private int g_hPen;
Private int g_hOldBrush;
Private int g_hBrush;
Private PatternStyle m_PatternStyle;

# Region ICustomFill Member

Public void ResetDC (int hDC)
{
// TODO: Add Polygons. ResetDC implementation
// Release resources
If (this. g_hPen! = 0)
{
SelectObject (hDC, g_hOldPen );
Deleteobject (g_hpen );
}
If (this. g_holdbrush! = 0)
{
SelectObject (HDC, g_holdbrush );
Deleteobject (g_hbrush );
}
}

Public void setupdc (int hdc, double DPI, object pbasesym)
{
// Todo: Add polygons. setupdc implementation
// Border Style
ESRI. mapobjects2.core. symbol sym = pbasesym as ESRI. mapobjects2.core. symbol;
G_hpen = createpen (sym. style, sym. Size, (INT) sym. Color );
// Create a paint brush from Bitmap Using GDI + and APIs
System. Drawing. bitmap BMP = (system. Drawing. Bitmap) This. m_patternstyle.image;
Int IBMP = BMP. gethbitmap (). toint32 ();
G_hBrush = CreatePatternBrush (ibmp );
DeleteObject (ibmp );
}

Public void Draw (int hDC, ref int points, ref int partCounts, int numParts)
{
// TODO: Add Polygons. Draw implementation
// Select the paint brush and paint brush into the current device description table.
This. g_hOldPen = SelectObject (hDC, g_hPen );
This. g_hOldBrush = SelectObject (hDC, g_hBrush );
// Draw a polygon
PolyPolygon (hDC, ref points, ref partCounts, numParts );
}
# Endregion


Application Example:

Figure 1 filling effect of a single symbol

Figure 2. Independent value filling effect

Download source code and examples [for reference only]

 

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.