The Arcade developer Attribute Rule Calculation docs say:
When the attribute rule is evaluated for a dataset, the return value for the expression is cast to the field type of the output value. It is best practice to handle casting within the script for full control of casting behavior to Number, Date, or Text return types.
It sounds like that second sentence is implying that we only need to cast datatypes to the output type when the datatype is Number, Date, or Text.
Is that correct?
For example, for geometries, would we return Polyline(my_dictionary) -- and then rely on Arcade to automatically cast that polyline to a geometry?
Or is the fact that Polyline is a subtype of the Geometry type mean that Polyline is technically already a geometry?
Is that correct?
No.
What it means is:
Take this rule:
// converts the value from the text field to integer and double
var txt = $feature.TextField
if(IsEmpty(txt)) { return }
return {"result": {"attributes": {"IntegerField": txt, "DoubleField": txt}}}
I'm not doing any type casting here. I return text values for numeric fields, ArcGIS automatically takes care of the conversion. Great, less work for me! Let's see how that turns out:
Uh oh, something is wrong here...
So the Attribute Rule automatically casted between the data types, but to be sure about the results I get (again. that should be best practice), I should do it myself:
var txt = $feature.TextField
if(IsEmpty(txt)) { return }
txt = Replace(txt, ",", "") // remove American thousands separator
txt = Replace(txt, ".", ",") // replace decimal separator
var dbl = Number(txt)
var int = Floor(dbl)
return {"result": {"attributes": {"IntegerField": int, "DoubleField": dbl}}}
Same concept applies to conversion from and to date. Probably more so, seeing how many different date formats there are...
As for geometries: Yes, you just return the Polyline, which is already a Geometry.