Hello,
I have arcgis pro 2.7.2 and sde point feature class..using attribute rule for X and Y in decimal degrees (DD). I found two different scripts from geonet. Please see issues and screenshots below. Please advise. Thank you.
Script #1 one field type text and 100 characters ATTRUBUTE RULE. nothing happen.
var polyx = text(centroid($feature).x);
var polyy = text(centroid($feature).y);
function metersToLatLon(mx, my) {
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 latlon = "";
var result = "";
var latlon = metersToLatLon(polyx, polyy);
result = Round(latlon[0], 6) + ', ' + Round(latlon[1], 6);
return result;
Script # 2 TWO fields x and y. DOUBLE(38, 8). It is populated but not the correct DD number.
it displays 7.1233 and 4.1234 something. But it is supposed to be -80 and 25 something.
//Latitude
var y = Centroid($feature).y
var originShift = 2.0 * PI * 6378137.0 / 2.0;
var lat = (y / originShift) * 180.0;
lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
return lat
//Longitude
var x = Centroid($feature).x
var originShift = 2.0 * PI * 6378137.0 / 2.0;
var lon = (x / originShift) * 180.0;
return lon
But then I tried to add calculate geometry tool and add geometry attribute tool manual. I got both same error.
Solved! Go to Solution.
Hi @AlexP_ ,
Attribute Rules use Arcade, as you already know, and currently, there is no support for projecting coordinates between coordinate systems in Arcade. The formulas you mentioned earlier only serve to translate Web Mercator Auxilliary Sphere to WGS1984. Only if you have the math to do this translation you will be able to do this using Arcade. That is the situation at this moment.
You may want to think about using a programmed task that executes a script and fills the attributes with the DD values. Not sure when projections will be supported in Arcade. I have heard that REST calls will be supported in Arcade later on, and this would also solve this problem.
I don't know why you are doing all the equations. What is the purpose of the address rule? Are you creating a new point and you want to trigger the rule then and calculate the xy?
@JoeBorgione I am trying to find a script that is working but it is not as expected. This is for an user create a new point, it should populate x and y fields in decimal degree.
If it's a new point, do you need the Centroid qualifier? I'm just not familiar with that function.
But check out this post: https://community.esri.com/t5/arcgis-pro-questions/using-arcade-to-calculate-xy-geometry/m-p/135271#...
@JoeBorgione I tested it but it returns in feet. I tried to click their link as suggested , I already tested that same script #1 as I posted here. It returns blank.
The result should be like this screenshot.
So those calculations are from @XanderBakker that seem to come from this post: https://community.esri.com/t5/developers-questions/lat-long-unit-conversion-with-arcade/m-p/207272?c...
In his post he converts meters to Lat Lat Long, but are you trying to convert FEET to lat long? I think the constant in that equation would need to be changed but I don't know what to. He refers to
http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
So that might help you out.
@JoeBorgione @XanderBakker I think I looked at the wrong script. is there anyway to do it direct populate DD? just like add XY coordinates tool with WGS 1984 in manually. the result is expected.. but lookin to apply that in attribute rule? point x and point y is gonna be blank when an user creates a point.
As mentioned earlier, I'm not familiar with that function.
@JoeBorgione Thank you, Joe. Hope someone or @XanderBakker might assist ..
Hi @AlexP_ ,
Attribute Rules use Arcade, as you already know, and currently, there is no support for projecting coordinates between coordinate systems in Arcade. The formulas you mentioned earlier only serve to translate Web Mercator Auxilliary Sphere to WGS1984. Only if you have the math to do this translation you will be able to do this using Arcade. That is the situation at this moment.
You may want to think about using a programmed task that executes a script and fills the attributes with the DD values. Not sure when projections will be supported in Arcade. I have heard that REST calls will be supported in Arcade later on, and this would also solve this problem.