Is it possible to calculate lat and long's in arcgis online?

3798
3
Jump to solution
07-25-2018 12:50 PM
DonPritt
Occasional Contributor II

I have fields for both lats and longs on feature points but some are displaying zero, is it possible to calculate each of these fields to populate lat in longs for all of them?

I know how to locally in Arcmap and Pro but was wondering if I could do this to online feature services.

Thanks,

DP

0 Kudos
1 Solution

Accepted Solutions
CarmelConnolly
Esri Regular Contributor

Hi Don, 

I don't believe it's possible to directly calculate lat/longs in ArcGIS Online but here are 2 possible workaround:

Xander shows how to use Arcade to generate these values in a pop up: Arcade Expression for Geometry in ArcGIS Online Popup These values can't be used in calculations or edited, but if the point is moved, the value will update. 

You can bring your ArcGIS Online features services into ArcGIS Pro and use your usual tools like Add Geometry Attributes on them: Portal items—ArcGIS Pro | ArcGIS Desktop 

Carmel

View solution in original post

3 Replies
CarmelConnolly
Esri Regular Contributor

Hi Don, 

I don't believe it's possible to directly calculate lat/longs in ArcGIS Online but here are 2 possible workaround:

Xander shows how to use Arcade to generate these values in a pop up: Arcade Expression for Geometry in ArcGIS Online Popup These values can't be used in calculations or edited, but if the point is moved, the value will update. 

You can bring your ArcGIS Online features services into ArcGIS Pro and use your usual tools like Add Geometry Attributes on them: Portal items—ArcGIS Pro | ArcGIS Desktop 

Carmel

DonPritt
Occasional Contributor II

Awesome!! Thanks Carmel..

0 Kudos
Sean_Perks
New Contributor II

I know this is from 2018 but I thought it would be good to add this in case folks come here looking for the answer. 

Also this link has some very useful calcs: https://www.esri.com/arcgis-blog/products/field-maps/field-mobility/common-calculated-expressions-fo...

 

// Create a function to convert meters to lat, long
// Source: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
function MetersToLatLon(geometry) {
    if (IsEmpty(geometry)) {
        return [null, null]
    }
    var originShift = 2.0 * PI * 6378137.0 / 2.0
    var lon = (geometry.x / originShift) * 180.0
    var lat = (geometry.y / originShift) * 180.0
    lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0)
    return [Round(lat, 6), Round(lon, 6)]
}

// Call the function and return the latitude or longitude value (change the 0 to a 1 for lon)
MetersToLatLon(Geometry($feature))[0]