Using Arcade to calculate xy geometry.

12811
14
Jump to solution
11-21-2019 10:36 AM
AbiDhakal
Occasional Contributor III

Hello GIS friends,

Is there an arcade expression I can use to calculate xy values for a point feature? I am using this (return Round(Geometry($feature)x, 6) expression, but it is not doing the work. My field name is Point_X and Point_Y.

Thank you very much,

Abi

Tags (1)
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi Abi Dhakal ,

You are missing a dot "." in the expression, It should be:

Round(Geometry($feature).X, 6)

... but if it is working for you, then I assume it is just a typo. 

You are mentioning WKID 3857 (Web Mercator Auxiliary Sphere) and that you want it in meters. However, this is a spatial reference that already return the coordinate in meters. If you want to obtain decimal degrees (WGS 1984) you can use a conversion to get that. See example here: https://community.esri.com/message/806053-re-latlong-unit-conversion-with-arcade?commentID=806053#co... 

View solution in original post

14 Replies
AbiDhakal
Occasional Contributor III

Hello GIS friends,

This expression worked for me, but it is in meters. How can is change it to  WKID 3857 from within the expression?

Thank you.

Abi

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Abi Dhakal ,

You are missing a dot "." in the expression, It should be:

Round(Geometry($feature).X, 6)

... but if it is working for you, then I assume it is just a typo. 

You are mentioning WKID 3857 (Web Mercator Auxiliary Sphere) and that you want it in meters. However, this is a spatial reference that already return the coordinate in meters. If you want to obtain decimal degrees (WGS 1984) you can use a conversion to get that. See example here: https://community.esri.com/message/806053-re-latlong-unit-conversion-with-arcade?commentID=806053#co... 

AbiDhakal
Occasional Contributor III

Sorry. I meant to say I have it in NAD_1983_UTM_Zone_16N and like you mentioned I want to obtain decimal degrees (WGS 1948). Would the same expression work with the OriginalShift and all? I'm actually trying to create an attribute rule for the xy fields to auto populate.

Once again I'm sorry for the confusion.

Abi

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Abi Dhakal ,

Unfortunately in Arcade you do not have access to any projection library (yet?). For this in ArcGIS Pro, you can use Python to do the job. Using a projection in a field calculation on a feature basis, might not be very fast. Depending the number of features you have, you might first want to project the featureclass, calculate the X and Y of the geometry and than join back those fields to the original featureclass.

AbiDhakal
Occasional Contributor III

@XanderBakker 

I'm sorry Xander, please accept my apology for not clearly stating what I'm looking for.

1. I'm trying to get WGS84 values in decimal degrees for a feature service that is in NAD 1983 UTM Zone16N .

2. I'm also trying to get WGS84 values in decimal degrees for a feature service that is in USA Contiguous Albers Equal Area Conic USGS.

So those are two different calculation for two toally different situations.

Thak you,
Abi

0 Kudos
AbiDhakal
Occasional Contributor III

Hey Xander,

Morning!

What I am trying to do is create an attribute rule where by any point collected automatically also has its xy calculated in decimal degrees. Is that possible?

Thank you.

Abi

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi AlabamaForest , 

Currently, that is not possible if it requires a projection of coordinates. 

AbiDhakal
Occasional Contributor III

Thank you very much Xander!

0 Kudos
ScottKichman
New Contributor III

I do these attribute rules for a federated service

 

Coordinates

//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