-1

I have two geometries with the same coordinate system (Wgs84), but their data units are different, one is degree and the other is meter. I need to perform some operations on them, like:

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

But I got an error:

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

So I want to convert the data in degrees to the data in meters, I don’t know how to do it.

The data in meters comes from the shp file. This shp file is loaded into SceneView.

The data in degrees comes from the PreviewMouseLeftButtonDown event of SceneView:

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

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

Then I thought about whether the unit can be modified by setting SceneView.SpatialReference.Unit, but it is read-only.

A .NET solution is the best, and other languages are also acceptable.

zLulus
  • 15
  • 1
  • 3

2 Answers2

0
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);
zLulus
  • 15
  • 1
  • 3
0

Most geometry engine operations requires all geometries to be in the same spatial reference. As the error points to, that is not the case. Before performing any geometry engine operation, you could use the following code to bring geometry2 over to match the spatial reference of geometry1 (or vise-versa):

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

The SceneView always returns coordinates in wgs84 lat/long.

dotMorten
  • 1,953
  • 1
  • 14
  • 10
  • Thank you very much! I am new to GIS, and I am confused about many concepts. I noticed the problem of the return coordinates of SceneView, it really caused trouble to my work, and it has been solved now. – zLulus Nov 06 '20 at 02:27