Select to view content in your preferred language

Arcade Expression to populate longitude and latitude

2854
3
08-04-2022 10:23 AM
KWilliams
New Contributor III

Hello,

Pretty new to Arcade. I need to take the geometry of my point feature and populate the field "Latitude" with the y geometry. Then run through that again but take the x geometry and populate the field "Longitude". My point feature was created in ArcPro, the map was in WGS84 for the creation, I verified again that my point feature is WGS84. I'm looking for decimal degrees but I'm not sure what this 5307669.5296 value is. Looking at other posts, sounds like its in meters? There's other posts about converting to what I'm looking for but I'm not sure where in the conversion code to plug in my '$feature'. Any help would be greatly appreciated.

I'm aware of this code here. I'm just not sure where in the expression to plug in my data (the $feature)? 

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];
}‍‍‍‍‍‍‍‍‍‍‍

 

Here's the page I'm referring to: Lat/Long unit conversion 

Playing around with this code, its not failing but its also not producing any 'results' - and I think I just don't know where to plug in my $feature

0 Kudos
3 Replies
Savannah2019
Occasional Contributor

Hi! 

I've used this code in the past to auto populate a pop-up with Lat, Long. I didn't change anything about the code at all. Except there was a second half to what you have:

function MetersToLatLon(mx, my) {
// Converts XY point from Spherical web 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 = (mx / originShift) * 180.0;
var lat = (my / originShift) * 180.0;

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


var poly = Geometry($feature);

var result = "";
if (!IsEmpty(poly)) {
var pnt_centr = Centroid(poly);

var latlon = MetersToLatLon(pnt_centr.x, pnt_centr.y);

result = Round(latlon[0], 6) + "," + Round(latlon[1], 6);
} else {
result = "";
}

return result;

This returned both in one line, but you can tweak the result to only show one. I found it here

ErnestoCarreras4
New Contributor III

Is it possible to convert coordinates from EPSG:2881 NAD83(HARN) / Florida East (ftUS) to EPSG4326 using Arcade in ArcGIS Pro?

MarkGambordella
New Contributor III

where you able to find a script to convert to your desired coordinates.  we are trying to do the same.

0 Kudos