Arcade: Get endpoint coordinates of multi-part polyline

1034
2
03-18-2022 07:55 PM
Bud
by
Notable Contributor

Arcade:

What’s the most succinct way to get the endpoint coordinates of multi-part polyline?

Related: Idea: Arcade Endpoint() function

Tags (1)
0 Kudos
2 Replies
KimGarbade
Occasional Contributor III

I liked this question because I've been looking for a reason to mess the multi-part polyline paths object for a while....

Three lines of code is easier to read, but you can do it in 1 (very bottom... in keeping with the "most succinct" theme)

var pathcount = Count(Geometry($feature).paths)-1
var linepath = Geometry($feature).paths[pathcount]
return Back(linepath).x +","+ Back(linepath).y

In the image below the selected polyline is multipart.  The blue labels are just the vertices of the lines labeled with their coordinates. The black labels are the results of the code to label the last vertex of each line.

KimGarbade_0-1647694736433.png

One line:

return Back(Geometry($feature).paths[Count(Geometry($feature).paths)-1]).x +","+ Back(Geometry($feature).paths[Count(Geometry($feature).paths)-1]).y

JohannesLindner
MVP Frequent Contributor

I'll just copy my answer from your idea:

In case you don't know: You can use negative numbers to index arrays from the end. While array[0] returns the first element, array[-1] returns the last element, array[-2] returns the second to last element and so on.

So you can get the last point of a polyline by jumping to the last point of the last line segment:

Geometry($feature).paths[-1][-1]

Have a great day!
Johannes