I have a geography field stored in my database, holding a linestring path.
I want to move a point n
meters along this linestring, and return the destin
I used Daniel's answer from above, but I had to fix the "func_MoveAlongPath" signature to
CREATE FUNCTION [dbo].[func_MoveAlongPath](@path geography,
@distance **float**,
@index int = 1)
The int would returned wrong results, because it would round the values in the recursive calls. I then converted it into an iterative version, since the recursive one couldn't handle larger distances in the sample data I had:
CREATE FUNCTION [dbo].[func_MoveAlongPathIter](@path geography,
@distance float)
RETURNS geography
AS
BEGIN
DECLARE @index int = 1;
DECLARE @result geography = null;
DECLARE @num_points int = @path.STNumPoints();
DECLARE @dist_to_next float;
DECLARE @comul_distance float = 0;
WHILE (@index < @num_points - 1) AND (@comul_distance < @distance)
BEGIN
SET @dist_to_next = @path.STPointN(@index).STDistance(@path.STPointN(@index + 1));
SET @comul_distance += @dist_to_next;
SET @index += 1;
END
SET @result = [dbo].[func_MoveTowardsPoint](@path.STPointN(@index - 1),
@path.STPointN(@index),
@distance - (@comul_distance - @dist_to_next));
RETURN @result;
END