[postgis-users] Left of/Right of test

Randall, Eric ERandall at eriecountygov.org
Tue Jul 23 08:22:12 PDT 2013


I use this.  Works but its quite a few years old,  maybe another way now.




If  line goes from A to B and point is P, 
 
 v = (Ay-By)*Px+(Bx-Ax)*Py+(Ax*By-Bx*Ay)
 
 v>0: "Left"
 v<0: "Right"
 v=0: "On the line" 
(or in front of B / behind A)



select sites_gid, roads_gid, case when
 
(  st_y(st_startpoint(sline)) - st_y(st_endpoint(sline)) ) * st_x(cpoint) 
+  (   st_x(st_endpoint(sline)) -  st_x(st_startpoint(sline))   ) * st_y(cpoint)
+  (  st_x(st_startpoint(sline)) * st_y(st_endpoint(sline)) - st_x(st_endpoint(sline)) 
* st_y(st_startpoint(sline))  ) > 0
 
then 'L' 
 
when
 
(  st_y(st_startpoint(sline)) - st_y(st_endpoint(sline)) ) * st_x(cpoint) 
+  (   st_x(st_endpoint(sline)) -  st_x(st_startpoint(sline))   ) * st_y(cpoint)
+  (  st_x(st_startpoint(sline)) * st_y(st_endpoint(sline)) - st_x(st_endpoint(sline)) 
* st_y(st_startpoint(sline))  ) < 0
 
then 'R'
 
when 
 
(  st_y(st_startpoint(sline)) - st_y(st_endpoint(sline)) ) * st_x(cpoint) 
+  (   st_x(st_endpoint(sline)) -  st_x(st_startpoint(sline))   ) * st_y(cpoint)
+  (  st_x(st_startpoint(sline)) * st_y(st_endpoint(sline)) - st_x(st_endpoint(sline)) 
* st_y(st_startpoint(sline))  ) = 0
 
then null
 
end
 
as side 
 
from ...





Eric Randall,   GIS DB Admin/Analyst
County of Erie, Pa
140 West 6th Street
Room 111
Erie, Pa 16501
Ph. 814-451-6063
Fx. 814-451-7000


L'unica via d'uscita è dentro
--Alice

-----Original Message-----
From: postgis-users-bounces at lists.osgeo.org [mailto:postgis-users-bounces at lists.osgeo.org] On Behalf Of Andreas Neumann
Sent: Tuesday, July 23, 2013 9:54 AM
To: postgis-users at postgis.refractions.net
Subject: [postgis-users] Left of/Right of test

Hi,

I want to test a point if it is left-of or right-of a given LINESTRING.
I found the << >> and &< &> but they do not behave like I expected.

Perhaps it is because they only test on the bounding box level and not on the real geometry?

Is there a left/right of test available on the geometry instead of the bounding box?

Thank you,
Andreas
_______________________________________________
postgis-users mailing list
postgis-users at lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users


More information about the postgis-users mailing list