[postgis-users] Query to select features that are parallel and perpendicular

Denis Rouzaud denis.rouzaud at gmail.com
Mon Feb 6 05:48:11 PST 2012


Hi,

As Sandro suggested, you can use ST_Azimuth.

I tried on myself and came up which a result, there might be a shorter way.

First, I created a view with the azimuth:

CREATE OR REPLACE VIEW azimuth_view AS
     SELECT 
id,ST_Azimuth(ST_PointN(wkb_geometry,1),ST_PointN(wkb_geometry,2))*180/pi() 
AS azimuth FROM mytable;

This supposes you have only 1 segment on each line (of course!)

Then, I test the difference between the azimuth and I give all parallels 
combinations with a given tolerance:

CREATE OR REPLACE VIEW parallel_view AS
     SELECT A1.id, A2.id AS parallel
     FROM azimuth_view A1, azimuth_view A2
     WHERE A1.id != A2.id
       AND (abs(A1.azimuth-A2.azimuth) <= tolerance
        OR  abs(A1.azimuth-A2.azimuth)-360 <= tolerance
        OR  abs(A1.azimuth-A2.azimuth)+360 <= tolerance );

You can do similar for orthogonal lines then.

PS: I tried with modulo but it does not accept double precision, only 
integer. Depending on wanted tolerance, this might not be enough!

Cheers,

Denis


On 02/06/2012 12:45 PM, Sindile Bidla wrote:
> Anyone who can offer advice on on building a query to accomplish the 
> following within the same line feature - roads:
>
> 1. create a new table or view of all line features that are parallel 
> to a selected line feature within the same line feature
>
> 2. create a new table or view of all line features that 
> are perpendicular to a selected line feature within the same line feature
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120206/4be3cfbb/attachment.html>


More information about the postgis-users mailing list