SharpMap

This post concludes our tutorial introducing SharpMap and how to use it in a mapping application. We were planning to explore it in some more depth by demonstrating some additional functionality, but we are working on another project that will be discussed in the near future. In short, SharpMap has tremendous potential as a lightweight component for adding mapping capabilities to desktop and web applications.

Our sample application’s source code is available to download below. It includes everything needed to compile and run the application using Visual C# Express. The SharpMap library, included in the download, is released under the GNU Lesser General Public License. For more information on that, see here.

Our third post in this series (part 1, part 2) on SharpMap continues the development of a basic mapping application programmed in C#. We will now add some more functionality to the program.

Zooming By Percentages

The SharpMap.Map class has a Zoom property that stores the map’s current width in the units of the map. To understand this better, add this line of code to the RefreshMap function we’ve already created:

Our previous post introduced SharpMap and how to use it in a C# program. We built a form and used a PictureBox control to display maps generated by SharpMap. We left off with a rather bland looking map of the world:

Adding Layer Styles

Adding colors to our countries layer is straightforward. In our form’s constructor, we simply define colors using the Style class:

In our ongoing effort to explore various methods for developing mapping applications, we need to consider incorporating existing libraries instead of writing code ourselves. One such solution is SharpMap. SharpMap is an emerging open source mapping engine that provides functionality to access GIS data, such as shapefiles, and generate map images. In their own words,

SharpMap is an easy-to-use mapping library for use in web and desktop applications. It provides access to many types of GIS data, enables spatial querying of that data, and renders beautiful maps. The engine is written in C# and based on the .Net 2.0 framework. SharpMap is released under GNU Lesser General Public License. [quote source]

So let’s go ahead and program a simple mapping application in C# that uses SharpMap. As with our other tutorials, this example is rather primitive on purpose to highlight specifically how easy it use to use SharpMap. Readers are encouraged to use this tutorial as a basis for creating much richer applications.