gpt4 book ai didi

c# - 转换 EPSG :4326 projection to EPSG:3857 mercator

转载 作者:行者123 更新时间:2023-11-30 12:08:56 25 4
gpt4 key购买 nike

我正在使用 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”地区获得的图像。如您所见,它太“宽”了。 enter image description here

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

编辑 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(); 函数,在缩放之前查看整个图像,它看起来像这样:

France - not zoomed

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

France - zoomed

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

关于c# - 转换 EPSG :4326 projection to EPSG:3857 mercator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44625176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com