Conversion from OSGB36 to WGS84, read shapefile dynamically

Topics: SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0
Nov 12, 2010 at 4:22 PM

Hi all,

Does SharpMap support the following funtions:

1) Conversion from OSGB36 to WGS84 dynamically

2) Read shapefile dynamically.


Nov 15, 2010 at 8:05 AM

Hello kingofwebguru,

1.) it does, but using Proj.Net you might have to customize your WKT to make it work properly.

2.) yes.

Hth FObermaier

Nov 15, 2010 at 9:22 PM


Could you provide sample code to do the following:

1) read from shapefile

2) convert OSGB36 to WGS84


Is SharpMap v2 the better one to use?



Nov 16, 2010 at 8:08 PM
Edited Nov 17, 2010 at 11:26 AM

hello kingofwebguru,

Reading a ShapeFile is not the problem that is pretty straight forward:

//SetUp Map object
var map = new SharpMap.Map(new System.Drawing.Size(400, 300));
//Create ShapeFile provider var sfp = new SharpMap.Data.Providers.ShapeFile( filename, true );
//Create a geometry layer
var gl = new SharpMap.Layers.VectorLayer("shapefile", sfp);
//SetUp coordinate transformation

csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
cs1 = csf.CreateFromWkt(OSGB36_wkt);
cs2 = csf.CreateFromWkt(WGS84_wkt);
ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransfromationFactory();
gl.CoordinateTransformation = ctf.CreateFromCoordinateSystems( cs1, cs2 );
//Add layer to map
map.Layers.Add(gl); //Get the map as Bitmap map.ZoomToExtents(); var bmp = map.GetMap()

I'm in the process of replacing that with DotSpatial.Projections, which might do better with these kinds of CoordinateSystems.

Since on-the-fly reprojection of vector data is an expensive task, the default question is can you avoid that by transforming beforehand with e.g. ogr2ogr / qgis?

The above applies to SharpMap v2 as well, the advantage of SharpMap v2 is that it has build in Topology support via NetTopologySuite and updateable DataProviders.

Hth FObermaier

Nov 16, 2010 at 10:07 PM
Edited Nov 17, 2010 at 11:27 AM


you might want to grab the latest code, set configuration to DebugDSProjection and replace the CoordinateTransformation setup code with

//SetUp Coordinate transformation
var piS = new DotSpatial.Projection.ProjectionInfo( <proj4 for osgb36> );
var piT = new DotSpatial.Projection.ProjectionInfo( <proj4 for wgs84> );
var ct = new DotSpatial.Projection.CoordinateTransformation
             { Source = piS, Target = piT };
gl.CoordinateTransformation = ct;

Hth FObermaier



Nov 18, 2010 at 1:56 PM
FObermaier wrote:
//Create ShapeFile provider
var sfp = new SharpMap.Data.Providers.ShapeFile( filename, true );


How do you read the contens of a shapefile after the shapefile handle is created?



Nov 18, 2010 at 2:02 PM

If you want to do mapping, you can look at the various samples in the WinFormSamples project


var sfp = new SharpMap.Data.ShapeFile( filename, false );
var fds = sfp.ExecuteIntersectionQuery( sfp.GetExtents() );
var fdt = fds.Tables[0];
foreach (var fdr in fdt.Rows)

Hth FObermaier