The Elevation API provided by Google, uses two parameters for requesting height along a path: path
and samples
. The path is the lat
and lng
of the starting and the finish points and the samples
is the sample points along a path for which to return elevation data. So the path is divided into an ordered set of equidistant points along the path, which are sent back to the client as an array of lat
, lng
and elevation
for each point. This can be useful for visualizing elevation profiles or such.
I have seen other open-source alternatives for the Google Elevation API, however, none of them has an easy way to provide a samples
parameter, so if one wants to achieve the same, you simply have to somehow 'explode' the path yourself into multiple equidistant points and send this array as part of the URL to the back-end.
Is there a library or algorithm I should consider when splitting the path (which is usually of type LineString / polyline) into equidistant points? In general, how should I approach this problem?
I run Open Topo Data and GPXZ, which are open and paid (respectively) alternatives to the Google Elevation API, and both support sampled paths!
The algorithm I use is detailed in Sampling points along a lat,lon path, and the Python code for doing this in Open Topo Data is on here on GitHub.
But in general, here's how to approach this problem:
s_i
:d_i
of samplei
along the path istotal_path_distance * i / n_samples
.d_segment_start <= d_i < d_segment_end
.s_i
is the result of travelling along the segment identified in the previous step by a distance ofd_segment_start - d_i
Some practical considerations