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

Simple WinForm Example

Topics: SharpMap Project, WinForms Controls
Apr 29, 2009 at 10:13 AM
I am just starting with Sharpmap, looks like a great fit for my current project.
I have a set of three dimensional points about 1000 points in the form of: (Long, Lat, Height) (-100, 40, 1000)(100°W,40°N,1000 feet).
I want to produce a "topographic map".  This can be contours, or tiled with gradient colored rectangles for each "point".

My problem is I am having a very steep learning curve for Sharpmap.  Most of the examples are NA because they are far more complex than what I'm trying to do, various web GIS servers, SQl Server etc. 

Could someone point me to a simple VB or C# end to end sample and/or walkthrough that might be of some help?

I'm sure if I can get a sample up and running, I can make modificatons to accomplish the end result I want.

I had great hopes for the Code: DemoWinForm, but it only provides the executables --- so :( not what I need.

I'm working with VS 2008 (VB) primarily, but can certainaly 'translate' C#.

Thanks in advance,

Ed Warren.
Apr 29, 2009 at 2:56 PM
I am in exactly the same situation. I am very enthusiastic about this project and believe that it completely meets my needs however it's a little too much for me to consume and I would greatly appreciate something a bit simpler. I am different than Ed in that I am working primarily with C# though VB is fine.
Apr 30, 2009 at 11:48 AM


I have gotten to this point still not working but closer.

Final issue has to do with how to connect up the Label layer's LabelCol property to the list of 3d points?? then how to display the labels.

Comments on a better approach would be appreciated.


Ed Warren


Note: PontList is List of type {-100,40,1200}, {-100.1,40.1,1100}, .... etc.
I'm trying to plot a point x,y (with z coordinate as the label). , or x,y with z as a colored rectangle, colored to match the value.

Sub setupMap(ByVal drLong As Single, ByVal drlat As Single, ByVal drSounding As Single, ByVal pointlist As List(Of BathymetricSounding))



Dim MapCenter As New SharpMap.Geometries.Point3D



Dim MapBath As New SharpMap.Layers.VectorLayer("Bathmetric")



Dim myMapPoints As New List(Of SharpMap.Geometries.Geometry)



For Each y In pointlist



New SharpMap.Geometries.Point3D(y.Latitude, y.Longitude, y.strDepth(strUnits)))






Dim myGeoProvider = New SharpMap.Data.Providers.GeometryProvider(myMapPoints)



Dim myMapLayer As New SharpMap.Layers.LabelLayer("Soundings")



myMapLayer.DataSource = myGeoProvider


MapCenter.X = drLong

MapCenter.Y = drlat

MapCenter.Z = drSounding


Me.MapImage1.Map.Center = MapCenter






Me.MapImage1.Map.BackColor = Color.BlanchedAlmond






Me.MapImage1.Refresh()  'fails with error: Attribute data is not supported by the GeometryProvider.'

End Sub


Apr 30, 2009 at 12:01 PM
Hi Ed, Rather than using the LabelColumn property you can use the LabelLayer.LabelStringDelegate to supply a method which takes in the FeatureDataRow for each record.
In this method you can then investigate the rows' Geometry property and in turn go through the ordinates of said geometry returning whatever you like.
If you want to colour the rectangle as well you can set a CustomTheme on the vector layer. CustomTheme takes a delegate as above and you can use it to return the appropriate VectorStyle 
hth jd
Apr 30, 2009 at 1:21 PM
Thanks, I will give it a try.  Right now I'm having problems finding my way to the "FeatureDataRow" with the current design (List(Of SharpMap.Geometries.Geometry) ).  I'm thinking I will need to build a  datatable, datacolumns, and datarows, then access it that way.   Will keep you posted, still impressed with this software -- "Wow".


Ed Warren.
Apr 30, 2009 at 1:26 PM
Edited Apr 30, 2009 at 1:56 PM
Hi Ed,
if you want to use labeling and use an in-memory provider, you will need to use GeometryFeatureProvider instead of GeometryProvider, otherwise you will get the "Attribute data is not supported by the GeometryProvider" exception. Otherwise you have the posibility to use any of the other file or db based providers.
Apr 30, 2009 at 2:06 PM
Hi Ed, see for an example of creating and populating a FeatureDataTable hth jd
May 1, 2009 at 3:03 PM
Thanks to all that have responded, I think you have me on a path to success.

I will work on it and get back if I have other questions,  again thanks.

To any other responders, I'm gone until June 1st and will not be able respond until after then.


Ed Warren.