Select to view content in your preferred language

Attribute Rule- X and Y coordinates Decimal Degrees

5645
10
Jump to solution
05-12-2021 10:12 AM
AlexP_
by
Frequent Contributor

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. 

AlexP__0-1620838797860.png

 

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

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. 

View solution in original post

10 Replies
JoeBorgione
MVP Emeritus

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?

That should just about do it....
AlexP_
by
Frequent Contributor

@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. 

0 Kudos
JoeBorgione
MVP Emeritus

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#...  

That should just about do it....
AlexP_
by
Frequent Contributor

@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. 

 

 

0 Kudos
JoeBorgione
MVP Emeritus

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.

 

 

That should just about do it....
0 Kudos
AlexP_
by
Frequent Contributor

@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. 

0 Kudos
JoeBorgione
MVP Emeritus

As mentioned earlier, I'm not familiar with that function. 

That should just about do it....
0 Kudos
AlexP_
by
Frequent Contributor

@JoeBorgione  Thank you, Joe. Hope someone or @XanderBakker might assist ..

0 Kudos
XanderBakker
Esri Esteemed Contributor

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.