[postgis-users] topology point - linestring

matze09 matthias.uden at gmail.com
Tue Jul 12 10:45:00 PDT 2011



Stephen, Nicolas wrote:
> 
>>
>> 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
> 
> 

hi nicolas, hi steve,

thanks a lot for your quick replies. i stumbled over the
st_linecrossingdirection function before but thought
it wouldn't be the most efficient way. well, it certainly isn't but at least
it seems to work.
i included the st_closestpoint function since it might be faster than
st_line_locate_point and st_line_interpolate_point.

the function below takes a point and a linestring as arguments and returns
-1/0/1 according to the topology. it works fine except for points where the
closest point coincides with the 
line's start/endpoint (in that case, the result is always 0 because there is
no intersection.)
will try to fix that later.

for now thanks and all the best,
matthias


CREATE FUNCTION pointToLinePos(geometry,geometry) RETURNS integer
	AS 'SELECT         
(-1)*st_linecrossingdirection(st_makeline($1,st_translate(foo.pt,0.1*st_x(foo.pt)-st_x($1)),0.1*st_y(foo.pt)-st_y($1)))),
$2)
	    FROM ( SELECT st_closestpoint($2,$1) AS pt ) AS foo;'
	LANGUAGE sql
	IMMUTABLE
	RETURNS null on null input;

-- 
View this message in context: http://old.nabble.com/topology-point---linestring-tp32045866p32047820.html
Sent from the PostGIS - User mailing list archive at Nabble.com.




More information about the postgis-users mailing list