-- to avoid routing through a big town...town SELECT m.osm_id losmid, m.highway lhighway, case when q.population :: decimal > '1000000' then 1 when q.population :: decimal > '500000' then 0.7 when q.population :: decimal > '150000' then 0.4 else 0.2 end as town_factor FROM planet_osm_line AS m INNER JOIN planet_osm_polygon AS q ON ST_Intersects(m.way, q.way) WHERE m.highway is not null and q.population :: decimal > '80000' order by town_factor desc;