Conversion from OSGB36 to WGS84, read shapefile dynamically

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

Hi all,

Does SharpMap support the following funtions:

1) Conversion from OSGB36 to WGS84 dynamically

2) Read shapefile dynamically.

 

Coordinator
Nov 15, 2010 at 9: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 10:22 PM

@FObermaier,

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?

 

 

Coordinator
Nov 16, 2010 at 9:08 PM
Edited Nov 17, 2010 at 12:26 PM

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

var
csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
var
cs1 = csf.CreateFromWkt(OSGB36_wkt);
var
cs2 = csf.CreateFromWkt(WGS84_wkt);
var
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

Coordinator
Nov 16, 2010 at 11:07 PM
Edited Nov 17, 2010 at 12:27 PM

Addendum:

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 2: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?

 

Thanks!!

Coordinator
Nov 18, 2010 at 3:02 PM

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

Otherwise:

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