Convert EPSG: 4326 projection to EPSG: 3857 Mercator

I use sharpmap to render borders (geometry) from MSSQL as a PNG image. Everything works well, except that countries look too “wide” in flat format.

As I understand it, I need to create a conversion in EPSG: 3857, but I have no idea how to do this.

Here is my code

 var map = new Map(new Size(request.Width, request.Height));
 map.BackColor = Color.Transparent;
 var countryGeometry = GeometryFromWKT.Parse(dto.CountryWkt);

 IProvider countryProvider = new GeometryFeatureProvider(countryGeometry);
 var countryLayer = new VectorLayer("country", countryProvider);
 var borderColor = System.Drawing.ColorTranslator.FromHtml("#525252");

 countryLayer.Style.EnableOutline = true;
 countryLayer.Style.Outline = new Pen(borderColor);
 countryLayer.Style.Fill = Brushes.Transparent;
 //does not work with this
countryLayer.CoordinateTransformation = new
                ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory().CreateFromCoordinateSystems(
                    ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84,
                    ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator);

 map.Layers.Add(countryLayer);

 map.ZoomToBox(new Envelope(dto.Envelope.BottomLeft.Longitude,
            dto.Envelope.TopRight.Longitude,
            dto.Envelope.BottomLeft.Latitude,
            dto.Envelope.TopRight.Latitude
        ));

 var img = map.GetMap();

WKT can be found here https://pastebin.com/PEbpAdxT

Any help is appreciated.

EDIT: This is the image I get now for France, and this is the Limousin region. As you can see, it is too "wide." enter image description here

This image, when I apply the transformation, which can be found in the code comment does not work with this enter image description here

EDIT 2

I also tried following the conversion, but that makes an empty png (without a red cross)

 public  ICoordinateTransformation Wgs84toGoogleMercator
        {
            get
            {

                if (_wgs84ToGoogle == null)
                {
                    CoordinateSystemFactory csFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
                    CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

                    IGeographicCoordinateSystem wgs84 = csFac.CreateGeographicCoordinateSystem(
                      "WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich,
                      new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East));

                  // var a =  csFac.CreateFromWkt("aa");


                    List<ProjectionParameter> parameters = new List<ProjectionParameter>();
                    parameters.Add(new ProjectionParameter("semi_major", 6378137.0));
                    parameters.Add(new ProjectionParameter("semi_minor", 6378137.0));
                    parameters.Add(new ProjectionParameter("latitude_of_origin", 0.0));
                    parameters.Add(new ProjectionParameter("central_meridian", 0.0));
                    parameters.Add(new ProjectionParameter("scale_factor", 1.0));
                    parameters.Add(new ProjectionParameter("false_easting", 0.0));
                    parameters.Add(new ProjectionParameter("false_northing", 0.0));
                    IProjection projection = csFac.CreateProjection("Google Mercator", "mercator_1sp", parameters);

                    IProjectedCoordinateSystem epsg900913 = csFac.CreateProjectedCoordinateSystem(
                      "Google Mercator", wgs84, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East),
                      new AxisInfo("North", AxisOrientationEnum.North));

                    ((CoordinateSystem)epsg900913).DefaultEnvelope = new [] { -20037508.342789, -20037508.342789, 20037508.342789, 20037508.342789 };

                    _wgs84ToGoogle = ctFac.CreateFromCoordinateSystems(wgs84, epsg900913);
                }

                return _wgs84ToGoogle;

            }
        }
+4
1

CoordinateTransformation, , .

, ZoomToBox , . map.ZoomToExtents();, , :

France - not increased

, , , , .

France - increased

, ZoomToBox, . , .:)

+2

Source: https://habr.com/ru/post/1679600/


All Articles