Click here to Skip to main content
15,121,963 members
Articles / Desktop Programming / Windows Forms
Posted 12 Jul 2009


171 bookmarked

Build a Desktop GIS Application Using MapWinGIS and C#

Rate me:
Please Sign up or sign in to vote.
4.89/5 (70 votes)
13 Jul 2009CPOL6 min read
The royal gate to building Desktop GIS applications using the Open Source MapWinGIS and C#.


A Geographic Information System is a type of application which has a set of facilities to capture, store, retrieve, maintain, and display geographic data and information. GIS applications are developed to meet many purposes, from simple purposes like GIS data exploration to sophisticated purposes like watershed mapping. Different commercial libraries are available for developers to use and implement in their applications, like ArcObject from ESIR and Map Suite from ThinkGeo. Unfortunately, the cost of license for these libraries is usually high, which makes the GIS application development process not viable for free lance programmers and small firms. In this series of tutorials, I am going to describe in detail how to build a desktop GIS application using the Open Source MapWinGIS library and C#. MapWinGIS is an ActiveX control for GIS development, with built-in support for many Raster and Vector formats. MapWinGIS.ocx is the core of MapWindow GIS, the well known Open Source, multi-purpose, GIS desktop application. The first step in reading this tutorial is acquiring MapWinGIS.ocx from the MapWindow GIS Open Source project website, then installing it to your computer using the installation procedures provided by the project site.

Create Your Map


In this tutorial, I am using .NET Framework 3.5 and Microsoft Visual Studio 2008 Professional Edition. Actually, you can use Visual Studio Express Edition without any problem. I am also using a set of GIS data in ESRI shapefile format, which I have provided above as a zipped file. I recommend you to download this data compressed file, decompress it, and place the file contents in an independent folder. Now, you are ready to go to the next step.

Create a Project and Add a Reference to MapWinGIS Components

Now, fire up your Visual Studio and create a new Windows Forms application. Point to the Project menu, then click Add Reference. In the Add Reference dialog box, point to COM tab, then select MapWinGIS Components from the Component Name list and click OK.


Now, you have a new reference in your project and you can show its name under References in the Solution Explorer.


Now, we are going to add the Map control to our toolbox. The Map control is a control used as a container and interactive display area for geographic data. To add this control to the toolbox, point to the General tab in the toolbox and right click. Select Choose Item from the menu. The Choose Toolbox Item dialog box will appear. Select the COM Component tab and then select Map Control. To add it to the toolbox, click OK.


Now, you can see the Map Control icon in the toolbox contained by the General tab.


Time to Create Your GUI

Now, it's time to build your interface. Drag a ToolStrip control from the Menu & Toolbars tab in the toolbox and drop it to the form. Add five buttons to the ToolStrip, and name these buttons toolCursor, toolZoomExtent, toolZoomIn, toolZoomOut, and toolPan. You can also assign meaningful labels and images to the buttons (you can use the images that I have in my project resources). Drag the Map control from the toolbox and drop it to the form. In the Properties window, set the Dock property of the Map control to Fill and set the CursorMode property to cmNone.

Load your GIS data to the Application Pragmatically

Now, we will add two ESRI Shapefiles for our map. The ESRI Shapefile or simply a Shapefile is a popular geospatial vector data format for geographic information systems software. In the Form1_Load event, add the following code:

//Add first layer to your map
int intHandler1; //integer index to handle the layer
//create a new instance for MapWinGIS.Shapefile
//MapWinGIS.Shapefile  is a data provider for ESRI Shapefile
MapWinGIS.Shapefile shapefile1 = new MapWinGIS.Shapefile();
//Define the data source for MapWinGIS.Shapefile instance
shapefile1.Open(@"D:\GISSampleData\base.shp", null );
//display the layer on the map
intHandler1 = axMap1.AddLayer(shapefile1, true);

