Arcade Geometry Function not working

3460
7
03-07-2019 10:28 PM
Jack_Zhang
Occasional Contributor

try to use ArcGIS Arcade Script to create geometries. However, even take the sample code provided by ESRI and run it in Arcade playground, it returns me the error "Execution Error:Cannot create Geometry in this SpatialReference. Engine is using a different spatial reference."

The code attached below:
var pointJSON = {'x' : -118.15, 'y' : 33.80, 'spatialReference' : {'wkid' : 4326}};
Point(pointJSON)

What's going on???

Tags (1)
7 Replies
XanderBakker
Esri Esteemed Contributor

At this moment only Web Mercator (Auxiliary Sphere) (102100 or 3857) is support for the creation of geometries.

XanderBakker
Esri Esteemed Contributor

So what you can do is use a function to translate the WGS Lat Lon coords and then construct the geometry:

function LatLonToMeters(lat, lon) {
    // convert from long/lat to google mercator (or EPSG:4326 to EPSG:900913)
    // Source: https://gist.github.com/springmeyer/871897
    var x = lon * 20037508.34 / 180;
    var y = Log(Tan((90 + lat) * PI / 360)) / (PI / 180);
    y = y * 20037508.34 / 180;
    return [x, y];
}

var lon = -118.15;
var lat = 33.80;

var xy = LatLonToMeters(lat, lon);
Console(xy);

var pointJSON = {'x' : xy[0], 'y' : xy[1], 'spatialReference' : {'wkid' : 102100}};
var pnt = Point(pointJSON);
Console(pnt);
return pnt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Jack_Zhang
Occasional Contributor

Thanks Xander, it's sad it only supports Web Mercator as most of our data are in UTM coordinates. ESIR's help doc also needs be more explicit on that. Also the sample code on the web site has negative longitude (-188.15) which I don't know how that work

KristianEkenes
Esri Regular Contributor

Hi Jack and Xander Bakker‌,

The following statement is incorrect:

"At this moment only Web Mercator (Auxiliary Sphere) (102100 or 3857) is support for the creation of geometries."

You can create geometries in any spatial reference in Arcade. However, the spatial reference of the geometry must match the spatial reference of the map where the Arcade is executed. Since a lot of maps have a web mercator spatial reference it appears like you can only work in web mercator.

XanderBakker
Esri Esteemed Contributor

Hi Kristian Ekenes , thanks for the clarification!

Any ETA on when we can create geometries with any SR regardless of the current SR of the map and transform geometries inside Arcade?

0 Kudos
KristianEkenes
Esri Regular Contributor

No. None at the moment. It has been discussed and we'll continue discussing it. There's a lot to consider here including performance. Is going from 4326 to 3857 (or vice versa) the typical workflow? Or would you require this capability to project geometries to other spatial references?

Another followup question: Do you see a case where you would write an expression with a hard coded geometry that would be used in more than one web map with different spatial references? This one seems like an edge case to me.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Kristian Ekenes ,

Let me try and answer your questions.

Is going from 4326 to 3857 (or vice versa) the typical workflow? 

Vice versa is a typical workflow, especially if you want to construct a URL and provide coordinates, most other applications (Survey123, StreetView, Waze, etc) will want this to be 4326 and in many cases you will have 3857. At this point we can use the funtions shared here in GeoNet, but it will be good to have something more decent and precise using the geometry engine. 

Or would you require this capability to project geometries to other spatial references?

Normally not (in my case at least), since most of my data is published using 3857 to AGOL. I can imagine the use case of having any other SR in the map and being able to 4326 would come in handy.

Do you see a case where you would write an expression with a hard coded geometry that would be used in more than one web map with different spatial references?

I use it for testing and to avoid creating another hosted feature service with the geometry and having to use FeatureSetBy* functions to get the geometry, so to be honest no. However, a user could have an attribute table or stand alone table with coordinates in a different SR and wanting to use these to create a link to another system that uses 4326.

I have come across several questions in GeoNet, where users have been asking for this functionality or being able to work with geometries in different projections. 

Edit: some examples:

0 Kudos