one label for two-lane roads (osm, qgis, postgis)

To label only one lane of a two-lane road I'm using the expression:

 angle_at_vertex($geometry,1) <= 180

and use it as filter. This works because in OSM each lane is drawn in their direction.

In the example below I'm using the expression angle_at_vertex($geometry,1) as label and in the second picture the expression angle_at_vertex($geometry,1) <= 180 as filter.

Before:

enter image description here

After:

enter image description here

Settings:

enter image description here


I don't know the schema of the OSM tables, but you asked for a query like this:

DELETE FROM labels WHERE label_id  IN (
    SELECT label_id_2 FROM (
        SELECT a.label_id AS label_id_1, b.label_id AS label_id_2 
        FROM labels AS a, labels AS b WHERE STDWithin(a.the_geom,b.the_geom, 0.001) and a.street = b.street and a.label_id != b.label_id
    )
)

This may work but It would be better if you have an id for the same label for different directions, and then this query would work 100%:

DELETE FROM labels WHERE label_id  IN (
    SELECT label_id_2 FROM (
        SELECT a.label_id AS label_id_1, b.label_id AS label_id_2 
        FROM labels AS a, labels AS b WHERE a.same_road_label_id = b.same_road_label_id;
    )
)