[postgis-users] Find similar LINESTRINGs with respect to direction

Alexander Loehr alexander.loehr at web.de
Thu Apr 19 01:00:34 PDT 2007


Hi!

I want to store routes in a PostGIS table with a LINESTRING geometry column:

CREATE TABLE "routes" (id serial PRIMARY KEY);
SELECT AddGeometryColumn('','routes','route','4326','LINESTRING',2);
CREATE INDEX routes_route_idx ON routes USING gist (route);

Further on I want to find routes from this table which are similar to a
given route X using the following statement:

SELECT routes.id FROM routes
 WHERE routes.route && X
       AND intersects(buffer(routes.route,0.0001),buffer(X,0.0001))
 ORDER BY
area(intersection(buffer(routes.route,0.0001),buffer(X,0.0001))) DESC;

I'm able to store the routes in the table and I'm able to find
intersecting routes. I have to say: A wonderful piece of software.

But I have no idea how to take care whether a intersecting route has the
same direction. For example: I have two routes stored in the table with
points A, B and C. One route is LINESTRING('A B C') and the other one is
LINESTRING('C B A'). When X is now LINESTRING('B C') the mentioned
SELECT statement will find both routes. Has someone an idea how to solve
this problem? Or do you think my approach is completely wrong?

Thanks for any reply.

Cheers,
Alex.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: alexander.loehr.vcf
Type: text/x-vcard
Size: 244 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070419/3fdc8a40/attachment.vcf>


More information about the postgis-users mailing list