Click or drag to resize

GeometryEngineProject Method (Geometry, SpatialReference)

Projects the given geometry from its current spatial reference system into the given spatial reference system.

Namespace:  Esri.ArcGISRuntime.Geometry
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.8.0.0
Syntax
public static Geometry Project(
	Geometry geometry,
	SpatialReference outputSpatialReference
)

Parameters

geometry
Type: Esri.ArcGISRuntime.GeometryGeometry
The geometry to be projected.
outputSpatialReference
Type: Esri.ArcGISRuntime.GeometrySpatialReference
The spatial reference to which geometry need to be projected.

Return Value

Type: Geometry
The geometry projected into the given SpatialReference. If the input geometry has a null SpatialReference, no projection occurs; instead, an identical geometry with the given SpatialReference is returned.
Remarks

A default best-choice DatumTransformation is applied to the project operation. To control the specific transformation used, use the Project(Geometry, SpatialReference, DatumTransformation) overload.

If the geometry parameter has z-values, those z-values will also be transformed, if both the SpatialReference of that geometry, and the outputSpatialReference parameter, have a vertical coordinate system.

Examples

WPF

Example Name: Project

Project a point from one spatial reference to another.

Code example screen shot.

C#
// Copyright 2019 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.

using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using Esri.ArcGISRuntime.UI.Controls;
using Color = System.Drawing.Color;

namespace ArcGISRuntime.WPF.Samples.Project
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Project",
        "Geometry",
        "Project a point to another spatial reference.",
        "")]
    public partial class Project
    {
        public Project()
        {
            InitializeComponent();
            Initialize();
        }

        private async void Initialize()
        {
            // Show a map in the default WebMercator spatial reference.
            MyMapView.Map = new Map(Basemap.CreateNationalGeographic());

            // Add a graphics overlay for showing the tapped point.
            GraphicsOverlay overlay = new GraphicsOverlay();
            SimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Red, 5);
            overlay.Renderer = new SimpleRenderer(markerSymbol);
            MyMapView.GraphicsOverlays.Add(overlay);

            // Respond to user taps.
            MyMapView.GeoViewTapped += MapView_Tapped;

            // Zoom to Minneapolis.
            Envelope startingEnvelope = new Envelope(-10995912.335747, 5267868.874421, -9880363.974046, 5960699.183877,
                SpatialReferences.WebMercator);
            await MyMapView.SetViewpointGeometryAsync(startingEnvelope);
        }

        private void MapView_Tapped(object sender, GeoViewInputEventArgs e)
        {
            // Get the tapped point - this is in the map's spatial reference,
            // which in this case is WebMercator because that is the SR used by the included basemaps.
            MapPoint tappedPoint = e.Location;

            // Update the graphics.
            MyMapView.GraphicsOverlays[0].Graphics.Clear();
            MyMapView.GraphicsOverlays[0].Graphics.Add(new Graphic(tappedPoint));

            // Project the point to WGS84
            MapPoint projectedPoint = (MapPoint) GeometryEngine.Project(tappedPoint, SpatialReferences.Wgs84);

            // Format the results in strings.
            string originalCoords = string.Format("Original: {0:F4}, {1:F4}", tappedPoint.X, tappedPoint.Y);
            string projectedCoords = string.Format("Projected: {0:F4}, {1:F4}", projectedPoint.X, projectedPoint.Y);
            string formattedString = string.Format("{0}\n{1}", originalCoords, projectedCoords);

            // Define a callout and show it in the map view.
            CalloutDefinition calloutDef = new CalloutDefinition("Coordinates:", formattedString);
            MyMapView.ShowCalloutAt(tappedPoint, calloutDef);
        }
    }
}
XAML
<UserControl x:Class="ArcGISRuntime.WPF.Samples.Project.Project"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
        <esri:MapView x:Name="MyMapView" />
    </Grid>
</UserControl>
See Also
Additional Examples
Hyperlink to ExampleDescription
AuthorMapCreate and save a map as an ArcGIS `PortalItem` (i.e. web map).
BufferListGenerate multiple individual buffers or a single unioned buffer around multiple points.
CreateAndSaveKmlFileConstruct a KML document and save it as a KMZ file.
GeodesicOperationsCalculate a geodesic path between two points and measure its distance.
ProjectProject a point from one spatial reference to another.
ProjectWithSpecificTransformationProject a point from one coordinate system to another using a specific transformation step.
SceneLayerSelectionIdentify features in a scene to select.
SceneLayerUrlDisplay an ArcGIS scene layer from a URL.
ShowCalloutShow a callout with the latitude and longitude of user-tapped points.