List transformations by suitability

View inC++QMLView on GitHubSample viewer app

Get a list of suitable transformations for projecting a geometry between two spatial references with different horizontal datums.

screenshot

Use case

Transformations (sometimes known as datum or geographic transformations) are used when projecting data from one spatial reference to another when there is a difference in the underlying datum of the spatial references. Transformations can be mathematically defined by specific equations (equation-based transformations), or may rely on external supporting files (grid-based transformations). Choosing the most appropriate transformation for a situation can ensure the best possible accuracy for this operation. Some users familiar with transformations may wish to control which transformation is used in an operation.

How to use the sample

Select a transformation from the list to see the result of projecting the point from EPSG:27700 to EPSG:3857 using that transformation. The result is shown as a red cross; you can visually compare the original blue point with the projected red cross.

Select 'Consider current extent' to limit the transformations that are appropriate for the current extent.

If the selected transformation is not usable (has missing grid files) then an error is displayed.

How it works

  1. Set the location of projection engine data on the device with TransformationCatalog.projectionEngineDirectory.
  2. Pass the input and output spatial references to TransformationCatalog.transformationsBySuitability for transformations based on the map's spatial reference OR additionally provide an extent argument to only return transformations suitable to the extent. This returns a list of ranked transformations.
  3. Use one of the DatumTransformation objects returned to project the input geometry to the output spatial reference.

Relevant API

  • DatumTransformation
  • GeographicTransformation
  • GeographicTransformationStep
  • GeometryEngine
  • GeometryEngine.project
  • TransformationCatalog

About the data

The map starts out zoomed into the grounds of the Royal Observatory, Greenwich. The initial point is in the British National Grid spatial reference, which was created by the United Kingdom Ordnance Survey. The spatial reference after projection is in web mercator.

Additional information

Some transformations aren't available until transformation data is provided.

This sample can be used with or without provisioning projection engine data to your device. If you do not provision data, a limited number of transformations will be available.

This sample uses a GeographicTransformation, which extends the DatumTransformation class. As of 100.9, ArcGIS Runtime also includes a HorizontalVerticalTransformation, which also extends DatumTransformation. The HorizontalVerticalTransformation class is used to transform coordinates of z-aware geometries between spatial references that have different geographic and/or vertical coordinate systems.

To download projection engine data to your device:

  1. Log in to the ArcGIS for Developers site using your Developer account.
  2. In the Dashboard page, click 'Download APIs and SDKs' and go to the Supplemental ArcGIS Runtime Data tab.
  3. Click the download button next to Projection Engine Data to download projection engine data to your computer.
  4. Unzip the downloaded data on your computer.
  5. Create an ~/ArcGIS/Runtime/Data/PEDataRuntime directory on your device and copy the files to this directory.

Tags

datum, geodesy, projection, spatial reference, transformation

Sample Code

