Il 2025-09-27 16:05 Antonio Valanzano ha scritto:
> If I try to find the point corresponding to a specified value of the
> measure the two function return partially different results.
>
> The first one "ST_Locate_Along_Measure()" retruns NULL for an
> intermediate value of the measure, if this value occurs in a position
> where there is no vertex, while the second one
> "ST_TrajectoryInterpolatePoint()" never returns NULL values and
> interpolates between the values of m.
>
Hi Antonio,
the documentation clearly explainds all; please see:
https://www.gaia-gis.it/gaia-sins/spatialite-sql-5.1.0.html#p14-
1. ST_Locate_Along_Measure()
"Return a derived geometry collection value with elements that
match the specified measure. NULL will be returned if any error
is encountered (or when no element corresponding to the given
measure is found)."
this is exectely what happens in your example; your test
LINESTRING has no Point with M=5, so a NULL will be returned.
going in further depth:
SELECT ST_AsText(ST_Locate_Along_Measure(
ST_GeomFromText('LINESTRING M(0 0 1, 1 1 2, 2 2 1, 3 3 2)'),
1));
----------
MULTIPOINT M(0 0 1, 2 2 1)
SELECT ST_AsText(ST_Locate_Along_Measure(
ST_GeomFromText('LINESTRING M(0 0 1, 1 1 2, 2 2 1, 3 3 2)'),
3));
----------
NULL
2. ST_TrajectoryInterpolatePoint()
"Check if a Geometry corresponds to a valid Trajectory.
a Trajectory is assumed to be a LINESTRING supporting
M-values growing from each vertex to the next.
Return a POINT Geometry being interpolated along the
Geometry (that is expected to be a valid Trajectory)
accordingly to the given M-value."
just few practical examples:
SELECT ST_AsText(ST_TrajectoryInterpolatePoint(
ST_GeomFromText('LINESTRING M(0 0 1, 1 1 2, 2 2 1, 3 3 2)'),
2));
----------------------
NULL
this will fail returning a NULL because the Linestring
is not a valid Trajectory; M-Values are not regularly
growing as required.
SELECT ST_AsText(ST_TrajectoryInterpolatePoint(
ST_GeomFromText('LINESTRING M(0 0 1, 1 1 2, 2 2 3, 3 3 5)'),
4));
------------------------
POINT M(2.5 2.5 4)
in this second attempt a Point has been interpolated
that falls halfway between the values M=3 and M=5
----------------------------------------
Short conclusion: the two functions are completely
different and shoukd not be confused with each other.
ST_Locate_Along_Measure() is kind of a filter intended
to extract all Points with the same M-Value
ST_TrajectoryInterpolatePoint() instead only works if
the M-Values are regularly increasing and in this
case will interpolate a new Point.
Just for your curiosity, this funcion was introduced
to support the analysis of GPS tracks, where eech
Waypoint has its own timestamp that is usually stored
ad the M-Value.
GPS loggers register the sequence of Waypoints at
fixex time intervals (e.g. every 1, 5 or 10 seconds),
but under some circumstances extrapolating intemediate
unrecorded Waypoints is really useful.
bye Sandro