ArcGIS Runtime:如何将点的单位从度转换为米

问题描述

我有两个具有相同坐标系(Wgs84)的几何,但是它们的数据单位不同,一个是度,另一个是米。 我需要对它们执行一些操作,例如:

var g1 = GeometryEngine.Difference(geometry1,geometry2);

但是我得到一个错误:

System.ArgumentException:'Invalid argument: geometry1 and geometry2 must have equivalent spatial references.'

所以我想将以度为单位的数据转换为以米为单位的数据,我不知道该怎么做。

以米为单位的数据来自shp文件。此shp文件已加载到SceneView。

以度为单位的数据来自SceneView的PreviewMouseLeftButtonDown事件:

// Get the mouse position.
Point cursorSceenPoint = mouseEventArgs.GetPosition(MySceneView);

// Get the corresponding MapPoint.
MapPoint onMapLocation = MySceneView.ScreenToBaseSurface(cursorSceenPoint);

然后我考虑了是否可以通过设置SceneView.SpatialReference.Unit来修改单位,但是它是只读的。

.NET解决方案是最好的,其他语言也可以接受。

解决方法

var point1 = ...;
var point2= GeometryEngine.Project(point1,YourNewSpatialReference) as MapPoint;
public static Geometry? Project(Geometry geometry,SpatialReference outputSpatialReference);
public static Geometry? Project(Geometry geometry,SpatialReference outputSpatialReference,DatumTransformation? datumTransformation);
,

大多数几何引擎操作要求所有几何都在同一空间参考中。正如错误所指出的,事实并非如此。在执行任何几何引擎操作之前,可以使用以下代码将geometry2移到与几何1的空间参考匹配的位置(或反之亦然):

if (!geometry1.SpatialReference.IsEqual(geometry2.SpatialReference))
   geometry2 = GeometryEngine.Project(geometry2,geometry1.SpatialReference);

SceneView始终以wgs84纬度/经度返回坐标。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...