I have roads(MultiLineString)
table in postgresql database. The roads are classified based on priority attribute i.e.
priority = 6 for motorway
priority = 5 for highway
priority = 4 for expressway
priority = 3 for major road
priority = 2 for minor road
priority = 1 for street
i need to select all roads that are parallel to motorways(priority = 6)
and are within 50 meters distance from either side.
From the above image, i want to select the green color roads which are parallel to blue color roads.
Update:
i tried using buffer but this also returns the line which is not parallel to the blue line. As shown in the image below, the lines perpendicular to blue lines are also selected as a result.
Best Answer
It would look something like this.
WARNING: This doesn't strictly find parallel "lines." PostGIS is real world and not an abstract modeling tool. It doesn't have a notion of
y=mx+b
to constitute "parallel". This finds linesegments that do not intersect within 50 meters. They can be visually perpendicular non-intersecting lines in the United States and Zimbabwe, and this query will return them.If you need visually parallel line segments defined by two points
This still won't find lines near each other, but they should be parallel. For instance, lines of longitude are parallel with other lines of longitude but they can cross earth as separate points on the geode.
If you need visually parallel lines defined by more than two points: tough. You can either calculate the angle with any two points or you're not talking about a line anyway.
Update with sample data
This is exactly the problem with your description..
Green is the buffer zone 50 meters.
priority=6