Recently, I read an article by datapointed which presented maps of streets of different cities colored by orientation.
The author gave some details about the method, which I tried to reproduce. In this post, I present the different steps from the calculation in my favorite spatial R ToolBox to the rendering in QGIS using a specific blending mode.
Data used in this post is from OpenStreetMap contributors :
Get it on OSM Metro Extract or GeoFabrik
In what we want, the orientation is not directed and orthogonal lines are rendered the same way.
This way, all our segments cover just a quarter of a circle and their sine values range from 0 to 1.
We can affect each segment an angle. I classified my angle values in two classes, with punchy base colors.
Actually, values near 0 and 1 correspond to almost equivalent orientations. They correspond to angles near 0 / 90°. The difference of colors is maximal when two streets have a 45° difference of angles. I chose a kind of diverging palette with dark saturated colors near 45° and bright desaturated ones near 0 / 90°. This way, similar angles are given similar brightness values.
Here is the result for our roads :
|Rendering with the inner orientation affected to the segments|
The second part is mostly cosmetic. We’ll use interpolation and smoothing to get a nice halo effect.
First, we generate the mid point of each line and affect the orientation to it.
Next, we process the interpolation by inverse distance weight based on these points and their orientation values.
Finally, we smooth the continuous surface to get something more pleasant.
|Interpolated raster & the same, smoothed|
We export the smoothed raster for a rendering within QGIS.
Here is how I superimposed my layers :
- The raster is put on top with the palette described above and a specific « Overlay » blending mode.
- The roads are put below with a grey value. Note that the grey value affects the final color because of the blending mode.
- Finally, a near black background lets the halo appear slightly.
|How the underlying color affects the final rendering in an overlay blending mode|
Here is the result for Paris :
|Smoothed result with a kind of halo (click to see in large scale)|
I decided to apply the process to a sample of NYC :
|NYC Streets oriented (click to see in large scale)|
Technical details and code
The two key functions are :
spatstat::angles.psp which compute the angles of segments
spatstat::idw which interpolates the data.