Select to view content in your preferred language

How to simplify multiline expression into 1 expression

252
3
Jump to solution
02-10-2025 02:28 PM
Yeaton
by
Occasional Contributor

Hello,

I've been trying to create a way  to return the slope of a line by using the elevation values obtained via the intersection of the start and end vertex of the line with topo contours.  Creating separate scripts  for attribute fields of the line (i.e., start elv, end elv, length) and then using those values in an equation field worked, but it takes a very long time to process.  I thought a viable alternative is to configure a popup with the same scripts condensed into one arcade expression.  I tried to configure the pop up with multi line script but it only returns the start vertex elevation value.  

Any advice is much appreciated.

The script is below:

//Start vertex (upper elevation) of line used for slope
var paths = Geometry($feature).paths
var line = paths[0][0]

//Selecting the elevation of the contour that is intersected by the start vertex
var x = featuresetbyname($datastore,"Homer_2ft_contour_Lidar_Gen")
for(var f in x){
if(intersects(line,f)){
return f.Contour}
}

//End vertex of line used for slope
Var p = paths[0][1]

//End vertex (lower elevation) of line used for slope
var y = featuresetbyname($datastore,"Homer_2ft_contour_Lidar_Gen")
for(var g in y){
if(intersects(p,g)){
return g.Contour}
}

//Equation to return slope of line
var z = (f-g)/$feature.Shape_Length * 100
return z

Best Regards,

A. Yeaton

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

It's giving you only the beginning vertex since you have a return function when you get an intersecting contour. You want to save that value and use it later. This shows two different outputs to select from, only the slope or the start elevation, the end elevation, and the slope. It also included breaks so you don't have to loop through all the contours.

//Start vertex (upper elevation) of line used for slope
var paths = Geometry($feature).paths;
var line = paths[0][0];
var begin = 0;
var end = 0;
//Selecting the elevation of the contour that is intersected by the start vertex
var x = featuresetbyname($datastore, "Homer_2ft_contour_Lidar_Gen");
for (var f in x) {
  if (intersects(line, f)) {
    begin = f.Contour;
    break;
  }
}

//End vertex of line used for slope
var p = paths[0][1];

//End vertex (lower elevation) of line used for slope
var y = featuresetbyname($datastore, "Homer_2ft_contour_Lidar_Gen");
for (var g in y) {
  if (intersects(p, g)) {
    end = g.Contour;
    break;
  }
}

//Equation to return slope of line
return (begin - end) / $feature.Shape_Length * 100;

//or if you want all values, you can use this return
return `Start elevation: ${begin}
End elevation: ${end}
Slope: ${(begin - end) / $feature.Shape_Length * 100}`;

 

View solution in original post

3 Replies
KenBuja
MVP Esteemed Contributor

It's giving you only the beginning vertex since you have a return function when you get an intersecting contour. You want to save that value and use it later. This shows two different outputs to select from, only the slope or the start elevation, the end elevation, and the slope. It also included breaks so you don't have to loop through all the contours.

//Start vertex (upper elevation) of line used for slope
var paths = Geometry($feature).paths;
var line = paths[0][0];
var begin = 0;
var end = 0;
//Selecting the elevation of the contour that is intersected by the start vertex
var x = featuresetbyname($datastore, "Homer_2ft_contour_Lidar_Gen");
for (var f in x) {
  if (intersects(line, f)) {
    begin = f.Contour;
    break;
  }
}

//End vertex of line used for slope
var p = paths[0][1];

//End vertex (lower elevation) of line used for slope
var y = featuresetbyname($datastore, "Homer_2ft_contour_Lidar_Gen");
for (var g in y) {
  if (intersects(p, g)) {
    end = g.Contour;
    break;
  }
}

//Equation to return slope of line
return (begin - end) / $feature.Shape_Length * 100;

//or if you want all values, you can use this return
return `Start elevation: ${begin}
End elevation: ${end}
Slope: ${(begin - end) / $feature.Shape_Length * 100}`;

 

Yeaton
by
Occasional Contributor

Thanks for the prompt reply, Ken!  I will give this a try and let you know how it goes.

Best,

Aaron

0 Kudos
Yeaton
by
Occasional Contributor

Thanks Ken,  your script worked nicely.

 

Best,

Aaron

0 Kudos