Search This Blog

Tuesday, September 6, 2011

DotSpatial

So I’m checking out DotSpatial for use in a project.. and the first thing on my list is to check it can convert coordinate systems easily from WGS84 <> OSGB36.

Seems the current version’s inbuilt definition of OSGB36 isn’t correct.. and when using it with the Reproject method gives out some strange results. It’s also listed as failing the unit test currently.

However you can specify the details yourself.. and then it seems to work just fine… so here’s the code for taking a coordinate as OSGB36 and transforming it to WGS84…

PointD pd = new PointD();
pd.X = 326097.07;
pd.Y = 673630.932;

double [] pts_xy = new double[2];
pts_xy[0] = pd.X;
pts_xy[1] = pd.Y;

double [] pts_z = new double[1];
pts_z[0] = 0;

var pStart = new ProjectionInfo("+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 +units=m +no_defs");
var pEnd = KnownCoordinateSystems.Geographic.World.WGS1984;
 
Reproject.ReprojectPoints(pts_xy, pts_z, pStart, pEnd, 0, 1);
System.Console.WriteLine(pts_xy[0] + " " + pts_xy[1]);

No comments: