ArcGIS 3.0.3 - centroid x and y expressions not consistent ArcGIS Pro vs Portal?

612
4
Jump to solution
02-03-2023 07:35 AM
VincentLaunstorfer
Occasional Contributor III

In ArcGIS Pro, I made 2 simple Arcade expressions to display lat and long in PopUps for polygons centroids.

Centroid($feature).x and Centroid($feature).y

As the layer is in WGS84, I get nice decimal degrees coordinates for centroids in pop-ups

Decimal_Degrees_lat_long.png

Once published as a Hosted layer, the same pop-ups using same Arcade expressions display funny coordinates, like some sort of projected coordinates in meters/feets

Decimal_Degrees_lat_long_Portal.png

Is it normal behavior? Is there any way to force Arcade in Portal to display decimal degrees in WGS84?

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

There isn't a built-in one (though that would be really handy!) But you can find a really nice function that @XanderBakker posted over here, which I am pasting with modifications below:

function MetersToLatLon(x, y) {
    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 c = Centroid($feature)

var coords = MetersToLatLon(c.x, c.y)

return Concatenate(coords, '\n')
- Josh Carlson
Kendall County GIS

View solution in original post

4 Replies
jcarlson
MVP Esteemed Contributor

The post-publishing coordinates are showing Web Mercator units. When you ask for coordinates in a web map, it will use the coordinates of the web map's projection, not the layer.

It is possible to get AGOL to open a WGS84 basemap, thus altering the map's projection, and your same expression would return decimal degrees.

- Josh Carlson
Kendall County GIS
0 Kudos
VincentLaunstorfer
Occasional Contributor III

I thought about the web-Mercator projection, it makes sense although not handy! In Arcade, I wonder if there is any function to translate the web-Mercator coordinates back to WGS84 decimal degrees...? Something like GeodeticX and GeodeticY, just like AreaGeodetic functions...

0 Kudos
jcarlson
MVP Esteemed Contributor

There isn't a built-in one (though that would be really handy!) But you can find a really nice function that @XanderBakker posted over here, which I am pasting with modifications below:

function MetersToLatLon(x, y) {
    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 c = Centroid($feature)

var coords = MetersToLatLon(c.x, c.y)

return Concatenate(coords, '\n')
- Josh Carlson
Kendall County GIS
VincentLaunstorfer
Occasional Contributor III

Thanks (@XanderBakker too). It really helped.In addition, I used a simple if statment in order to display WGS84 lat/lon in decimal degrees in ArcGIS Pro, and once published to Portal using the MetersToLatLon function.

IIf(centroid($feature).x <= 180 && centroid($feature).x >= -180, centroid($feature).y + ',' + centroid($feature).x,
MetersToLatLon(centroid($feature).x, centroid($feature).y)[0] + ',' + MetersToLatLon(centroid($feature).x, centroid($feature).y)[1]);

 

0 Kudos