[postgis-users] topology point - linestring

Stephen Woodbridge woodbri at swoodbridge.com
Tue Jul 12 08:04:26 PDT 2011


On 7/12/2011 10:57 AM, Nicolas Ribot wrote:
>> hi all,
>>
>> within a linear referencing task i need the shortest distances of all points
>> to the linestring.
>> that itself wouldn't be a problem with st_line_locate_point and st_distance,
>> but i also need to know the topological position of the point relative to
>> the linestring (left, right or on the linestring).
>>
>> e.g. the linear referencing tool in ArcGIS indicates the relative location
>> of a point to a line by means of a (un-)signed distance value (the tool
>> returns positive and negative distance values).
>>
>> i haven't found any postgis function yet for this problem.
>> does anyone know of a function which solves this? or a workaround which runs
>> as quick as possible?
>>
>> thanks in advance and
>> best regards,
>>
>> matthias
>
> Hi Matthias,
>
> Maybe st_linecrossingdirection could be used ?
> (http://postgis.refractions.net/documentation/manual-1.5/ST_LineCrossingDirection.html)
> using a tiny linestring composed of one point and a slight translation
> of this point ?


How about st_shortestline [1] this gives you a vector from the point to 
the line, now you can get a vector along you reference line from start 
to that point or that point to the end of the the reference line. If you 
compute the cross product of those to vectors and the sign of the Z 
value of the cross product is positive you point is to the right, 
negative to the left and zero means you are on the line.

I think I would probably wrap this into a stored procedure that returns 
a record like distance|side|point_on_line or something like that.

-Steve

[1] 
http://postgis.refractions.net/documentation/manual-1.5/ST_ShortestLine.html




More information about the postgis-users mailing list