1. Preface
For reasons of cost and efficiency, the former company requires the use of open source in our products.GIS components to replace the previously used MAPX, after a period of searching, I found Mapwingis this thing basically can meet our requirements. After a few days of groping, I wrote this article, hoping to be helpful to other people who use Mapwingis. I usually contact GIS very few, also at most is in the development system occasional use of mapx, a lot of basic concepts also do not understand, so there may be a lot of wrong place, forget forgive.
2.MapWinGIS Brief Introduction
Mapwingis is an open source ActiveX component that is functionally similar to MAPX, and can be used by developers to perform GIS functions in their own systems, such as maps, Image,grid displays;Plot points, lines, graphs on layers, calculate lengths, Access GISData and other related work.
Its main features include:
Open, edit, save files in image,grid,shapfile,tin,dbf format directly
Browse, annotate, set colors, and more in the map.
Spatial data query in a map
Dynamically plot spatial data on a layer.
Access the relevant data in the map.
Convert different formats, such as from Tin to gird.
The developers of the Mapwingis team appear to be mainly from the University of Iowa, Mapwingis Press Mozilla Public License 1.1. Release. On the basis of Mapwingis, they developed the Mapwindow GIS, a GIS system that allows users to browse data directly through it and perform other functions through a series of plugins. There is also a set of Mapwinx, which is an auxiliary tool under the Dotnet platform.
Mapwingis is developed by VC under VS2003, Mapwindow GIS is developed by vb.net. Where the Mapwingis code has about 150,000 lines, about 50% of the annotation rate. The Mapwindow website provides a simple example code for VB6, or you can learn some of its more advanced features by watching the Mapwindow GIS.
Its official website is [www.mapwindow.org], the binary is available on the websiteprogram download, source code download, and there are related forums and documents, information is relatively rich, it seems as if there is a developer is Chinese, so there is a Chinese forum, is too few posts.
3. Conversion of file formats
Because the user provides a MapInfo tab-formatted BASEMAP, and Mapwingis cannot process the file in that format, it is necessary to do the relevant conversion work. This is done by first converting the MapInfo's tab-formatted basemap to the MapInfo MIF format (MIF format is the MapInfo Text Interchange Format file). The MIF file format is then converted to the SHP format that Mapwingis can read directly (SHP format is a spatial data file format defined by ESRI Company).
We can use Mitab to convert the tab format to MIF format, Mitab is a set of open source C + + libraries (see [mitab.maptools.org]), which allows users to implement transformations in their own applications based on this library. Mitab also provides a command-line tool Tab2tab.exe directly converts the tab format to MIF format, with the following command:
Tab2tab Source.tab DIST.MIF
After the MIF file is available, the MIF format can be converted to SHP format with OGR, and Ogr is also a set of open source C + + libraries (see [ogr.maptools.org]), which allows users to implement transformations in their own applications based on this library. The org also provides a command-line tool Ogr2ogr.ext to convert the commands to:
Ogr2ogr-f "ESRI Shapefile" dist.shp source.mif
After getting the SHP file from the tab file, we can use the Mapwingis.
4. Introduction to Objects
In Mapwingis, the most commonly used objects are the following:
Map:mapwingis is the most important object for displaying Grid,image and Shapefiles, which manages the layers and responds to mouse actions, similar to the Map object in the MAPX.
Shapefiles: A layer object that can be created by the user or generated from a layer file (SHP file), similar to the Layer object in the MAPX, where punctuation, marking, marking, and so on can be applied to the object.
Shape: A graphical object, which can be a point, a first, a polygon, and so on.
Point: Represents a coordinate dot
Fields: A field that stores relevant geographic information, similar to a field in a dbf table.
Table: One of the tables that stores the relevant geographic information.
Use of 5.MapWinGIS
Mapwingis in the use of VB is relatively simple, the site also provides a VB example, has been very detailed, I am here to talk about the VC in the call and some of my use of some of the problems encountered
5.1 Invocation Mode
In VC6, it seems that for some special reason (as the reason will be discussed later), it is not possible to go directly from Project->add to Project->components and Controls as with other ActiveX Select Mapwingis.ocx to generate the relevant encapsulation class, it will report a mistake, the error is "the ActiveX Control was not registered properly, or it type library version number is Incorrect ... ". You can only select the registered map control from gallery/registered ActiveX controls to add to this project, but in this way only the CMap wrapper class of the map object can be generated, and other objects cannot generate the wrapper class. If a subclass of "COleDispatchDriver" is generated from the type Library, then when a method or property of the associated encapsulated class is called, such as the Open method of Cshapefile, an exception is generated, and the message code for the exception is "8002801D". About this exception, MS has a related explanation, roughly is the version of ATL seems wrong, the previous can not insert the OCX object is probably the reason, the address of this article is: "Http://support.microsoft.com/default.aspx?" scid=kb%3ben-us%3b221792 ". I also saw in the Mapwindow forum that some people have raised this question, and some people have come across it. So, I try to come up with the correct invocation method is to use "#import" Mapwingis.ocx "Rename_namespace (" Mapwindow ") Rename (" GetObject "," Mapwingisgetobject ")" , in order to save trouble, you can still use the previous method of inserting OCX to create a CMap wrapper class, using the map object directly call the map wrapper class, while other objects use IXXXXPTR smart pointer, the following is the calling process:
1. Insert the OCX object in Project->add to Project->components and controls, and generate the CMap1 wrapper class
2. Add #import "Mapwingis.ocx" Rename_namespace ("Mapwindow") Rename ("GetObject", "Mapwingisgetobject") in the StdAfx header file
3. Create a resource ID, select Resource Symbols in the View menu, create a new resource ID, and name it Idc_map
4. In the header file of the view, include the resulting encapsulated class header file, and then add the encapsulated class object, the following code:
#include "Map.h"
Class Ctestmapwindowview:p ublic CView
{
Protected:
CMap1 M_map;
}
5. Create a WM_CREATE message-map function for the view class in an app that views (assumed to be a document-view structure), adding the following code:
if (M_map.create (NULL, ws_visible, CRect (0,0,400,400), this, idc_map) = = False) {
return-1;
}
6. Create a WM_SIZE message map function in the view class, add the following code
void Ctestmapwindowview::onsize (UINT nType, int cx, int cy)
{
Cview::onsize (NType, CX, CY);
Todo:add your message Handler code here
M_map.resize (Cx,cy);
}
In this way, the framework of the application is basically complete and can be compiled and run.
5.2 Adding layers
Because the smart pointer is used for encapsulation in a layer Shapefile object, the code that joins the layer is
Mapwindow::ishapefileptr SF;
HRESULT HR=SF. CreateInstance ("Mapwingis.shapefile");
if (! SUCCEEDED (HR)) {
return;
}
Uses_conversion;
Open a layer file
if (!sf->open (A2bstr ("c:\\temp\\testgis\\shp\\11.shp"), NULL)) {
return;
}
will set the color, label and other information, add the layer to map
Long Hanlde=m_map.addlayer (sf,true); M_map.setshapelayerfillcolor (Handle,rgb ((255-1) *rand (), (255-1) *rand (), (255-1) *rand ()));
M_map.setshapelayerlinecolor (Handle,rgb ((255-1) *rand (), (255-1) *rand (), (255-1) *rand ()));
M_map.setlayerlabelsvisible (handle,true);
5.3 Handling Events
To handle Mapwingis events, you need to create an event slot (EventSink). To do this, in the header file of the view class, add "Declare_eventsink_map ()" Under the Declare_message_map () line, Add the following code to the CPP file:
Begin_eventsink_map (Ctestmapwindowview,cview)
End_eventsink_map ()
In response to the MouseMove event, add the following code to the two lines of code above
On_event (ctestmapwindowview,idc_map,0x03,onmousemove,vts_i2 vts_i2 vts_i4 VTS_I4)
Then add a method to the Ctestmapwindowview class that declares the function:
afx_msg void OnMouseMove (short _button,short _shift,long _x,long _y);
It is important to note that in Mapwingis, in order to be able to respond to an event, you must call Setsendmousemove (TRUE) to respond to the mouse move event, as is the case with other response events.
5.4 Changing the display position
When the user wants the map to roam automatically, the Getextents object of the maps object is called to get the extents object of the map, and then the setbounds of the extents object is called to set the relevant bounds. Finally, the setextents of the map object is called to set the extents object to the Map object.
5.5 Dynamic plotting
When users want to dynamically plot data more frequently, you can use newdrawing to create a paint layer, and then call Drawpoint, DrawLine, or DrawPolygon to mark points, lines, and polygons on the layer you just created. With cleardrawing, you can clear all the graphics that are drawn on this layer, and for the display of the dynamic trajectory, after the draw is called, the cleardrawing is cleared and then the corresponding trajectory is redrawn.
Users can call newdrawing multiple times to create a new paint layer, and the related actions on the new paint layer do not affect other layers of paint that have already been created. The user can call cleardrawing to clear all the graphics on the specified paint layer. However, after you create a new paint layer, you cannot perform any further painting on the other painting layers, and after you call draw, you cannot manipulate the drawn object. The only thing that is available is that you can set a key to the object you just created, set a string for the object you just drew, and read the string. However, you cannot get strings for other objects that you previously set.
5.6 Drawing layers Dynamically
In addition to using newdrawing to create a painting layer, you can also create a shapefile dynamically, making dots, lines, and polygons on this shapefile, and adding additional data as you create the layer. That is, add one or more field, and after inserting a shape, you can specify that the row's data be inserted on the field. On this layer, all graphical objects can be manipulated.
5.7 Shapefilecolorbreak objects and Shapefilecolorscheme objects
When creating Shapefilecolorbreak objects and Shapefilecolorscheme objects, their progid is "Mapwingis.shapefilelegendbreak" and " Mapwingis.shapefilelegend "instead of" Mapwingis.shapefilecolorbreak "and" Mapwingis.shapefilecolorschema ". The name of the person I took for granted at the outset was the name of the ProgID, which was later found to be wrong, and here's a reminder.
6. Other Notes
The display speed of Mapwingis with the number of several times more than mapx, I have done experiments, if the plot to plot 1 million points, if the use of mapx, about 5-10 minutes, if using Mapwingis, on the shapefile to draw about 1 minutes, Using Newdraw is faster.
Perhaps due to some of the reasons for the SHP itself, some of the information peculiar to the MapInfo map, such as railroad lines, specially labeled points (such as the Red Cross of medical institutions), and the width of the cable, have not been converted to SHP. Thus the displayed map does not show in the mapx good-looking, of course, can be displayed through other methods to display this information, but it is more troublesome, if users of the GIS system requirements are relatively high, with Mapwingis may have some trouble.
After the Mapwingis of the source code I used VS2005 compiled a bit, found that can not be compiled, with VS2003, in the debug version of the connection error, release version is compiled through, specific what reason, there is time to think about
Mapwindow Simple Introduction