ListTransformations.qml
Use dark colors for code blocksCopy
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// [WriteFile Name=ListTransformations, Category=Geometry]
// [Legal]
// Copyright 2017 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 2.6
import QtQuick.Controls 2.2
import Esri.ArcGISRuntime 100.15
import Esri.ArcGISExtras 1.1

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600

    property bool peDataSet: true
    readonly property string dataPath: System.userHomePath + "/ArcGIS/Runtime/Data/PEDataRuntime"

    Component.onCompleted: TransformationCatalog.projectionEngineDirectory = dataPath

    Connections {
        target: TransformationCatalog
        function onErrorChanged() {
            peDataSet = false;
        }
    }

    MapView {
        id: mapView
        anchors {
            left: parent.left
            right: parent.right
            top: parent.top
        }
        height: parent.height / 2

        Component.onCompleted: {
            // Set the focus on MapView to initially enable keyboard navigation
            forceActiveFocus();
        }

        Map {
            id: map
            Basemap {
                initStyle: Enums.BasemapStyleArcGISLightGray
            }

            ViewpointCenter {
                center: originalGeometry
                targetScale: 5000
            }

            onLoadStatusChanged: {
                if (loadStatus !== Enums.LoadStatusLoaded)
                    return;

                getTransformations();
                statusBar.expand();
            }
        }

        // Create a GraphicsOverlay with two Graphics - one to hold the default
        // transformed geometry, and the other to use the selected transformation
        GraphicsOverlay {
            Graphic {
                geometry: originalGeometry

                SimpleMarkerSymbol {
                    style: Enums.SimpleMarkerSymbolStyleSquare
                    color: "blue"
                    size: 20
                }
            }

            Graphic {
                id: projectedGraphic
                geometry: originalGeometry

                SimpleMarkerSymbol {
                    style: Enums.SimpleMarkerSymbolStyleCross
                    color: "red"
                    size: 20
                }
            }
        }

        // Create a geometry located in the Greenwich observatory courtyard in London, UK, the location of the
        // Greenwich prime meridian. This will be projected using the selected transformation.
        Point {
            id: originalGeometry
            x: 538985.355
            y: 177329.516
            SpatialReference { wkid: 27700 }
        }
    }

    Rectangle {
        id: transformationView

        anchors {
            left: parent.left
            right: parent.right
            top: mapView.bottom
        }

        height: parent.height / 2
        color: "#f7f7f7"

        CheckBox {
            id: orderCheckbox
            anchors {
                left: parent.left
                top: parent.top
                margins: 10
            }
            text: "Order by suitability for map extent"
            onCheckedChanged: {
                getTransformations();
            }
        }

        ListView {
            id: transformationList
            anchors {
                left: parent.left
                right: parent.right
                top: orderCheckbox.bottom
                bottom: parent.bottom
                margins: 10
            }
            clip: true

            delegate: Item {
                id: itemDelegate
                height: 45
                width: parent.width
                clip: true

                // show the DatumTransformation name
                Text {
                    id: label
                    anchors {
                        verticalCenter: parent.verticalCenter
                        left: parent.left
                        right: parent.right
                    }
                    width: parent.width
                    text: model.modelData.missingProjectionEngineFiles ? "%1 <font color=red><b>Missing grid files</b></font>".arg(model.modelData.name) : model.modelData.name
                    textFormat: Text.RichText
                    wrapMode: Text.WrapAnywhere
                    maximumLineCount: 2
                    font.pixelSize: 12
                }

                MouseArea {
                    id: itemMouseArea
                    anchors.fill: parent
                    onClicked: {
                        transformationList.currentIndex = index;
                        const transform = transformationList.model[index];
                        if (transform.missingProjectionEngineFiles) {
                            let missingFiles = "Missing grid files: ";
                            const steps = transform.steps;
                            for (let i = 0; i < steps.length; i++) {
                                for (let j = 0; j < steps[i].projectionEngineFilenames.length; j++) {
                                    missingFiles += steps[i].projectionEngineFilenames[j];
                                }
                            }
                            statusText.text = missingFiles + " ";
                            if (statusBar.isExpanded)
                                timer.restart();
                            else
                                statusBar.expand();
                        } else {
                            projectedGraphic.geometry = GeometryEngine.projectWithDatumTransformation(originalGeometry, map.spatialReference, transform);
                        }
                    }
                }
            }

            highlightMoveDuration: 1
            highlightFollowsCurrentItem: true
            highlight: Rectangle {
                color: "#d6d6d6"
                radius: 4
            }
        }
    }

    Rectangle {
        id: statusBar
        property int expanded: parent.height - height
        property int hidden: parent.height
        property bool isExpanded: y === expanded
        anchors {
            left: parent.left
            right: parent.right
        }
        height: 45
        color: "black"
        y: hidden

        Text {
            id: statusText
            anchors {
                left: parent.left
                right: parent.right
                verticalCenter: parent.verticalCenter
                margins: 10
            }
            color: "white"
            wrapMode: Text.WrapAnywhere
            text: peDataSet ?
                      "Projection engine directory set %1".arg(dataPath) :
                      "Error setting projection engine directory: %1. %2".arg(TransformationCatalog.error.message).arg(TransformationCatalog.error.additionalMessage)
        }

        Timer {
            id: timer
            interval: 5000
            onTriggered: statusBar.animate();
        }

        onYChanged: {
            if (y === expanded)
                timer.restart();
        }

        NumberAnimation {
            id: statusAnimation
            target: statusBar
            properties: "y"
            duration: 500
            easing.type: Easing.OutQuad
        }

        function expand() {
            statusAnimation.from = statusBar.hidden;
            statusAnimation.to = statusBar.expanded;
            statusAnimation.start();
        }

        function hide() {
            statusAnimation.from = statusBar.expanded;
            statusAnimation.to = statusBar.hidden;
            statusAnimation.start();
        }

        function animate() {
            if (statusBar.y === statusBar.hidden)
                expand();
            else
                hide();
        }
    }

    function getTransformations() {
        if (orderCheckbox.checked)
            transformationList.model = TransformationCatalog.transformationsBySuitabilityWithAreaOfInterest(originalGeometry.spatialReference, map.spatialReference, mapView.visibleArea.extent);
        else
            transformationList.model = TransformationCatalog.transformationsBySuitability(originalGeometry.spatialReference, map.spatialReference);
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.