ThinkGeo.com    |     Documentation    |     Premium Support

Mercator Projection

I’m having some issues setting projections still.

All my data (shapefiles) come in WGS84 unprojected, with units in decimal degrees. I want to project all of these to standard mercator projection, which is -180 to +180 degrees left to right.

I THINK this is what I want: http://spatialreference.org/ref/epsg/wgs-84-world-mercator. I set it up like this:

Map.MapUnit = GeographyUnit.DecimalDegree;

ShapeFileFeatureLayer.BuildIndexFile(mainShapeFilePath, BuildIndexMode.DoNotRebuild);
ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(mainShapeFilePath);

Proj4Projection proj4Projection = new Proj4Projection();
proj4Projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(3395);
worldLayer.FeatureSource.Projection = proj4Projection;

However, the shapefile does not display correctly. What am I doing wrong?

Hi Dan,

I guess you forget set the correct current extent for your shape.

You should want to call worldLayer.Open() and GetBoudingBox() to set it to current extent.

Regards,

Ethan

Hi thanks for the reply. I was doing that actually, it still didn’t work.

string mainShapeFilePath = @"../../AppData/Merge_Countries.shp";
Map.MapUnit = GeographyUnit.DecimalDegree;

ShapeFileFeatureLayer.BuildIndexFile(mainShapeFilePath, BuildIndexMode.DoNotRebuild);
ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(mainShapeFilePath);

Proj4Projection proj4Projection = new Proj4Projection();
proj4Projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(3395);
worldLayer.FeatureSource.Projection = proj4Projection;

AreaStyle areaStyle = new AreaStyle();
areaStyle.FillSolidBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 233, 232, 214));
areaStyle.OutlinePen = new GeoPen(GeoColor.FromArgb(255, 118, 138, 69), 1);
areaStyle.OutlinePen.DashStyle = LineDashStyle.Solid;
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = areaStyle;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
worldLayer.Name = "World Layer";

Map.Overlays.Add("World Overlay", worldOverlay);

worldLayer.Open();
Map.CurrentExtent = worldLayer.GetBoundingBox();
Map.RestrictedExtent = Map.CurrentExtent;
worldLayer.Close();

Map.Refresh();

Above is the full code.
Below is the shapefile I’m testing.

testShapefile.zip (2.5 MB)

Hi Dan,

The “EPSG:3395” map unit is Meter, so you need to change the MapUnit to Meter as following statements:

winformsMap1.MapUnit = GeographyUnit.Meter;

Then it should display correctly.

Thanks
Mark

Looks like it should work. I didn’t think changing the map units to meters would fix it but I forgot it’s taking the internal string and projecting it to the new projection, so it shouldn’t matter in the end.

Thank you very much!

Hi Dan,

I am glad to hear that’s helpful.

Regards,

Ethan