Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for Qt

Project

Sample Viewer View Sample on GitHub

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

  1. 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.

Tags

coordinate system, coordinates, latitude, longitude, projected, projection, spatial reference, Web Mercator, WGS 84

Sample Code

import QtQuick 2.6
import Esri.ArcGISRuntime 100.9
import Esri.ArcGISRuntime.Toolkit.Controls 100.9

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

    MapView {
        id: mapView
        anchors.fill: parent

        Map {
            BasemapNationalGeographic {}

            // Set initial viewpoint to Minneapolis
            ViewpointExtent {
                Envelope {
                    xMin: -10995912.335747
                    yMin: 5267868.874421
                    xMax: -9880363.974046
                    yMax: 5960699.183877
                    spatialReference: SpatialReference { wkid: 3857 }
                }
            }
        }

        // Declare a callout
        Callout {
            id: callout
            calloutData: parent.calloutData
            accessoryButtonHidden: true
            autoAdjustWidth: true
            maxWidth: 350
            leaderPosition: leaderPositionEnum.Automatic
        }

        // create a graphics to show the input location
        GraphicsOverlay {

            // create a red marker symbol for the input point
            Graphic {
                id: inputGraphic

                SimpleMarkerSymbol {
                    color: "red"
                    size: 5
                    style: Enums.SimpleMarkerSymbolStyleCircle
                }
            }
        }

        // handle mouseClicked signal
        onMouseClicked: {
            // get the mouse click as a point
            const 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 WGS84
            const 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();
        }
    }
}