c# – 转换EPSG:4326投影到EPSG:3857 mercator
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 转换EPSG:4326投影到EPSG:3857 mercator,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3415字,纯文字阅读大概需要5分钟。
内容图文
![c# – 转换EPSG:4326投影到EPSG:3857 mercator](/upload/InfoBanner/zyjiaocheng/781/6432e2cd69034d79b6835863b66efbb9.jpg)
我使用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
任何帮助表示赞赏.
编辑:
这是我现在为法国和它的区域“Limousin”得到的图像.正如你所看到的,它太“宽”了.
这是我应用转换时的图像,可以在代码注释下找到它不适用于此
编辑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;
}
}
解决方法:
您使用的CoordinateTransformation实际上有效.
由于ZoomToBox坐标错误,您将获得空白图像,因此它实际上显示了图像的空白部分.如果你使用map.ZoomToExtents();相反,要在缩放之前查看整个图像,它看起来像这样:
现在,如果我在浏览器中手动缩放以获得应用此转换的法国特写图像,您可以看到它实际上不再被拉伸.
作为结论,我要说你只需要修复你的ZoomToBox坐标,一切都会正常工作.希望能帮助到你.
内容总结
以上是互联网集市为您收集整理的c# – 转换EPSG:4326投影到EPSG:3857 mercator全部内容,希望文章能够帮你解决c# – 转换EPSG:4326投影到EPSG:3857 mercator所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。