//Add second layer
int intHandler2;
MapWinGIS.Shapefile shapefile2 = new MapWinGIS.Shapefile();
shapefile2.Open(@"D:\GISSampleData\nile.shp", null);
intHandler2 = axMap1.AddLayer(shapefile2, true);

In the first line, we have created an integer variable (intHandler1). In the second line, we have created an instance (shapefile1) for the MapWinGIS.Shapefile class. MapWinGIS.Shapefile is a container for geometric entities that represent real world geographic features. In the third line, the data source for the new object (shapefile1) is defined. This data source is an ESRI Shapefile. This data source shows Egypt as a polygon. In the fourth line, we have added this new object to our map control (axMap1) and made it visible. The function AddLayer is used to add a geographic layer to the map control and return an integer indicating the layer handler. Lines 4 to 8 add the second Shapefile to the Map control and make it visible. It is now time to run your first GIS application; strike F5 in your key board to show Egypt's map in the map control.


Change Your Feature Symbol

Customizing different symbology for different geographic features included in the map is one of the most important tasks for a GIS developer. In this lesson, I am going to present the easiest way to customize features symbology. Actually, MapWinGIS provides many advanced methods to symbolize GIS data, which I will discuss in an advanced lesson. Now, add the following code after the previous code in Form1_Load event:

