Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to extrapolate from a line segment to find a point on the line but a 3rd of the way 'back', i.e. trying to find point new, given points A and B below:

enter image description here

Given a line, I can interpolate it to get a position at any particular percentage along it:

=# select st_line_interpolate_point(
   st_makeline('0101000020E6100000300DC347C49418C03EE8D9ACFAA44A40', 
               '0101000020E6100000FB743C66A03218C0CDCCCCCCCC7C4A40'), 
   0.333);
0101000020E6100000ED45B41D537718C069C6A2E9EC984A40

I tried entering a negative number to find a point along the line in the opposite direction, but that fails as the interpolation argument has to be in the range [0, 1]

I thought about first scaling the line, but that doesn't use the centre of the line as the origin, so is useless for my purposes.

share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

Another way I have solved a similar problem previously is to break it down into the following steps.

-- get the points A and B given a line L
A := ST_STARTPOINT(L);
B := ST_ENDPOINT(L);

-- get the bearing from point B --> A
azimuth := ST_AZIMUTH(B,A);

-- get the length of the line A --> B
length := ST_DISTANCE(A,B);
newlength := length + (length * (1/3));   -- increase the line length by 1/3

-- create a new point 1/3 as far away from A as B is from A
newpoint := ST_TRANSLATE(A, sin(azimuth) * newlength, cos(azimuth) * newlength);

EDIT: fixed the assignment of newlength so that it is 1 1/3 the length, rather than 1/3 and switched A & B around to match diagram.

share|improve this answer
    
We have a winner! Much more comprehensible. –  EoghanM Sep 10 '12 at 15:34
    
This is pretty cool –  Nathan W Oct 17 '12 at 5:29
    
Thanks. I originally had this snippet from some work I was doing manually interpolating between contour lines - turned out it was a waste of time what I was trying to do with the contours, but glad this this snippet helped someone else out! :) –  Jayden Oct 17 '12 at 6:29
add comment

Have solved it with:

F = 1.3333
st_affine(A, F, 0, 
             0, F, 
            (F-1)*-st_x(st_line_interpolate_point(st_makeline(A, B), 0.5)), 
            (F-1)*-st_y(st_line_interpolate_point(st_makeline(A, B), 0.5))
          )

Explanation:

(2-d) Scale the start point by a factor of 1.3333, taking the midpoint of the line segment as the origin for scaling.

Get out the graph paper!

http://en.wikipedia.org/wiki/Affine_transformation

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.