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

Can't display a map

Topics: SharpMap v2.0, WinForms Controls
Oct 26, 2007 at 9:50 AM
I don't know how to display a map using windows forms. The next code is doesn't work:

using ...

namespace TestMapV2
public class Form2 : Form
private SharpMap.Presentation.WinForms.MapViewControl mapCtrl;

public Form2()
private void InitializeComponent()

private IEnumerable<Geometry> RandomGeometries
Geometry g = null;
Random rnd = new Random();
for (int i = 0; i < 4; i++)
g = new Point(rnd.Next(300), rnd.Next(300));
yield return g;

private void InitMap()
SharpMap.Map map = new SharpMap.Map();
mapCtrl.Map = map;
GeometryProvider provider = new GeometryProvider(RandomGeometries);
GeometryLayer layer = new GeometryLayer("RandomGeometries", provider);

mapCtrl.ZoomToExtents(); //sometimes(!) thrown System.NotSupportedException exception!

That is wrong in this example?
Oct 28, 2007 at 1:34 AM
I tried exactly the same example. It looks like it is not finished yet in v2.

It looks like the reason of an error is in GeometryProvider - it does not implement CreateNewTable() yet. "public IList<Geometry> Geometries" is simply not used. And CreateNewTable() is empty, probably it should return exception:

public FeatureDataTable CreateNewTable()
return new NotImplementedException("");

Currently it seems to be impossible to create some lightweight Geometry collection class because everything should go into DataTable in IFeatureLayer. And there is no way to bypass it. It is design feature.

Maybe there should be a way to get only Geometries of features in IFeatureLayer so that they can be directly rendered using BasicGeometryLayer. In this case Geometry layer will not need to implement Features property.

However it is hard to say since new design is still unclear for me. Class diagram of a new design with some short explanations will be very usefull. Something like VS2005 class diagram with notes explaining interfaces / classes.

I also tried to compile last sources from Google using VS2005 with DemoWinForm included and it looks like some references and vs2005 solution are broken.

See a very small patch for VS 2005, fixing a few references, adding your example to SharpMap.Presentation.WinForms.Tests as a unit test

Small suggestion about source code, it will be good to write a message somewhere on Source Code page telling people that recent sources are on and that CodePlex sources are not used. Or delete CodePlex sources and put link to Google Code there. I probably not the fist who tried to download and compile v2 sources from CodePlex :)