//Set Filling color of the ploygon shapefile
//Set the line color
axMap1 .set_ShapeLayerLineColor (intHandler2 ,
//Set the line width

In the first line, we use the set_ShapeLayerFillColor method of the Map control (axMap1). This method uses the layer handler (intHandler1) and a color in UInt32 format to set the fill color for the defined layer. There are many other useful methods provided by the Map control to customize the layer symbology, like set_ShapeLayerFillStipple which defines the filling type of the layer, and set_ShapeLayerFillTransparency which defines the transparency level of the layer. In the second line, another method is used. This method - set_ShapeLayerLineColor - defines the color of line for line-geometry layers using the layer handler and the UInt32 format for color. In the third line, I have used the set_ShapeLayerLineWidth method to define the width of the line-geometry layer using this layer handler, and a float number denotes the line width. Run your application to see how it displays your map now.


Add Some Actions to Your Map

Sure, you want to add some amazing actions like zoom in, zoom out, and pan for your map. Adding such actions is a very simple task with MapWinGIS. The CursorMode property for the Map control provides these tasks in an easy to use way; you have to assign the mode that you want to this property to use it directly in your map. In the following code, I am going to play with the CursorMode property using the Click event for each button in my toolbar.

private void toolCursor_Click(object sender, EventArgs e)
    axMap1.CursorMode = MapWinGIS.tkCursorMode.cmNone;

private void toolZoomIn_Click(object sender, EventArgs e)
    axMap1.CursorMode = MapWinGIS.tkCursorMode.cmZoomIn;

private void toolZoomOut_Click(object sender, EventArgs e)
    axMap1.CursorMode = MapWinGIS.tkCursorMode.cmZoomOut;

private void toolPan_Click(object sender, EventArgs e)     
    axMap1.CursorMode = MapWinGIS.tkCursorMode.cmPan;

To set your map to the maximum map extent, you will use the ZoomToMaxExtents method of the Map control. Just call this method using the Click event as follows to display your map in the maximum extent:

private void toolZoomExtent_Click(object sender, EventArgs e)

Time to test these new features; run your application, and check every button.


MapWinGIS is the most easy way to create GIS desktop applications. The above features show the principle tasks required by a GIS programmer. Future lessons in this series will look at many useful and advanced features of MapWinGIS.


  • First version: July 12, 2009.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Wisam E. Mohammed
Dammam University, Kingdom of Saudi Arabia
Egypt Egypt
Wisam Mohammed was graduated with B.Sc in Math then got M.Sc and Ph.D in Geographic Information Systems. He is working now as Assistant Professor for GIScience in Dammam University, Kingdom of Saudi Arabia where he is living. He had worked for different international and governmental firms.
He is also a Technical Writer. He published many books in Arabic and many scientific papers in the scientific journals. He is the official editor for the Arabic Manual of MapWindow GIS. His book "Basics of Geographic information Systems" was best seller technical book for 2008 in many Arabian Countries. He was honored by many scientific and academic institutions in Arabic countries as a pioneer of the Open Source paradigm in the Arabian World.

Comments and Discussions

QuestionAdd a Reference to MapWinGIS Components Pin
MemberSHOKH JAKHON KAYUMIY13-May-20 21:42 
QuestionGIS Application for mobile Pin
Member 1270228820-Mar-17 8:27
MemberMember 1270228820-Mar-17 8:27 
QuestionGIS Programming in silverlight Pin
mghafouri15-Aug-16 21:01
Membermghafouri15-Aug-16 21:01 
QuestionmapControl Pin
saethnono3-Apr-16 17:00
Membersaethnono3-Apr-16 17:00 
AnswerRe: mapControl Pin
Saeed pi16-May-18 6:36
professionalSaeed pi16-May-18 6:36 
GeneralRe: mapControl Pin
Member 148190731-May-20 4:56
MemberMember 148190731-May-20 4:56 
Questionregarding mapcontrols Pin
Member 1194520729-Aug-15 21:50
MemberMember 1194520729-Aug-15 21:50 
QuestionMapwinGis Pin
uma5b310-Sep-14 23:48
Memberuma5b310-Sep-14 23:48 
QuestionA Great Tutorial! Pin
Member 1104655330-Aug-14 12:10
MemberMember 1104655330-Aug-14 12:10 
AnswerRe: A Great Tutorial! Pin
MemberSHOKH JAKHON KAYUMIY13-May-20 21:45 
QuestionGreat tutorial! Pin
Ruchir927-Jan-14 7:46
MemberRuchir927-Jan-14 7:46 
QuestionAfter class Pin
TransformYa3-Jan-14 2:12
professionalTransformYa3-Jan-14 2:12 
GeneralMy vote of 1 Pin
Member 462289631-Oct-13 0:08
MemberMember 462289631-Oct-13 0:08 
QuestionThank You Pin
solalem17-Aug-13 0:57
Membersolalem17-Aug-13 0:57 
Questionhow to Geoproject and project raster image (WGS 84 only)in AxMap control while click a button Pin
leostalin9118-Oct-12 2:14
Memberleostalin9118-Oct-12 2:14 
QuestionCorrupted MapWinGIS dll Pin
nikhil sai11-Sep-12 0:22
Membernikhil sai11-Sep-12 0:22 
GeneralMy vote of 4 Pin
D-Kishore28-Aug-12 22:55
MemberD-Kishore28-Aug-12 22:55 
Questionhow to view lat/long of georefrenced tiff using mapwindow layer Pin
leostalin9120-Aug-12 3:52
Memberleostalin9120-Aug-12 3:52 
GeneralThank you Wisam E. Mohammed Pin
Ravi_Raturi11-Jun-12 7:02
MemberRavi_Raturi11-Jun-12 7:02 
Questionmapwingis Pin
golpesare.shirazi5-Apr-12 6:33
Membergolpesare.shirazi5-Apr-12 6:33 
QuestionA name space..... Pin
Annyclerk2-Jan-12 16:40
MemberAnnyclerk2-Jan-12 16:40 
Questionusing MapWindow 6 for making window mapping application Pin
meenakshi syal19-Oct-11 0:16
Membermeenakshi syal19-Oct-11 0:16 
GeneralProblem in VS 2010 Pin
Layinka17-Oct-11 4:26
professionalLayinka17-Oct-11 4:26 
Questionproblem to run the example Pin
Raul Rivero Monzon30-Sep-11 4:37
professionalRaul Rivero Monzon30-Sep-11 4:37 
AnswerRe: problem to run the example Pin
Layinka17-Oct-11 4:31
professionalLayinka17-Oct-11 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.