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

Shape file not rendered when it uses a UTM projection

Topics: General Topics, SharpMap v0.9 / v1.x, WinForms Controls
May 12, 2010 at 5:15 PM

I'm using SharpMap 0.9 to display a map on a WinForm that allows users to load their own Shape files.  This works fine most of the time but we have found that if the Shape file uses a UTM projection then the file is not rendered on the map and no error is reported.

This is an example of a PRJ file where this problem occurs


This is the method that creates the transformation:
/// <summary>
/// Creates and returns a Mecator projection transformation that can be applied to a layer.
/// Needs to know the projection coordinate system of the source layer in order to create the
/// correction transformation.
/// </summary>
/// <param name="sourceCoordSystem">Source coordinate system.</param>
/// <returns>A Mecator projection transformation.</returns>
private ICoordinateTransformation TransformToMercator(ICoordinateSystem sourceCoordSystem)
CoordinateSystemFactory coordFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

List<ProjectionParameter> parameters = new List<ProjectionParameter>();
parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
parameters.Add(new ProjectionParameter("central_meridian", 0));
parameters.Add(new ProjectionParameter("false_easting", 0));
parameters.Add(new ProjectionParameter("false_northing", 0));
IProjection projection = coordFac.CreateProjection("Mercator", "Mercator_2SP", parameters);

IProjectedCoordinateSystem targetCoordSystem = coordFac.CreateProjectedCoordinateSystem("Mercator", GeographicCoordinateSystem.WGS84, projection, LinearUnit.Metre,
new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

return new CoordinateTransformationFactory().CreateFromCoordinateSystems(sourceCoordSystem, targetCoordSystem);
and this is the method that loads the Shape file and calls TransformToMercator:

public void LoadShapeFile(SharpMap.Map map, MapOverlaySettings overlaySettings)
	IpVectorLayer newLayer = new IpVectorLayer(overlaySettings.Name);
	ShapeFile shp = new ShapeFile(overlaySettings.Filename, true);

	// go ahead with rendering of shape file - set style properties for the layer (default is black filled, no outlining)
	SharpMap.Styles.VectorStyle layerStyle = new SharpMap.Styles.VectorStyle();
	layerStyle.EnableOutline = true;
	layerStyle.Outline.Color = overlaySettings.Colour;
	newLayer.Style = layerStyle;
	newLayer.Enabled = overlaySettings.Visible;
	newLayer.DataSource = shp;
	newLayer.Filled = overlaySettings.Fill;

	// Use Mector projection - if the SHP file has an associated projection file [*.PRJ] then SharpMap 
	// will read and use this projection - so check to ensure we know what we are transforming from.
	// If no projection specified degault to SharpMap's default (equirectangular).
	newLayer.CoordinateTransformation = shp.CoordinateSystem == null ? TransformToMercator(GeographicCoordinateSystem.WGS84) : TransformToMercator(shp.CoordinateSystem);


I've tried stepping through the code but as a non-GIS person I'm having difficulty understanding what should be happening.  I've found that when Sharp files are rendered they take the Projected -> Geographic path through CoordinateTransformationFactory.CreateFromCoordinateSystems, whereas the problem arises when the Projected -> Projected route is taken.  In this later case it is the ConcatenatedTransform class that is used for the TransformList method and when this is used I'm always getting an empty polygon returned by GeometryTransform.TransformPolygon (whereas when MapProjection.TransformList is used TransformPolygon returns a populated polygon).

Thanks in advance, Alastair



Jul 20, 2010 at 8:17 AM



Jul 20, 2010 at 8:41 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.