1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
 
[out:json][timeout:25];
area(3602774075);
// Get relevant street types in bbox and return nodes that have ways with maximum speed of 50 km/h AND 30 km/h.
way({{bbox}})[highway~"primary|secondary|tertiary|residential|unclassified"][name]->.all;
way.all[maxspeed=30];
node(w)->.slow;
way.all[maxspeed=50];
node(w)->.fast;
node.slow.fast;
// Get ways with 50 km/h touching 30 km/h. Next, we want to get rid of cases where 30 km/h is a street you need to turn in. We approximate that by checking for same street name (which has its limitations).
way(bn)[maxspeed=50]->.candidate;
way.candidate;
foreach->.segment(
  way.segment;
  complete(1)
  {
    node(w);
    way(bn)[highway][maxspeed=30](if:t["name"]==segment.u(t["name"]));
  }
  if(count(ways)>1)
  {
    // For the same street name, there is one segment with 30 km/h touching a segment with 50 km/h. Next, we need to test if extending the 50 km/h ways by a maximum of 500m results in touching another 30 km/h way.
    (._; -way.segment;)->.first30;
    way.segment;
    complete(30)
    {
      node(w);
      way(bn)[highway][maxspeed=50](if:sum(length())<500&&t["name"]==segment.u(t["name"]));
    }
    (._;)->.shortEnough50;
    node(w)->.shortEnough50Nodes;
    
    complete(1)
    {
      node(w);
      way(bn)[highway][maxspeed=30](if:t["name"]==segment.u(t["name"]));
    }
  // Best way to test if 50 km/h street has a 30 km/h segment at its start and end is to count nodes.
    (._;-way.shortEnough50;)->.ending30;
    way.ending30;
    node(w)->.ending30Nodes;
    node.ending30Nodes.shortEnough50Nodes;
    if(count(nodes)>1)
    {  
      // There is a speed change at the beginning and ending of the 50 km/h street section! Output the ways...
      way.ending30;
      out geom;
      way.shortEnough50;
      out geom;     
    }
  }
)
 
{{style:
  way[maxspeed=30]{ color:green; width:7; opacity:0.3; }
  way[maxspeed=50]{ color:red; width:11; opacity:0.7; }
}}
 
300 m
Leaflet © OpenStreetMap contributors
1