NOTICE: is being shutdown on 1st March 2024. Please use the OpenStreetMap Community Forum

Is there a way for Mapnik to render a symbol at every junction? I can't find an obvious rule.

I don't mean each node along a line - just where two lines properly intersect at a junction, on the same level with a joining node (i.e. not say at a bridge).

Mapnik seems to have


but that will presumably give me every node, not purely the junctions.

I'm trying to create a rendering showing where there are proper junctions, not things which appear to be junctions but aren't actually connected properly. (I'm aware that there are great tools like KeepRight for this, but I'm working on custom data that needs such a debugging layer.)

asked 21 Apr '16, 12:54

fooquency's gravatar image

accept rate: 0%

This is not a question of Mapnik being able to do something; the question is whether you can get your data source to compute these locations. (Mapnik's responsibility would then consist of placing an icon there, no more.)

If the data comes from shape files then you're out of luck since there's no geo processing available.

If the data comes from a PostGIS database then you could mark all intersections between two bits of road like this:

SELECT st_intersection(a, b) AS geom
FROM planet_osm_line a, planet_osm_line b
AND b.highway IS NOT NULL
AND st_intersects(a,b);

or substitute your own table and attributes instead of planet_osm_line and highway. Note that while this will be correct in one direction (a road that ends near, instead of on, another road will never show an icon) it is not necessarily correct in the other (an icon shown on the map does not necessarily mean that you can turn into the other road there). That's because the "simple feature" geometries don't have topology and cannot differentiate between two streets actually being connected (i.e. same node id in OSM) and two streets just incidentally being in the same location without being connected (e.g. due to a different z order).

You can correct for some of that by adding stuff like and ((a.bridge is null and b.bridge is null) or (a.bridge=b.bridge)) etc but it is always going to be guesswork.

In the OSM world you could get perfect results by evaluating the planet_osm_ways table which is generated when you run osm2pgsql with --slim, however this is a bit complicated.

permanent link

answered 21 Apr '16, 13:09

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
accept rate: 23%

edited 21 Apr '16, 13:09


You could probably extend this slightly by, after the intersection test on the lines, take the sets of vertices in the linestrings (st_dumppoints) and see if the sets include a common member. That will still have some false positives where OSM ways have independent nodes with identical coordinates, but at least remove almost all the bridges and tunnels where nodes aren't coincident.

(21 Apr '16, 14:26) Andy Allan

Thanks, Frederik and Andy - this is most useful.

(21 Apr '16, 17:47) fooquency

I recently put together a little tool to identify junctions, defined as "any node with more than two highways calling at it". It takes an .osm.pbf as input, and outputs a CSV of lat, lon, and junction type (a compound string enumerating the highway values). It may not slot into your workflow, and it almost certainly requires some tweaking to suit, but you may find it useful:

permanent link

answered 21 Apr '16, 18:08

Richard's gravatar image

Richard ♦
accept rate: 18%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 21 Apr '16, 12:54

question was seen: 2,371 times

last updated: 21 Apr '16, 18:08

NOTICE: is being shutdown on 1st March 2024. Please use the OpenStreetMap Community Forum