I am rather a fan of GIS (Geographic Information Systems). I started off many years ago with ESRI’s ArcView® 3.x, then progressing to ArcGIS® 8.x / 9.x. Almost all of my projects I based on the extensions idea that makes ESRI’s GIS products so powerful. There are a number of applications for the E.O.D. (Explosives Ordnance Disposal) that I started off, such as the various modules of KMRPAS, a QS/Controlling application that can be used in the field for documentation of the ongoing work, and in the office for the bill of quantities and generating maps for the client. As the name implies, the prototype of KMRPAS had been coded with a PASCAL derivate: Delphi 5. The project was later converted to VB.NET, when the further development was commercialised.
Since then I had not been able to afford to keep up with the yearly updates necessary to stay in tune with ESRI’s new versions. If you are free-lance you just cannot pro-actively invest 2000 or so Euros in a software that might or might nor generate revenue.
So I was looking around for alternatives: I tried SharpMap, but I had the feeling that development somehow stalled a little when the originator of the project himself joined ESRI’s team. Also, SharpMap was (or is) more a framework that you use building your own application from scratch. What I did, though, use some of the extensive sources to gain more insight into spatial implementations.
Some time ago I purchased a book that elaborated on the use of open source products for desktop GIS (forgot the exact name, though). Amongst all the candidates from the pre-dominatly Linux world (QGIS, Grass) and their (much hated by me) C/C++ API’s, one mentioning caught my interest: MapWindow 4. This is a product that can be used in a variety of different scenarios: As a stand-alone desktop GIS, giving you a broad set of functions, both on raster and vector data, and, which can be extended by plug-ins, a lot of which are freely available on the web. Secondly, you can use MapWindow 4 as the basis for your own extensions, pretty much like the good old ArcGIS® stuff I wrote some years ago. By implementing a plugin interface by any language that is able to utilise ActiveX, you write your own application on top of MapWindow 4, and through some internal magic the plugin appears in the list of available plugins and can there be activated. Thirdly, you can use any COM-aware language to write your own application from scratch, embedding MapWindow 4 functionality by using the ActiveX control. This is a little more (or even more) work that the plugin/extension approach, but you end up with an application that looks truly yours.
Since MapWindow 4 is open source, it would also be possible to extend the source code itself and recompile your very own version of MapWindow 4. However, I consider this bad practise, as you potentially en up with a myriad of concurrent versions of the same product. Plus, Version 4 is based on C++ sources, counting me out for source code manipulation, anyway
.
With the advent of Version 6 of MapWindow the developer team has migrated to .NET as their development environment, utilising the C# language. Development is volatile and things get broken, re-assembled, re-broken etc., often. But I decided to base all my future development on this version. I my solution for my magnetic utilities I have added MapWindow 6 straight from the project’s SubVersion directory, keeping it current from within the IDE (I use SharpDevelop 3.1 for this now). There are a couple of tutorials on the web, however, they are a little hard to find and cover only a tiny proportion of what is already possible using MapWindow 6. There is also very little documentation as yet; understandable, though, as the team is obviously wanting to distribute a halfway stable version first, before indulging into the boring old word processing.
To build a first runnable application using the MapWindow 6 framework, create a new Windows forms application from within your favourite .NET IDE. As said before, I use SharpDevelop 3.1, mainly for the ability to make use of solution folders, which I extensively use. However, Visual Studio 2008 in its Express edition is also available at not cost, but doesn’t support solution folders (a minor flaw, I’d say…).
If you want to keep it simple, add the MapWindow6 assembly as a reference (MapWindow.dll in the /Releases/ folder). Also, import the available toolbox items, in order to build your application with drag and drop components. Again, to do that add the MapWindow.dll assembly to your tool box manager (Using SharpDevelop the procedure is a little different from VS2008). You will find that by the time of writing this 57(!) toolbox items are added. A lot of these seem to be items to aid the core development of MapWindow 6, but a two handfuls of components can well be used in your own application (off course, so can the others, but I suspect that they will eventually disappear from the publicly available components. So, I’d rather stay away from them).
At this point a word of criticism: Why on earth some of the Components have small letters at the beginning of their name remains completely non-obvious to me. They are not private, nor internal, but published on the toolbox. There are a number of other code formatting and naming issues, but then, maybe I am prejudice from my experience with ESRI-stuff, which has deeply influenced my own coding style (I still call classes that implement an interface XxxxClass / IXxxx. If they don’t, I don’t call them …Class. I also count up my interfaces, if I decide to extend my implementations. Examples: IPoint / IPointClass / IPoint2).
Let’s move on to creating our first MapWindow6 application. These are the steps:
1. Create a new Windows forms application and give it whatever name.
2. Add a menu strip to it and call it menuMain or whatever you like. You could implement a number of menu items and attached some event handling to it, such like providing and Exit function to leave the application.
3. Add a statusStrip. You could use the one provided by .NET, but the MapWindow6 team has implemented its own version of a statusStrip, called mwStatusStrip (see above!). This neatly fits into the other MapWindow components by providing a couple of automatic features for displaying Map and Legend statii.
4. Add a .NET ToolStripContainer to your form and make it dock in filled mode. You don’t actually need this, if you are not planning to be able to dock your toolbars in other locations than the design one.
5. Add the mwToolStrip component to your toolstrip container. This is a preconfigured tool strip adding basic functionality to your map without any implementation efforts on your side.
6. Now add a SplitContainer filling the rest of your form’s area automatically. Again, this is not a requirement, but if you like the MapWindow4 application’s layout, this is achieved best using the SplitContainer.
7. In the SplitContainer’s left area add a Legend from the MapWindow components. Make it dock in filled mode.
8. Do the same on the right, but this time adding a Map component.
9. Make sure that you go through the properties of each MapWindow6 component that you added to your form (i.e. mwStatusStrip, mwToolStrip, Legend and Map), and ensure that the mutual references are properly set. For example: the map component has a property called Legend. This should be set to your Legend component. The toolstrip will certainly give you an “object null reference” exception, if you do not correctly set its Map property. I fell over that to begin with and was looking for the reason for hours.
10. Build and run your Form. It should do this without errors and you get a basic MapWindow6 application to which you can add raster (bitmaps) and shapefiles already. Also, you can zoom, pan and select, without having written a line of code yourself.
I hope you had success following these suggestions and I have awoken your interest for GIS in general and MapWindow6 in particular. Once I mastered the mechanism to upload screen shots to my site, I shall certainly include some of those in the future.
Until then,
Stay out of mischief!.
Herman the German
Recent Comments