首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将EPSG:4326投影转换为EPSG:3857 mercator

将EPSG:4326投影转换为EPSG:3857 mercator
EN

Stack Overflow用户
提问于 2017-06-19 08:02:31
回答 1查看 2.7K关注 0票数 4

我使用锐利地图从MSSQL渲染边框(几何图形)作为PNG图像。除了一些国家在平面图像格式上看上去太“宽”外,一切都很好。

据我所知,我需要创建到EPSG:3857投影的转换,但我不知道如何实现。

这是我的密码

代码语言:javascript
复制
 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();

我们可以在这里找到https://pastebin.com/PEbpAdxT

任何帮助都是非常感谢的。

编辑:这是我现在得到的法国和它的地区"Limousin“的图像。如你所见,它太“宽”了。

这是我应用转换时的图像,可以在代码注释does not work with this下面找到

编辑2

我也尝试过进行转换,但这会呈现空白的png (没有红十字会)。

代码语言:javascript
复制
 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;

            }
        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-21 15:00:09

您使用的CoordinateTransformation实际上是有效的。

因为您的ZoomToBox坐标是错误的,所以您得到的是空白图像,因此它实际上显示了图像的空白部分。如果您使用map.ZoomToExtents();函数,在缩放之前查看整个图像,它如下所示:

现在,如果我手动放大浏览器以获得应用此转换的法国特写图像,您可以看到它实际上已经不再拉伸了。

总之,我要说的是,您只需要修复ZoomToBox坐标,一切都会正常工作。希望能帮上忙。:)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44625176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档