{"word_count": 405, "character_count": 2560}
Recently, I read an article by datapointed&#160;which presented maps of&#160;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.The code is given at the end of the article.Data used in this post is from OpenStreetMap contributors :Get it on&#160;OSM Metro Extract&#160;or&#160;GeoFabrikFirst, polylines are split into lines.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 segmentsThe 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.interpolationFinally, we smooth the continuous surface to get something more pleasant.Interpolated raster &#38; the same, smoothedWe 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 modeHere is the result for Paris :Smoothed result with a kind of halo &#160;(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 codeThe two key functions are :spatstat::angles.psp which compute the angles of segmentsspatstat::idw which interpolates the data.