Select to view content in your preferred language

Lat/Long unit conversion with Arcade

25351
21
Jump to solution
10-11-2018 01:10 PM
AhjungKim4
Frequent Contributor

I am adding geometry fields using Arcade Geometry($feature).x and Geometry($feature).y.  Since my target feature layer is in Web Mercator projection, my custom lat & long fields are displaying the values in meter.  Is there a way to convert this to decimal degrees with arcade function? 

21 Replies
RyanBohan
Frequent Contributor

Thank you!  I had a Rest endpoint with only x,y in the attributes.

Your arcade worked perfectly to be able to use google directions

RyanBohan_0-1716414056025.png

var x = Geometry($feature).x
var y = Geometry($feature).y

// Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84 Datum
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];

var string = "https://www.google.com/maps/dir/?api=1&destination=" + lat + "," + lon + "&tavelmode=walking"
return string

 

0 Kudos
RyanBohan
Frequent Contributor

It would be great to have some increased functions added to arcade to include ToLatitude(geometry($feature).x) and ToLongitude(geometry($feature).y)

Please consider adding a kudo to this idea

Covert point geometry to Latitude and Longitude - Esri Community