【发布时间】:2019-03-21 00:58:57
【问题描述】:
如何使用从 prj 文件读取源坐标系统的 ProjNet4GeoAPI 创建与 MapSui.Projections.ITransformation 接口兼容的新转换类。
从 Mapsui 源代码中,有一个 MinimalTransformation 实现了 ITransformation 接口,用于在 SphericalMercator 和 WGS84 之间进行转换。
From Mapsui documentation: 开箱即用的 Mapsui 对投影的支持是有限的。 MinimalProjection 类仅在 SphericalMercator (EPSG:3857) 和 WGS84 (EPSG:4326) 之间投影。但是,可以创建自己的转换。您需要实现 ITransformation 接口。在此实现中,您需要使用其他一些投影库。推荐一个是ProjNet4GeoAPI。
我可以使用 ProjNet4GeoAPI 创建一个工作转换类,但它实现 GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation 而不是 Mapsui.Projection.ITransformation
// (FROM SOURCE) prj name: NAD_1983_StatePlane_Massachusetts_Mainland_FIPS_2001"
ICoordinateSystemFactory csFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
string file = @"C:\DRC_Data\Arcview\USA\Townships\NYTOWNS_POLY.prj";
string wkt= System.IO.File.ReadAllText(file);
var csFrom = csFac.CreateFromWkt(wkt);
//(TO) Prj name: "WGS 84 / Pseudo-Mercator"
file = @"C:\DRC_Data\Arcview\3857.prj";
wkt = System.IO.File.ReadAllText(file);
ICoordinateSystem csTo = csFac.CreateFromWkt(wkt);
//Step 2) Create transformation class.
CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
//To 3857
//var is ICoordinateTransformation
ICoordinateTransformation ct = ctFac.CreateFromCoordinateSystems(csFrom, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator);
如何在 Mapsui 中使用 ICoordinateTransformation 类? 我是否在 Mapsui.Projection 中创建像 SphericalMercator 这样的投影类 (见下面的代码)?
来自 Mapsui.Projection:
public class MinimalTransformation : ITransformation
{
private readonly IDictionary<string, Func<double, double, Point>> _toLonLat = new Dictionary<string, Func<double, double, Point>>();
private readonly IDictionary<string, Func<double, double, Point>> _fromLonLat = new Dictionary<string, Func<double, double, Point>>();
public MinimalTransformation()
{
_toLonLat["EPSG:4326"] = (x, y) => new Point(x, y);
_fromLonLat["EPSG:4326"] = (x, y) => new Point(x, y);
_toLonLat["EPSG:3857"] = SphericalMercato.ToLonLat;
_fromLonLat["EPSG:3857"] = SphericalMercator.FromLonLat;
}
源码:https://github.com/garykindel/ShapefileProjectionDemo 使用 Mapsui 2.0.0-beta.22 nuget 包,我从 master 手动构建 Mapsui.desktop.dll。
【问题讨论】:
-
如果您使用投影代码和示例创建一个 github 项目,我可以帮助您实现这一点。它可以作为 Mapsui 样本
-
将代码添加到带有 shapefile 的测试 wpf 应用项目中。我希望得到实施方面的帮助,我很乐意在 Mapsui github.com/garykindel/ShapefileProjectionDemo 的示例代码中分享答案
-
谢谢!我克隆了它并提交了一个问题。
标签: coordinate-systems geoapi mapsui