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

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.
If the selected transformation is not usable (has missing grid files) then an error is displayed.
How it works
- Pass the input and output spatial references to
TransformationCatalog::transformationsBySuitabilityfor 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. - Use one of the
DatumTransformationobjects 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
This sample uses a GeographicTransformation, which extends the DatumTransformation class. As of 100.9, the ArcGIS Maps SDK for Qt 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.
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.
To download projection engine data to your device:
- Log in to the ArcGIS for Developers site using your Developer account.
- On the Dashboard page, click the ‘Downloads’ tab and select ‘Projection Engine Data’ from the navigation column.
- Download the applicable release version of Projection Engine Data.
- Unzip the downloaded data on your computer.
- Create an
~/ArcGIS/Runtime/Data/PEDataRuntimedirectory on your device and copy the files to this directory.
Tags
datum, geodesy, projection, spatial reference, transformation
Sample code
// [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]
#ifdef PCH_BUILD#include "pch.hpp"#endif // PCH_BUILD
// sample headers#include "ListTransformations.h"
// ArcGIS Maps SDK headers#include "DatumTransformation.h"#include "Envelope.h"#include "Error.h"#include "GeographicTransformation.h"#include "GeographicTransformationStep.h"#include "GeometryEngine.h"#include "Graphic.h"#include "GraphicListModel.h"#include "GraphicsOverlay.h"#include "GraphicsOverlayListModel.h"#include "Map.h"#include "MapQuickView.h"#include "MapTypes.h"#include "Point.h"#include "Polygon.h"#include "SimpleMarkerSymbol.h"#include "SpatialReference.h"#include "SymbolTypes.h"#include "TransformationCatalog.h"#include "Viewpoint.h"
// Qt headers#include <QStandardPaths>#include <QUrl>#include <QVariantMap>#include <QtCore/qglobal.h>
using namespace Esri::ArcGISRuntime;
// helper method to get cross platform data pathnamespace{ QString defaultDataPath() { QString dataPath;
#ifdef Q_OS_IOS dataPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); #else dataPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); #endif
return dataPath; }} // namespace
ListTransformations::ListTransformations(QQuickItem* parent /* = nullptr */): QQuickItem(parent){}
void ListTransformations::init(){ // Register the map view for QML qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView"); qmlRegisterType<ListTransformations>("Esri.Samples", 1, 0, "ListTransformationsSample");}
void ListTransformations::componentComplete(){ QQuickItem::componentComplete();
// get data path const QUrl dataPath = QUrl(defaultDataPath() + "/ArcGIS/Runtime/Data/PEDataRuntime");
// connect to TransformationCatalog error signal connect(TransformationCatalog::instance(), &TransformationCatalog::errorOccurred, this, [this](const Error& e) { if (e.isEmpty()) return;
emit showStatusBar(QString("Error setting projection engine directory: %1. %2").arg(e.message(), e.additionalMessage())); });
// 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. const double x = 538985.355; const double y = 177329.516; m_originalPoint = Point(x, y, SpatialReference(27700));
// find QML MapView component m_mapView = findChild<MapQuickView*>("mapView");
// Create a map using the light gray canvas basemap m_map = new Map(BasemapStyle::ArcGISLightGray, this);
// Set initial viewpoint of the map m_map->setInitialViewpoint(Viewpoint(m_originalPoint, 5000));
// connect to map loaded signal connect(m_map, &Map::doneLoading, this, [this, dataPath] { // Set the TransformationCatalog path TransformationCatalog::setProjectionEngineDirectory(dataPath.toString()); if (TransformationCatalog::projectionEngineDirectory().length() > 0) emit showStatusBar(QString("Projection engine directory set: %1").arg(TransformationCatalog::instance()->projectionEngineDirectory()));
// get the initial list of transformations refreshTransformationList(true); });
// add graphics to the map view addGraphics();
// set map to map view m_mapView->setMap(m_map);}
// Create a GraphicsOverlay with two Graphics - one to hold the default// transformed geometry, and the other to use the selected transformationvoid ListTransformations::addGraphics(){ // Create the original graphic SimpleMarkerSymbol* blueSquare = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Square, QColor("blue"), 20.f, this); m_originalGraphic = new Graphic(m_originalPoint, blueSquare, this);
// Create the projected graphic SimpleMarkerSymbol* redCross = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Cross, QColor("red"), 20.f, this); m_projectedGraphic = new Graphic(m_originalPoint, redCross, this);
// Create the Overlay GraphicsOverlay* overlay = new GraphicsOverlay(this); m_mapView->graphicsOverlays()->append(overlay); overlay->graphics()->append(m_originalGraphic); overlay->graphics()->append(m_projectedGraphic);}
void ListTransformations::refreshTransformationList(bool orderBySuitability){ // get the input/output spatial reference SpatialReference inSpatialReference = m_originalGraphic->geometry().spatialReference(); SpatialReference outSpatialReference = m_map->spatialReference();
// request the transformations if (orderBySuitability) m_transformations = TransformationCatalog::transformationsBySuitability(inSpatialReference, outSpatialReference, m_mapView->visibleArea().extent()); else m_transformations = TransformationCatalog::transformationsBySuitability(inSpatialReference, outSpatialReference);
// update the QML property list m_transformationList.clear(); for (DatumTransformation* transformation : std::as_const(m_transformations)) { QVariantMap transformationMap; transformationMap["name"] = transformation->name(); transformationMap["isMissingProjectionEngineFiles"] = transformation->isMissingProjectionEngineFiles(); m_transformationList.append(transformationMap); }
// update the property emit transformationListChanged();}
void ListTransformations::updateGraphicTransformation(int index){ GeographicTransformation* transform = static_cast<GeographicTransformation*>(m_transformations.at(index)); if (transform->isMissingProjectionEngineFiles()) { QString missingFiles = "Missing grid files: "; const QList<GeographicTransformationStep> steps = transform->steps(); for (const GeographicTransformationStep& step : steps) { const auto filenames = step.projectionEngineFilenames(); for (const QString& filename : filenames) { missingFiles += filename; } } emit showStatusBar(missingFiles); } else { Geometry projectedPoint = GeometryEngine::project(m_originalPoint, m_map->spatialReference(), transform); m_projectedGraphic->setGeometry(projectedPoint); }}// [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]
#ifndef LISTTRANSFORMATIONS_H#define LISTTRANSFORMATIONS_H
// ArcGIS Maps SDK headers#include "Point.h"
// Qt headers#include <QList>#include <QQuickItem>#include <QVariantList>
namespace Esri::ArcGISRuntime{class Map;class MapQuickView;class Graphic;class DatumTransformation;}
class ListTransformations : public QQuickItem{ Q_OBJECT
Q_PROPERTY(QVariantList transformationList MEMBER m_transformationList NOTIFY transformationListChanged)
public: explicit ListTransformations(QQuickItem* parent = nullptr); ~ListTransformations() override = default;
void componentComplete() override; static void init(); Q_INVOKABLE void refreshTransformationList(bool orderBySuitability); Q_INVOKABLE void updateGraphicTransformation(int index);
signals: void transformationListChanged(); void showStatusBar(QString message = "");
private: Esri::ArcGISRuntime::Map* m_map = nullptr; Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr; Esri::ArcGISRuntime::Point m_originalPoint; Esri::ArcGISRuntime::Graphic* m_originalGraphic = nullptr; Esri::ArcGISRuntime::Graphic* m_projectedGraphic = nullptr; QList<Esri::ArcGISRuntime::DatumTransformation*> m_transformations; QVariantList m_transformationList;
void addGraphics();};
#endif // LISTTRANSFORMATIONS_H// [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 QtQuickimport QtQuick.Controlsimport Esri.Samples
ListTransformationsSample { id: rootRectangle clip: true width: 800 height: 600
// add a mapView component MapView { id: mapView anchors { left: parent.left right: parent.right top: parent.top } height: parent.height / 2 objectName: "mapView"
Component.onCompleted: { // Set the focus on MapView to initially enable keyboard navigation forceActiveFocus(); } }
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: refreshTransformationList(checked); }
ListView { id: transformationListView anchors { left: parent.left right: parent.right top: orderCheckbox.bottom bottom: parent.bottom margins: 10 } clip: true model: transformationList
delegate: Item { id: itemDelegate height: 45 width: transformationListView.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.isMissingProjectionEngineFiles ? "%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: { transformationListView.currentIndex = index; updateGraphicTransformation(index); } } }
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 }
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(); } }
onShowStatusBar: message => { statusText.text = message;
if (statusBar.isExpanded) timer.restart(); else statusBar.expand(); }}