Project a point from one spatial reference to another.
Use case
Being able to project between spatial references is fundamental to a GIS. An example of when you would need to re-project data is if you had data in two different spatial references, but wanted to perform an intersect analysis with the GeometryEngine.intersect function. This function takes two geometries as parameters, and both geometries must be in the same spatial reference. If they are not, you could first use GeometryEngine.project to convert the geometries so they match.
How to use the sample
Click anywhere on the map. A callout will display the clicked location's coordinate in the original (basemap's) spatial reference and in the projected spatial reference.
How it works
Call the static method, GeometryEngine.project, passing in the original Geometry and a SpatialReference to which it should be projected.
Relevant API
GeometryEngine
Point
SpatialReference
Additional information
In cases where the the output spatial reference uses a different geographic coordinate system than that of the input spatial reference, see the GeometryEngine.project method that additionally takes in a DatumTransformation parameter.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// [WriteFile Name=ProjectGeometry, Category=Geometry]// [Legal]// Copyright 2018 Esri.// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]import QtQuick
import Esri.ArcGISRuntime
import Esri.ArcGISRuntime.Toolkit
Rectangle {
id: rootRectangleclip: truewidth: 800height: 600MapView {
id: mapViewanchors.fill: parentComponent.onCompleted: {
// Set the focus on MapView to initially enable keyboard navigation forceActiveFocus();
}
Map {
Basemap {
initStyle: Enums.BasemapStyleArcGISTopographic
}
// Set initial viewpoint to MinneapolisViewpointExtent {
Envelope {
xMin: -10995912.335747yMin: 5267868.874421xMax: -9880363.974046yMax: 5960699.183877spatialReference: SpatialReference { wkid: 3857 }
}
}
}
// Declare a calloutCallout {
id: calloutcalloutData: parent.calloutData
accessoryButtonVisible: falseautoAdjustWidth: truemaxWidth: 350leaderPosition: Callout.LeaderPosition.Automatic
}
// create a graphics to show the input locationGraphicsOverlay {
// create a red marker symbol for the input pointGraphic {
id: inputGraphicSimpleMarkerSymbol {
color: "red"size: 5style: Enums.SimpleMarkerSymbolStyleCircle
}
}
}
// handle mouseClicked signalonMouseClicked: mouse => {
// get the mouse click as a pointconst originalPoint = mouse.mapPoint;
// show the clicked location on the map with a graphic inputGraphic.geometry = originalPoint;
// create the output SpatialReference by specifying a well known ID (WKID)const spatialReference = ArcGISRuntimeEnvironment.createObject("SpatialReference", {
wkid: 4326 });
// project the web mercator point to WGS84const projectedPoint = GeometryEngine.project(originalPoint, spatialReference);
// update callout data calloutData.title = "Coordinates" calloutData.location = originalPoint;
const ox = originalPoint.x.toFixed(5)
const oy = originalPoint.y.toFixed(5);
const px = projectedPoint.x.toFixed(5);
const py = projectedPoint.y.toFixed(5);
calloutData.detail = "Original: %1, %2\nProjected: %3, %4".arg(ox).arg(oy).arg(px).arg(py);
// show the callout callout.showCallout();
}
}
}