【问题标题】:Converting EPSG:4326 projection to EPSG:3857 mercator将 EPSG:4326 投影转换为 EPSG:3857 墨卡托
【发布时间】:2017-06-19 08:02:31
【问题描述】:

我正在使用sharpmap 将MSSQL 中的边框(几何)渲染为PNG 图像。 一切都很好,除了国家/地区在平面图像格式上看起来太“宽”。

据我了解,我需要创建到 EPSG:3857 投影的转换,但我不知道该怎么做。

这是我的代码

 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 可以在这里找到https://pastebin.com/PEbpAdxT

感谢任何帮助。

编辑: 这是我现在为法国获得的图像,它是“豪华轿车”地区。如您所见,它太“宽”了。

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

编辑 2

我也尝试过以下转换,但这会呈现空白 png(没有红色叉号)

 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;

            }
        }

【问题讨论】:

  • 嗨罗伯特。从长远来看,临时笔记(例如赏金等)在帖子中并不是真正有用,因此它们在 cmets 中更好。我们的经验是,即使它们已经过时或过期,它们通常也会被留下。除了紧急请求外,我不会注意到,这里不鼓励这样做。
  • 作者提供+100 来回复这篇文章。
  • 请阅读Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - 总结是这不是解决志愿者的理想方式,并且可能会适得其反。请不要将此添加到您的问题中。
  • @halfer 谢谢。我会记住这一点的。
  • 您确定您的源数据在 EPSG:4326 中吗?例如,不在法国国家预测中?

标签: c# .net gis geospatial sharpmap


【解决方案1】:

你使用的CoordinateTransformation确实有效。

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

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

作为结论,我想说您只需要修复您的ZoomToBox 坐标,一切都会正常工作。希望能帮助到你。 :)

【讨论】:

  • 我也试过了,但我的是空白的。我还尝试将信封转换为缩放。您是否使用了我发布的相同 WKT?
  • @Robert 是的,这是我唯一的一个。
  • 这很奇怪。你能把你的代码放到 GitHub 上吗,也许我的一些依赖关系搞砸了?
  • 由于某种原因,我无法编译您的项目。 Nuget 不会提取与Sharpmap 相关的任何内容。
  • 最后。事实证明我的代码没问题,但是因为我从他们的 git 构建了 sharpmap,所以当我想手动添加 DLL 时,我弄乱了引用。解决方案是将代码移动到新项目,手动安装Sharpmap依赖项,然后在网站中引用该项目。
猜你喜欢
  • 2017-07-12
  • 2011-11-26
  • 2019-07-03
  • 2022-01-08
  • 2016-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-28
相关资源
最近更新 更多