How to use the geometry of a related record in Arcade

876
5
04-08-2020 12:00 AM
New Contributor II

Good morning all

I am trying to calculate the distance between points in two different feature layers using Arcade.

Using FeatureSetById I can pull the data for the related feature layer, but how do I use the geometry of the related feature in the arcade Distance function?

Thanks

Gavin

//First read out the unique id of current feature
var A1 = \$feature.holenumber
//Access the second feature
var A2 = FeatureSetById(\$map, /* Designed_drilling */ "Designed_drilling_3788", ['holenumber'], true)

//create sql expression
var A3 = "holenumber = '" + A1 + "'"

// filter the second feature using the sql expression
var A4 = Filter(A2, A3)

return A4

//Distance(\$feature, \$A4, 'meters')

Tags (2)
1 Solution

Accepted Solutions
Esri Esteemed Contributor

Glad to hear that the expression worked (after altering the coordinate system). Can you mark the post that answered your question as the correct answer?

5 Replies
Esri Esteemed Contributor

Hi 2123590 ,

Remember that when you use Filter it will return a featureset (even if there is only 1 result in it). Therefore, you will have to access for instance the first feature in the featureset to be able to use the geometry. I also recommend you to use more understandable names for your variables for readability.

``````//First read out the unique id of current feature
var holenumber = \$feature.holenumber;

//Access the second feature
var fs_designed = FeatureSetById(\$map, /* Designed_drilling */ "Designed_drilling_3788", ['holenumber'], true);

//create sql expression
var sql = "holenumber = '" + holenumber + "'";

// filter the second feature using the sql expression
var filtered_holes = Filter(fs_designed, sql); // this returns a featureset!

// set default distance
var dist = -1;
if (Count(filtered_holes)) {
// the filter returned in a result, take the first feature
var designed_hole = First(filtered_holes);
// get the geometry
var geom = Geometry(designed_hole);
// calculate the distance
dist = Distance(\$feature, geom, 'meters');
}

return dist;
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````
New Contributor II

Good morning Xander Bakker

Thanks for the help, unfortunately when I run the script you gave, I just get a run time error. I ran the different functions separately to make sure they each work and that I get geometry out and not a feature set. But everything checks out, but still the run time error.

Where do I look for the issue? Could it be my data?

Regards,

Gavin

Esri Esteemed Contributor

Hi 2123590 ,

If it would be possible to have access to the data or a sample of it I could test it and see what is going wrong. Is that possible?

New Contributor II

I managed to figure out the problem and it was not the arcade expression. My data is in a projected coordinated system, if I use one of the ESRI base maps, the expression works. If I use my own base map that is in the same projected coordinate system, the expression crashes. I assume it has to do with how ArcGIS calculates distance in a web map. (The expression works 100% in ArcGIS Pro.)

Thanks for the help.

Regards,

Gavin

Esri Esteemed Contributor

Glad to hear that the expression worked (after altering the coordinate system). Can you mark the post that answered your question as the correct answer?