Select to view content in your preferred language

Using Arcade to Iterate Over Polyline Vertices

771
2
Jump to solution
02-14-2023 02:42 AM
StefanAngerer
Regular Contributor

Hey Esri Community!

Hope you're all doing well. I'm working on a project and I'm wondering if any of you know if it's possible to iterate over the vertices of a polyline in Arcade and set the height of each vertex to a specific value, say -0.80?

If you have any tips or resources that could help me out with this, I'd really appreciate it!

Thanks in advance for your help!

Best, Stefan

PS: I know, it would be more convinient to just set the default value of the z-value to the desired height but somehow this is not an option in this project 😉

PPS: This is the code I have come up so far:

if (...)){
var lineGeo = Geometry($feature);
var linePaths = lineGeo.paths;
var newPath = [];

for (var lineSegment in linePaths){
for(var vertex in linePaths[lineSegment]){
var startPoint = linePaths[lineSegment][vertex][0]
var endPoint = linePaths[lineSegment][vertex][1]
var height = -0.80
var newSegment = [startPoint, endPoint, height]
push(newPath, newSegment)
}
}

var newLineGeo = Polyline({
paths: [newPath],
hasZ: true,
spatialReference: lineGeo.spatialReference
});
return newLineGeo
} else {
return Geometry($feature);
}

 
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

 

// return early if your condition is false
// this makes the rest of the code more readable
var condition = true
if(!condition) {
    return Geometry($feature)
}

var paths = Geometry($feature).paths
var new_paths = []
for(var p in paths) {
    var path = paths[p]
    var new_path = []
    for(var v in path) {
        var vertex = path[v]
        var new_vertex = [vertex.x, vertex.y, -0.8]
        Push(new_path, new_vertex)
    }
    Push(new_paths, new_path)
}
return Polyline({paths: new_paths, spatialReference: Geometry($feature).spatialReference})

 


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

 

// return early if your condition is false
// this makes the rest of the code more readable
var condition = true
if(!condition) {
    return Geometry($feature)
}

var paths = Geometry($feature).paths
var new_paths = []
for(var p in paths) {
    var path = paths[p]
    var new_path = []
    for(var v in path) {
        var vertex = path[v]
        var new_vertex = [vertex.x, vertex.y, -0.8]
        Push(new_path, new_vertex)
    }
    Push(new_paths, new_path)
}
return Polyline({paths: new_paths, spatialReference: Geometry($feature).spatialReference})

 


Have a great day!
Johannes
Bud
by
Esteemed Contributor
0 Kudos