Change/Transform Geometry in Expression

1536
1
01-20-2019 07:04 PM
MarcoPoetsch_ret
New Contributor III

Hi there,

I have the following issue:

I want to display the coordinates of points in AGOL in WKID 4326.
However, since the reference system of the map is different I get this error message:

Cannot create Geometry in this SpatialReference.
Engine is using a different spatial reference.

Is there a way to project the geometry using Arcade?

Tags (2)
0 Kudos
1 Reply
XanderBakker
Esri Esteemed Contributor

Hi Marco Poetsch , 

Projection is not supported in the Arcade expression (yet). So in theory it is not possible to apply a projection in an Arcade expression. However, I have used a rather simple function to transform a point in Web Mercator Auxialiary Sphere to WGS 1984:

function MetersToLatLon(x, y) {
    // Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84 Datum
    // Fuente: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
    var originShift = 2.0 * PI * 6378137.0 / 2.0;

    var lon = (x / originShift) * 180.0;
    var lat = (y / originShift) * 180.0;

    lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
    return [lat, lon];
}

I have used this to create hyperlinks to Waze, Streetview and prefill a Survey123 surfey with a location. An example of how this is done (in Spanish) can be found here: https://community.esri.com/docs/DOC-11541-crear-un-enlace-para-navegar-con-waze-en-la-ventana-emerge...