Is there a way to calculate length of linestring from one point to another?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
If I have one linestring and coordinates of two points on that linestring, what is the easiest way to calculate not shortest distance from those two points, but distance over the given road (given linestring) in PostGIS?
So in the given example given linestrin is whole line and I want to calculate length of red line between points A and B.
Any help with this?
postgis postgresql linestring length points
add a comment |Â
up vote
2
down vote
favorite
If I have one linestring and coordinates of two points on that linestring, what is the easiest way to calculate not shortest distance from those two points, but distance over the given road (given linestring) in PostGIS?
So in the given example given linestrin is whole line and I want to calculate length of red line between points A and B.
Any help with this?
postgis postgresql linestring length points
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
If I have one linestring and coordinates of two points on that linestring, what is the easiest way to calculate not shortest distance from those two points, but distance over the given road (given linestring) in PostGIS?
So in the given example given linestrin is whole line and I want to calculate length of red line between points A and B.
Any help with this?
postgis postgresql linestring length points
If I have one linestring and coordinates of two points on that linestring, what is the easiest way to calculate not shortest distance from those two points, but distance over the given road (given linestring) in PostGIS?
So in the given example given linestrin is whole line and I want to calculate length of red line between points A and B.
Any help with this?
postgis postgresql linestring length points
asked Aug 14 at 6:39
Anastasia
132
132
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
This is one way of doing it
Find out how big fraction of the line is between the 2 points with ST_LineLocatePoint and multiply that fraction with the whole length.
SELECT
(ST_LineLocatePoint(l,p2)-ST_LineLocatePoint(l,p1) )*st_length(l) dist_along_line,
st_distance(p1, p2) direct_distance
FROM
(
SELECT 'linestring(1 1, 1 2, 2 2, 5 0, 10 5)'::geometry l,
'point(1 2)'::geometry p1, 'point(5 3)'::geometry p2
) a
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
This is one way of doing it
Find out how big fraction of the line is between the 2 points with ST_LineLocatePoint and multiply that fraction with the whole length.
SELECT
(ST_LineLocatePoint(l,p2)-ST_LineLocatePoint(l,p1) )*st_length(l) dist_along_line,
st_distance(p1, p2) direct_distance
FROM
(
SELECT 'linestring(1 1, 1 2, 2 2, 5 0, 10 5)'::geometry l,
'point(1 2)'::geometry p1, 'point(5 3)'::geometry p2
) a
add a comment |Â
up vote
4
down vote
accepted
This is one way of doing it
Find out how big fraction of the line is between the 2 points with ST_LineLocatePoint and multiply that fraction with the whole length.
SELECT
(ST_LineLocatePoint(l,p2)-ST_LineLocatePoint(l,p1) )*st_length(l) dist_along_line,
st_distance(p1, p2) direct_distance
FROM
(
SELECT 'linestring(1 1, 1 2, 2 2, 5 0, 10 5)'::geometry l,
'point(1 2)'::geometry p1, 'point(5 3)'::geometry p2
) a
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
This is one way of doing it
Find out how big fraction of the line is between the 2 points with ST_LineLocatePoint and multiply that fraction with the whole length.
SELECT
(ST_LineLocatePoint(l,p2)-ST_LineLocatePoint(l,p1) )*st_length(l) dist_along_line,
st_distance(p1, p2) direct_distance
FROM
(
SELECT 'linestring(1 1, 1 2, 2 2, 5 0, 10 5)'::geometry l,
'point(1 2)'::geometry p1, 'point(5 3)'::geometry p2
) a
This is one way of doing it
Find out how big fraction of the line is between the 2 points with ST_LineLocatePoint and multiply that fraction with the whole length.
SELECT
(ST_LineLocatePoint(l,p2)-ST_LineLocatePoint(l,p1) )*st_length(l) dist_along_line,
st_distance(p1, p2) direct_distance
FROM
(
SELECT 'linestring(1 1, 1 2, 2 2, 5 0, 10 5)'::geometry l,
'point(1 2)'::geometry p1, 'point(5 3)'::geometry p2
) a
answered Aug 14 at 7:02
Nicklas Avén
11.3k12539
11.3k12539
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f292684%2fis-there-a-way-to-calculate-length-of-linestring-from-one-point-to-another%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password