Select to view content in your preferred language

Arcade Expression - ChatGPT

2635
5
Jump to solution
01-26-2023 02:17 PM
LoganMayerVM
Emerging Contributor

I am very much a novice with Arcade Expressions and I was hoping someone may be kind enough to help with writing an expression that can calculate the number of miles in a layer ('DART_Bus_Route_KML') do not fall within a 0.25 mile radius of locations on another layer ('billboards').

I thought I'd try to use the technology that everyone raves about, ChatGPT, to help with writing the expression, and it wrote this:

var bus_miles = Length(geometry(DART_Bus_Route_KML))/1609.34;
var near_billboards = Intersects(geometry(DART_Bus_Route_KML), Buffer(geometry(billboards), 0.25));
var non_near_bus_miles = Sum(Filter(bus_miles, !near_billboards));
return non_near_bus_miles;

When running the expression, I get the error message: "Execution error - Line : 1, 32: Identifier not recognised".

Any suggestions on where our AI overlord may have made an error in his expression?

Thanks to anyone who may be able to help!

 

 

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

I asked because Arcade has different profiles, each with different capabilities, so it does matter.

But honestly, unless you need the output of this expression to dynamically adjust to live data, you're probably better off just performing an actual analysis workflow, buffering and clipping the layers.

If you're doing this entirely in AGOL, check out the documentation.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
5 Replies
jcarlson
MVP Esteemed Contributor

That's pretty funny! And not too bad, considering.

To problems are a few:

  1. "billboards" and "DART_Bus_Route_KML" don't refer to anything. To access layers in an Arcade expression, you need to use a FeatureSet expression of some kind.
  2. Intersects will return features which intersect in any way with the other feature / featureset. If even a foot of the feature intersected, it would be included, even though the majority of the feature (and thus its linear measurement) fell outside the buffer. You'll need to clip the routes by the buffered geometry, which is possible in Arcade, but not terribly efficient.
  3. Filter needs a SQL expression as its second parameter
  4. Sum needs a field name for which to calculate the sum
  5. Buffer needs a units parameter, I think?

Where are you trying to implement this expression? ChatGPT probably doesn't know which Arcade profile you're working in.

- Josh Carlson
Kendall County GIS
0 Kudos
LoganMayerVM
Emerging Contributor

Hi Josh! Thanks for the quick reply! I'm probably embarrassing myself here, but I don't think I really know 'where' I'm trying to implement it - or at least I'm not totally understanding the question.

It's in one of my maps on ArcGIS Online (not pro - if that makes a difference). In terms of where the ultimate answer would appear (pop-up, field, etc.), it isn't as important to me as just figuring out the number of miles that don't fall within the 0.25 miles.

Is there a better way of clipping the route without using Arcade? 

This will probably be the only time I end up using a feature like this but I may end up just going through the online course because based on your feedback, here is my poor attempt at trying to update the expression (at least based on my interpretation of your first few notes).

var bus_miles = Length(geometry($featureDART_Bus_Route_KML))/1609.34;
var near_billboards = Intersects(geometry($featureDART_Bus_Route_KML), Buffer(geometry($layerbillboards), 0.25));
var non_near_bus_miles = Sum(Filter(bus_miles, !near_billboards));
return non_near_bus_miles;

0 Kudos
jcarlson
MVP Esteemed Contributor

I asked because Arcade has different profiles, each with different capabilities, so it does matter.

But honestly, unless you need the output of this expression to dynamically adjust to live data, you're probably better off just performing an actual analysis workflow, buffering and clipping the layers.

If you're doing this entirely in AGOL, check out the documentation.

- Josh Carlson
Kendall County GIS
0 Kudos
LoganMayerVM
Emerging Contributor

That is great feedback Josh! I will definitely dive in on the documentation. 

 

Really appreciate you going out of your way to help!

0 Kudos
DavidForbuss1
Frequent Contributor

Great idea using ChatGPT!  I just tried it for some labeling help and it sort of worked, but it definitely was better than google : ) 

0 Kudos