This project has moved and is read-only. For the latest updates, please go here.

Getting started with SharpMap disappointed me

Topics: Algorithms, Data Access, General Topics, SharpMap Project, WinForms Controls
May 7, 2008 at 5:57 PM
I am a newbie here and I was fascinated hearing about GIS source like this. I downloaded the demo win form and checked what SharpMap has for me. I was disappointed that the map box did not show any thing and many controls in the win form did not respond at all (except just that it gets depressed for the click!!!) On of the keys added layers in the left checkedlist but I did not see any thing on the map box on the right panel. It was just blank.

I then decided to figure out myself and downloaded the win form client source code with SharpMap and SharpMap.UI projects. Since I use VS Express edition latest, I had to convert the source code to latest (which is done by express edition itself on agreeing upon a prompted dialog box). But I was disappointed to see that the Form Design (actual window form where you drag controls in from toobox) did not show up spitting some error. But the code did open. I could not compile the code due to the aforesaid windows problem showing up from the design of the winform.

I then walked through the code of the win form client to check what has been done and tried doing that myself in a fresh project. Initially the main function that loads the map is LoadWms() but when I had the same in my source code, everything went fine (with LoadWms loading the layer objects in the checked list properly) but still nothing was showing up in the map box. As per my understanding initially this is the function that is supposed to be loading the map. It is not throwing any error and it does able to communicate with the server, else it would not have been able to populate the checkedlist (I was also able to get other information from server).

I was very much impressed at first sight but now my expectations are going down because of such issues. Please help me on what could be the problem. Also let me know if we have a good "GEtting started" guide/tutorial to start with. The help file coming with this API is simply a junk for a newbie. It has all information but no starting point or ending point! Please help me guys.

Thanks in advance
Parthiban Rajendran
May 7, 2008 at 10:02 PM
Hi Parthiban -

I agree: the onramp to SharpMap is too steep and filled with potholes and lacks a guardrail.

There is a work item (Tutorial for beginners) to improve this area, but no one has gotten around to it. We're all to busy just getting SharpMap to run for what we need it to do. That we share it is not a guarantee that anyone else will find it useful... it's the same story with any open source.

SharpMap is a relatively immature project, given it's complexity. Most of the people who get productive with it are early adopters, and probably already have some GIS experience or have a lot of time to invest in getting it working. I expect this to change as the project matures.

An upshot is that these forums are usually quite helpful. There are a number of people who can answer questions here, and often do.

After SharpMap v2.0 reaches a stable point, you should see more effort in getting the on-ramp smoother. Again, I'm sorry that you had an unpleasant experience.
May 9, 2008 at 5:56 PM
Hi codekaizen
Thank you very much for the support. I am new to this open source world too, as a developer and believe as I grow my knowledge, I shall come with basic tutorials for beginners like me.

Regarding the problem, I removed the source codes of SharpMap and SharpMap.UI and just added the binaries downloaded, thus compiling only my project (against the way I was compiling before, my project, sharpmap and its UI project). This seems to work well. It was just very late to establish communication with server. But I am atleast able to display a decent map with some layers, zoom in or out, pan etc. sigh.. :)
Then I started trying shapefiles. I downloaded India's shape file and managed to make my project use it with vector layer instead of WMS layer before which got the map from server. This shape file, since its local, is very fast. I am now able to display the shape file, zoom in or out and pan it. I now want to do the following.

1. I want to programmatically extract polygons of the shape file and colour them
2. I want to specify the coordiantes of a place (a point) in India, and colour the nearest enclosing polygon of the point (if districts are the smallest divisions of a country, then the district enclosing the point specified would be the nearest enclosing polygon and thus I want to colour that one).

To accomplish the first one, I tried the following code but getting "Invalid attributes error":

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MapTrial2
public partial class Form1 : Form
SharpMap.Map myMap;
SharpMap.Layers.VectorLayer myLayer;
SharpMap.Data.Providers.ShapeFile myShapeFile;

public Form1()
public void MyInitialization()
myMap = new SharpMap.Map(mapImage1.Size);
myLayer = new SharpMap.Layers.VectorLayer("My India Layer");
public SharpMap.Layers.VectorLayer LoadPopulation(SharpMap.Layers.VectorLayer myVectorLayer)
SharpMap.Styles.VectorStyle minimum = new SharpMap.Styles.VectorStyle();
SharpMap.Styles.VectorStyle maximum = new SharpMap.Styles.VectorStyle();
minimum.Fill = Brushes.White;
maximum.Fill = Brushes.Red;
minimum.Outline = new Pen(Color.Black, 1);
maximum.Outline = new Pen(Color.Yellow, 5);
minimum.EnableOutline = true;
maximum.EnableOutline = false;

SharpMap.Rendering.Thematics.GradientTheme popdens = new SharpMap.Rendering.Thematics.GradientTheme("PopDens", 0, 400, minimum, maximum);
myVectorLayer.Theme = popdens;

return myVectorLayer;


private void button1_Click(object sender, EventArgs e)
buttonStart.Enabled = false;

//Create shape map layer and add it to map box
myShapeFile = new SharpMap.Data.Providers.ShapeFile(@"D:\MyProjects\VisualStudio\For Real Estate database\MapTrial2\MapTrial2\india\india_ds.shp");
myLayer.DataSource = myShapeFile;
myLayer.Style.Outline = new Pen(Color.White, 1f);
myLayer.Style.EnableOutline = true;
label1.Text = "Shape Type of this file: " + myShapeFile.ShapeType;

//Load the custom theme..

myLayer = LoadPopulation(myLayer);


mapImage1.Map = myMap;

buttonStart.Enabled = true;
private void buttonZoomIn_Click(object sender, EventArgs e)
mapImage1.ActiveTool = SharpMap.Forms.MapImage.Tools.ZoomIn;
private void buttonZoomOut_Click(object sender, EventArgs e)
mapImage1.ActiveTool = SharpMap.Forms.MapImage.Tools.ZoomOut;
private void buttonPan_Click(object sender, EventArgs e)
mapImage1.ActiveTool = SharpMap.Forms.MapImage.Tools.Pan;
private void buttonZoomToExtent_Click(object sender, EventArgs e)


The problem seems to be that I dont have the proper featuredatarow filled to help the thematics function perform its job. I am pretty new to C# and datasets are nearly greek and latin for me. Please help me to accomplish the 2 tasks specified above. Even after hours of searching, I could not find useful material to help me on that.

Parthiban R