Get length of roads in a polygon using Arcade

275
1
11-19-2019 12:20 AM
Highlighted
by
Occasional Contributor II

Dear All,

Is it possible, to get the Length of Roads in a polygon layer using Arcade. I tried something below:

var fs = FeatureSetByName($map, 'Roads')
//Clip(geometry, envelope)
var roadsLength = Clip(fs, $feature)

Length(roads, 'kilometers')‍‍‍‍‍

How can I achieve this.

Regards,

Krish   

Reply
0 Kudos
1 Reply
Highlighted
Esri Esteemed Contributor

Hi krishnavsav ,

See below what you can do. This code is not optimized to enhance readability, however, depending the amount of lines you have in a polygon, this could result in a performance hit, since there will be multiple requests to the server.

// get the lines feature set:
var lines = FeatureSetByName($map,"Tubería Acero");

// select only the lines that intersect with the polygon
var relevantlines = Intersects($feature, lines);

// count the overlapping lines
var cnt = Count(relevantlines);

// set the initial total length to 0
var totlength = 0;


if (cnt > 0) {
// there are overlapping lines, loop through each line
for (var line in relevantlines) {
// intersect the line with the polygon
var lineint = Intersection(line, $feature);
// add the length to the total
totlength += LengthGeodetic(lineint, 'm');
}
}

return totlength;
Reply
0 Kudos