Transformations (Projection 2 Projection) HELP!

Aug 29, 2007 at 5:13 PM
Edited Aug 29, 2007 at 5:21 PM
I have read SharpGIS's blog posts on adding a shape file to a Virtual Earth map and I am having some trouble with my transformations. I've found these previous discussions that have similar, if not identical, problems.

Cannot Convert Coordinatesystem from Transverse Mercator To Mercator;
URGENT: Projection problem;
Problem with Traverse_Mercator;

The issue as far as I can tell is that SharpMap can't do projection to projection transformations on its own. If I send a projection coordinate system into the Transform2Mercator function I get the "Geographic coordinate system was null" error when it tries to use the projection as a geographic coordinate system.

I changed the code to leave it as a projection coordinate system and SharpMap blows up on map.GetMap() presumeably because Projection 2 Projection is not implemented.

Just as with one of the previous discussions on this issue my shape file's .prj file begins with PROJCS instead of GEOCS. Which is why I start with a projection coordinate system.

PLEASE: I am at a loss. How can I get it into the correct transformation? I have gotten the shape file to draw in Virtual Earth by not transforming it at all and it draws in Africa instead of Alabama.

Here is the .prj


and my code:

public static SharpMap.Map CreateMap(System.Drawing.Size size)
//Initialize a new map of size 'imagesize'
SharpMap.Map map = new SharpMap.Map(size);
//Set up the countries layer
SharpMap.Layers.VectorLayer layCounties = new SharpMap.Layers.VectorLayer("Counties");
SharpMap.Data.Providers.ShapeFile shpCounties = new SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~\Appdata\GISCounty.shp"), true);
layCounties.DataSource = shpCounties;

layCounties.CoordinateTransformation = Transform2Mercator(shpCounties.CoordinateSystem);
layCounties.Style.Fill = new SolidBrush(Color.Green);
layCounties.Style.Outline = System.Drawing.Pens.Black;
layCounties.Style.EnableOutline = true;

map.BackColor = Color.Beige;
HttpContext.Current.Trace.Write("Map initialized");
return map;

public static ICoordinateTransformation Transform2Mercator(ICoordinateSystem source)
CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

System.Collections.Generic.List<ProjectionParameter> parameters = new System.Collections.Generic.List<ProjectionParameter>(5);
parameters.Add(new ProjectionParameter("latitudeoforigin", 0));
parameters.Add(new ProjectionParameter("central_meridian", 0));
parameters.Add(new ProjectionParameter("false_easting", 0));
parameters.Add(new ProjectionParameter("false_northing", 0));
IProjection projection = cFac.CreateProjection("Mercator", "Mercator_2SP", parameters);

IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Mercator", source as IGeographicCoordinateSystem, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

return new CoordinateTransformationFactory().CreateFromCoordinateSystems(source, coordsys);
Aug 31, 2007 at 6:28 AM
Edited Aug 31, 2007 at 6:30 AM
The problem is the piece of code that creates the projected CS. In this sample code it just create a mercator projection with the same geographic CS as the from coordinate system, which is expected to be geographic in this case.
You should replace 'source as IGeographicCoordinateSystem' with the geographic CS that you want to be used in the mercator projection (with Virtual Earth you will want to use the spheric wgs84-based geo cs). Just be aware that both your from and to-CS should specify a TOWGS84 parameter if it uses a different datum than WGS84 unless they both use the same datum.
Alternatively the whole set of code for creating the Mercator can be done by using the WKT parser and put in the WKT text you found on sharpgis' webpage you are referring to, and then you just need the last line of code for creating the transform.