@tilda-geo/bicycle-infrastructure 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +15 -0
- package/NOTICE.md +13 -0
- package/README.md +23 -14
- package/dist/index.d.ts +225 -10
- package/dist/index.js +1875 -818
- package/package.json +11 -9
package/dist/index.js
CHANGED
|
@@ -1,132 +1,95 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"tertiary",
|
|
12
|
-
"tertiary_link"
|
|
13
|
-
];
|
|
14
|
-
var MINOR_ROAD_CLASSES = [
|
|
15
|
-
"unclassified",
|
|
16
|
-
"residential",
|
|
17
|
-
"road",
|
|
18
|
-
"living_street",
|
|
19
|
-
"pedestrian",
|
|
20
|
-
"service"
|
|
21
|
-
];
|
|
22
|
-
var PATH_CLASSES = ["track", "path", "footway", "cycleway", "steps"];
|
|
23
|
-
var SIDEPATH_HIGHWAY_CLASSES = /* @__PURE__ */ new Set([...PATH_CLASSES, "pedestrian"]);
|
|
24
|
-
var ALLOWED_HIGHWAYS = /* @__PURE__ */ new Set([
|
|
25
|
-
...TRUNK_MOTORWAY_CLASSES,
|
|
26
|
-
...MAJOR_ROAD_CLASSES,
|
|
27
|
-
...MINOR_ROAD_CLASSES,
|
|
28
|
-
...PATH_CLASSES
|
|
29
|
-
]);
|
|
1
|
+
// src/helpers/sanitize-string.ts
|
|
2
|
+
function sanitizeString(value) {
|
|
3
|
+
if (value == null) return void 0;
|
|
4
|
+
let out = value.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "");
|
|
5
|
+
out = out.replace(
|
|
6
|
+
/<\s*\/?\s*[A-Za-z][^>]*?>/g,
|
|
7
|
+
(tag) => tag.replace(/</g, "(").replace(/>/g, ")")
|
|
8
|
+
);
|
|
9
|
+
return out;
|
|
10
|
+
}
|
|
30
11
|
|
|
31
|
-
// src/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
function unnestPrefixedTags(tags, prefix, infix, dest, metaPrefix) {
|
|
35
|
-
const metaPrefixString = metaPrefix ?? "";
|
|
36
|
-
const fullPrefix = metaPrefixString + prefix + infix;
|
|
37
|
-
const prefixLen = fullPrefix.length;
|
|
38
|
-
for (const key of Object.keys(tags)) {
|
|
39
|
-
const val = tags[key];
|
|
40
|
-
if (val === void 0) continue;
|
|
41
|
-
if (!key.startsWith(fullPrefix)) continue;
|
|
42
|
-
if (key === fullPrefix) {
|
|
43
|
-
const destinationKey = metaPrefix ? metaPrefixString.slice(0, -1) : prefix;
|
|
44
|
-
dest[destinationKey] = val;
|
|
45
|
-
dest._infix = infix;
|
|
46
|
-
} else {
|
|
47
|
-
const extractedSuffix = key.slice(prefixLen + 1);
|
|
48
|
-
const suffixKey = extractedSuffix.match(/^[^:]*/)[0];
|
|
49
|
-
if (infix !== "" || !(suffixKey === "left" || suffixKey === "right" || suffixKey === "both")) {
|
|
50
|
-
const destinationKey = metaPrefix ? metaPrefixString + extractedSuffix : extractedSuffix;
|
|
51
|
-
dest[destinationKey] = val;
|
|
52
|
-
dest._infix = infix;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return dest;
|
|
12
|
+
// src/helpers/sanitize-traffic-sign.ts
|
|
13
|
+
function stripWhitespaces(trafficSign) {
|
|
14
|
+
return trafficSign.replace(/, /g, ",").replace(/; /g, ";");
|
|
57
15
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
function convertDirectedTags(cycleway, directionReference) {
|
|
67
|
-
const parent = cycleway._parent;
|
|
68
|
-
const side = cycleway._side ?? "";
|
|
69
|
-
for (const key of DIRECTED_PARENT_TAGS) {
|
|
70
|
-
const directedKey = key + SIDE_TO_DIRECTION[side];
|
|
71
|
-
cycleway[key] = cycleway[key] ?? parent[key] ?? parent[directedKey];
|
|
16
|
+
function sanitizeValue(value) {
|
|
17
|
+
return sanitizeString(stripWhitespaces(value));
|
|
18
|
+
}
|
|
19
|
+
function sanitizeTrafficSign(trafficSign) {
|
|
20
|
+
if (trafficSign == null) return void 0;
|
|
21
|
+
if (trafficSign === "no" || trafficSign === "none") return "none";
|
|
22
|
+
if (/^DE:\S/.test(trafficSign)) {
|
|
23
|
+
return sanitizeValue(trafficSign);
|
|
72
24
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
25
|
+
const substitutions = [
|
|
26
|
+
[/^DE: /, "DE:"],
|
|
27
|
+
[/^DE\./, "DE:"],
|
|
28
|
+
[/^D:/, "DE:"],
|
|
29
|
+
[/^D\./, "DE:"],
|
|
30
|
+
[/^de:/, "DE:"],
|
|
31
|
+
[/^DE1/, "DE:1"],
|
|
32
|
+
[/^DE2/, "DE:2"],
|
|
33
|
+
[/^2/, "DE:2"],
|
|
34
|
+
[/^1/, "DE:1"]
|
|
35
|
+
];
|
|
36
|
+
for (const [pattern, replacement] of substitutions) {
|
|
37
|
+
if (pattern.test(trafficSign)) {
|
|
38
|
+
return sanitizeValue(trafficSign.replace(pattern, replacement));
|
|
79
39
|
}
|
|
80
40
|
}
|
|
81
|
-
return
|
|
41
|
+
return sanitizeString(trafficSign);
|
|
82
42
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
43
|
+
|
|
44
|
+
// src/derive/derive-traffic-signs.ts
|
|
45
|
+
function deriveTrafficSigns(tags) {
|
|
46
|
+
if (tags == null) {
|
|
47
|
+
return {
|
|
48
|
+
traffic_sign: void 0,
|
|
49
|
+
"traffic_sign:forward": void 0,
|
|
50
|
+
"traffic_sign:backward": void 0
|
|
51
|
+
};
|
|
92
52
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
unnestPrefixedTags(tags, prefix, "", newObj, mp);
|
|
110
|
-
unnestPrefixedTags(tags, prefix, ":both", newObj, mp);
|
|
111
|
-
unnestPrefixedTags(tags, prefix, `:${side}`, newObj, mp);
|
|
112
|
-
}
|
|
113
|
-
if (newObj._infix !== void 0 && transformation.filter(newObj)) {
|
|
114
|
-
convertDirectedTags(newObj, transformation.direction_reference);
|
|
115
|
-
results.push(newObj);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
53
|
+
return {
|
|
54
|
+
traffic_sign: sanitizeTrafficSign(tags.traffic_sign ?? tags["traffic_sign:both"]),
|
|
55
|
+
"traffic_sign:forward": sanitizeTrafficSign(tags["traffic_sign:forward"]),
|
|
56
|
+
"traffic_sign:backward": sanitizeTrafficSign(tags["traffic_sign:backward"])
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/helpers/extract-value-from-lanes.ts
|
|
61
|
+
function parseLanesValue(lanesValue) {
|
|
62
|
+
return lanesValue.split("|");
|
|
63
|
+
}
|
|
64
|
+
function findLaneIndex(tags) {
|
|
65
|
+
const cyclewayLanes = tags["cycleway:lanes"];
|
|
66
|
+
if (cyclewayLanes != null) {
|
|
67
|
+
const i = parseLanesValue(cyclewayLanes).indexOf("lane");
|
|
68
|
+
if (i !== -1) return i;
|
|
118
69
|
}
|
|
119
|
-
|
|
70
|
+
const bicycleLanes = tags["bicycle:lanes"];
|
|
71
|
+
if (bicycleLanes != null) {
|
|
72
|
+
const i = parseLanesValue(bicycleLanes).indexOf("designated");
|
|
73
|
+
if (i !== -1) return i;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
120
76
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
77
|
+
function extractValueFromLanes(lanesTag, tags) {
|
|
78
|
+
const laneIndex = findLaneIndex(tags);
|
|
79
|
+
if (laneIndex == null) return void 0;
|
|
80
|
+
const raw = tags[lanesTag];
|
|
81
|
+
if (raw != null) {
|
|
82
|
+
const values = parseLanesValue(raw);
|
|
83
|
+
if (values[laneIndex] != null && values[laneIndex] !== "") return values[laneIndex];
|
|
128
84
|
}
|
|
129
|
-
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
function extractLastValueFromLanes(lanesValue) {
|
|
88
|
+
if (lanesValue == null) return void 0;
|
|
89
|
+
const lanes = parseLanesValue(lanesValue);
|
|
90
|
+
if (lanes.length > 0) return lanes[lanes.length - 1];
|
|
91
|
+
return void 0;
|
|
92
|
+
}
|
|
130
93
|
|
|
131
94
|
// src/helpers/strings.ts
|
|
132
95
|
function containsSubstring(str, subStr) {
|
|
@@ -150,128 +113,66 @@ function hasTagWithPrefix(tags, prefix) {
|
|
|
150
113
|
return false;
|
|
151
114
|
}
|
|
152
115
|
|
|
153
|
-
// src/transform/prepare-tags.ts
|
|
154
|
-
function toSemicolonList(parts) {
|
|
155
|
-
return parts.filter((p) => p != null && p !== "").join("; ");
|
|
156
|
-
}
|
|
157
|
-
function restrictedAccessTags(tags) {
|
|
158
|
-
const restricted = [];
|
|
159
|
-
if (tags.access === "no") restricted.push("access");
|
|
160
|
-
if (tags.highway === "cycleway" && tags.bicycle === "no") restricted.push("bicycle");
|
|
161
|
-
if (tags.highway === "footway" && tags.foot === "no") restricted.push("foot");
|
|
162
|
-
return restricted;
|
|
163
|
-
}
|
|
164
|
-
function transformLifecycleTags(tags) {
|
|
165
|
-
if (!tags.highway) return;
|
|
166
|
-
if (tags.construction != null && ALLOWED_HIGHWAYS.has(tags.construction)) {
|
|
167
|
-
tags.highway = tags.construction;
|
|
168
|
-
tags.lifecycle = "construction";
|
|
169
|
-
tags.construction = void 0;
|
|
170
|
-
}
|
|
171
|
-
const constructionRestricted = restrictedAccessTags(tags);
|
|
172
|
-
if (constructionRestricted.length > 0) {
|
|
173
|
-
const text = `${tags["access:reason"] ?? ""} ${tags.description ?? ""} ${tags.note ?? ""}`.toLowerCase();
|
|
174
|
-
if (containsSubstring(text, "construction") || containsSubstring(text, "baustelle")) {
|
|
175
|
-
tags.lifecycle = "construction_no_access";
|
|
176
|
-
tags.description = toSemicolonList([tags.description, "TILDA-Hinweis: Weg gesperrt aufgrund einer Baustelle."]);
|
|
177
|
-
for (const t of constructionRestricted) tags[t] = void 0;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
const blockedTerms = ["sperrung", "gesperrt", "blockiert", "blocked", "closure", "closed", "blocked off"];
|
|
181
|
-
const blockedRestricted = restrictedAccessTags(tags);
|
|
182
|
-
if (blockedRestricted.length > 0) {
|
|
183
|
-
const text = `${tags.description ?? ""} ${tags.note ?? ""}`.toLowerCase();
|
|
184
|
-
if (blockedTerms.some((term) => containsSubstring(text, term))) {
|
|
185
|
-
tags.lifecycle = "blocked";
|
|
186
|
-
tags.description = toSemicolonList([tags.description, "TILDA-Hinweis: Weg gesperrt (Sperrung)."]);
|
|
187
|
-
for (const t of blockedRestricted) tags[t] = void 0;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
function transformCyclewayOppositeSchema(tags) {
|
|
192
|
-
if (tags.oneway !== "yes") return;
|
|
193
|
-
if (tags.cycleway === "opposite") {
|
|
194
|
-
tags.cycleway = "no";
|
|
195
|
-
tags["oneway:bicycle"] = "no";
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (tags.cycleway === "opposite_lane") {
|
|
199
|
-
tags.cycleway = void 0;
|
|
200
|
-
tags["cycleway:right"] = "no";
|
|
201
|
-
tags["cycleway:left"] = "lane";
|
|
202
|
-
tags["oneway:bicycle"] = "no";
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
if (tags.cycleway === "opposite_track") {
|
|
206
|
-
tags.cycleway = void 0;
|
|
207
|
-
tags["cycleway:right"] = "no";
|
|
208
|
-
tags["cycleway:left"] = "track";
|
|
209
|
-
tags["oneway:bicycle"] = "no";
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
function transformConstructionPrefix(tags) {
|
|
213
|
-
const constructionKeys = [];
|
|
214
|
-
for (const key of Object.keys(tags)) {
|
|
215
|
-
const value = tags[key];
|
|
216
|
-
if (value !== void 0 && key.startsWith("construction:")) constructionKeys.push([key, value]);
|
|
217
|
-
}
|
|
218
|
-
for (const [key, value] of constructionKeys) {
|
|
219
|
-
const baseTag = key.slice("construction:".length);
|
|
220
|
-
tags[baseTag] = value;
|
|
221
|
-
tags[key] = void 0;
|
|
222
|
-
if (baseTag.startsWith("cycleway:") || baseTag.startsWith("sidewalk:")) {
|
|
223
|
-
tags[`${baseTag}:lifecycle`] = "construction";
|
|
224
|
-
} else {
|
|
225
|
-
tags.lifecycle = "construction";
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
function transformCyclewayBothPostfix(tags) {
|
|
230
|
-
if (tags.cycleway === "no" && tags["cycleway:both"] == null && tags["cycleway:left"] == null && tags["cycleway:right"] == null) {
|
|
231
|
-
tags["cycleway:both"] = "no";
|
|
232
|
-
tags.cycleway = void 0;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
function prepareTags(tags) {
|
|
236
|
-
transformLifecycleTags(tags);
|
|
237
|
-
transformCyclewayOppositeSchema(tags);
|
|
238
|
-
transformConstructionPrefix(tags);
|
|
239
|
-
transformCyclewayBothPostfix(tags);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// src/helpers/sanitize-for-logging.ts
|
|
243
|
-
function sanitizeForLogging(value, allowed, ignored = []) {
|
|
244
|
-
if (value == null) return void 0;
|
|
245
|
-
if (allowed.includes(value)) return value;
|
|
246
|
-
if (ignored.includes(value)) return void 0;
|
|
247
|
-
return DISALLOWED;
|
|
248
|
-
}
|
|
249
|
-
function removeDisallowedValue(value) {
|
|
250
|
-
return value === DISALLOWED ? void 0 : value;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
116
|
// src/helpers/parse-length.ts
|
|
117
|
+
var DECIMAL_COMMA_VALUES = {
|
|
118
|
+
"0,3": "0.3",
|
|
119
|
+
"0,5": "0.5",
|
|
120
|
+
"0,6": "0.6",
|
|
121
|
+
"1,5": "1.5",
|
|
122
|
+
"2,2": "2.2",
|
|
123
|
+
"2,5": "2.5",
|
|
124
|
+
"2,50": "2.50"
|
|
125
|
+
};
|
|
254
126
|
function splitUnit(str) {
|
|
255
|
-
if (str == null) return null;
|
|
256
127
|
const m = str.match(/^(-?[0-9.]+) ?([A-Za-z]*)$/);
|
|
257
128
|
if (!m) return null;
|
|
258
129
|
const val = Number(m[1]);
|
|
259
130
|
if (Number.isNaN(val)) return null;
|
|
260
|
-
|
|
261
|
-
return [val, unit];
|
|
131
|
+
return [val === 0 ? 0 : val, m[2] || "m"];
|
|
262
132
|
}
|
|
263
133
|
function parseLength(length) {
|
|
264
134
|
if (length == null) return void 0;
|
|
265
|
-
const
|
|
135
|
+
const key = String(length);
|
|
136
|
+
const parsed = splitUnit(DECIMAL_COMMA_VALUES[key] ?? key);
|
|
266
137
|
if (!parsed) return void 0;
|
|
267
138
|
const [val, unit] = parsed;
|
|
139
|
+
if (val < 0) return void 0;
|
|
268
140
|
if (unit === "cm") return val / 100;
|
|
269
141
|
if (unit === "m") return val;
|
|
270
142
|
if (unit === "km") return val * 1e3;
|
|
271
143
|
return void 0;
|
|
272
144
|
}
|
|
145
|
+
function parseWidth(width) {
|
|
146
|
+
const value = parseLength(width);
|
|
147
|
+
return value !== void 0 && value > 0 ? value : void 0;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/types.ts
|
|
151
|
+
var DISALLOWED = "DISALLOWED_VALUE";
|
|
152
|
+
|
|
153
|
+
// src/helpers/sanitize-for-logging.ts
|
|
154
|
+
function sanitizeForLogging(value, allowed, ignored = []) {
|
|
155
|
+
if (value == null) return void 0;
|
|
156
|
+
if (allowed.includes(value)) return value;
|
|
157
|
+
if (ignored.includes(value)) return void 0;
|
|
158
|
+
return DISALLOWED;
|
|
159
|
+
}
|
|
160
|
+
function removeDisallowedValue(value) {
|
|
161
|
+
return value === DISALLOWED ? void 0 : value;
|
|
162
|
+
}
|
|
273
163
|
|
|
274
164
|
// src/sanitize/sanitize-road-tags.ts
|
|
165
|
+
var PROTECTIVE_SEPARATION = [
|
|
166
|
+
"bollard",
|
|
167
|
+
"flex_post",
|
|
168
|
+
"vertical_panel",
|
|
169
|
+
"studs",
|
|
170
|
+
"bump",
|
|
171
|
+
"planter",
|
|
172
|
+
"fence",
|
|
173
|
+
"jersey_barrier",
|
|
174
|
+
"guard_rail"
|
|
175
|
+
];
|
|
275
176
|
var SEPARATION_ALLOWED = [
|
|
276
177
|
"no",
|
|
277
178
|
"bollard",
|
|
@@ -302,7 +203,14 @@ var MARKING_ALLOWED = [
|
|
|
302
203
|
"pictogram",
|
|
303
204
|
"surface"
|
|
304
205
|
];
|
|
305
|
-
var TRAFFIC_MODE_ALLOWED = [
|
|
206
|
+
var TRAFFIC_MODE_ALLOWED = [
|
|
207
|
+
"no",
|
|
208
|
+
"motor_vehicle",
|
|
209
|
+
"parking",
|
|
210
|
+
"psv",
|
|
211
|
+
"bicycle",
|
|
212
|
+
"foot"
|
|
213
|
+
];
|
|
306
214
|
var SURFACE_COLOR_ALLOWED = ["red", "green", "red;green", "no"];
|
|
307
215
|
function sided(tags, base, side) {
|
|
308
216
|
let value = tags[`${base}:${side}`] ?? tags[`${base}:both`];
|
|
@@ -371,266 +279,7 @@ var SIDED_SANITIZERS = {
|
|
|
371
279
|
marking,
|
|
372
280
|
traffic_mode: trafficMode,
|
|
373
281
|
buffer
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
// src/categories/decision-view.ts
|
|
377
|
-
var IS_DECISION_VIEW = /* @__PURE__ */ Symbol("isDecisionView");
|
|
378
|
-
function resolveSided(source, key) {
|
|
379
|
-
let base;
|
|
380
|
-
let side;
|
|
381
|
-
if (key.endsWith("_left")) {
|
|
382
|
-
base = key.slice(0, -"_left".length);
|
|
383
|
-
side = "left";
|
|
384
|
-
} else if (key.endsWith("_right")) {
|
|
385
|
-
base = key.slice(0, -"_right".length);
|
|
386
|
-
side = "right";
|
|
387
|
-
}
|
|
388
|
-
if (base === void 0 || side === void 0) return { handled: false };
|
|
389
|
-
const sanitizer = SIDED_SANITIZERS[base];
|
|
390
|
-
if (!sanitizer) return { handled: false };
|
|
391
|
-
const value = sanitizer(source, side);
|
|
392
|
-
if (value === DISALLOWED) return { handled: true, value: void 0 };
|
|
393
|
-
return { handled: true, value };
|
|
394
|
-
}
|
|
395
|
-
function decisionTagsView(source) {
|
|
396
|
-
if (source[IS_DECISION_VIEW]) return source;
|
|
397
|
-
return new Proxy(source, {
|
|
398
|
-
get(target, key) {
|
|
399
|
-
if (key === IS_DECISION_VIEW) return true;
|
|
400
|
-
if (typeof key !== "string") return target[key];
|
|
401
|
-
const sided2 = resolveSided(target, key);
|
|
402
|
-
if (sided2.handled) return sided2.value;
|
|
403
|
-
const value = target[key];
|
|
404
|
-
return value === DISALLOWED ? void 0 : value;
|
|
405
|
-
},
|
|
406
|
-
set(target, key, value) {
|
|
407
|
-
if (typeof key === "string") target[key] = value;
|
|
408
|
-
else target[key] = value;
|
|
409
|
-
return true;
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// src/categories/tag-predicate.ts
|
|
415
|
-
var pred = {
|
|
416
|
-
eq: (key, value) => ({ op: "eq", key, value }),
|
|
417
|
-
neq: (key, value) => ({ op: "neq", key, value }),
|
|
418
|
-
in: (key, values) => ({ op: "in", key, values }),
|
|
419
|
-
notIn: (key, values) => ({ op: "notIn", key, values }),
|
|
420
|
-
exists: (key) => ({ op: "exists", key }),
|
|
421
|
-
notExists: (key) => ({ op: "notExists", key }),
|
|
422
|
-
includes: (key, substring) => ({ op: "includes", key, substring }),
|
|
423
|
-
hasPrefix: (key, prefix) => ({ op: "hasPrefix", key, prefix }),
|
|
424
|
-
hasSuffix: (key, suffix) => ({ op: "hasSuffix", key, suffix }),
|
|
425
|
-
hasTagWithPrefix: (prefix) => ({ op: "hasTagWithPrefix", prefix }),
|
|
426
|
-
and: (...predicates) => ({ op: "and", predicates }),
|
|
427
|
-
or: (...predicates) => ({ op: "or", predicates }),
|
|
428
|
-
not: (predicate) => ({ op: "not", predicate }),
|
|
429
|
-
macro: (name) => ({ op: "macro", name }),
|
|
430
|
-
literal: (value) => ({ op: "literal", value })
|
|
431
|
-
};
|
|
432
|
-
function tagValue(tags, key) {
|
|
433
|
-
return tags[key];
|
|
434
|
-
}
|
|
435
|
-
function evalPredicate(tags, predicate, macros) {
|
|
436
|
-
switch (predicate.op) {
|
|
437
|
-
case "eq":
|
|
438
|
-
return tagValue(tags, predicate.key) === predicate.value || void 0;
|
|
439
|
-
case "neq":
|
|
440
|
-
return tagValue(tags, predicate.key) !== predicate.value || void 0;
|
|
441
|
-
case "in": {
|
|
442
|
-
const v = tagValue(tags, predicate.key);
|
|
443
|
-
return v != null && predicate.values.includes(v) || void 0;
|
|
444
|
-
}
|
|
445
|
-
case "notIn": {
|
|
446
|
-
const v = tagValue(tags, predicate.key);
|
|
447
|
-
return v != null && !predicate.values.includes(v) || void 0;
|
|
448
|
-
}
|
|
449
|
-
case "exists":
|
|
450
|
-
return tagValue(tags, predicate.key) != null || void 0;
|
|
451
|
-
case "notExists":
|
|
452
|
-
return tagValue(tags, predicate.key) == null || void 0;
|
|
453
|
-
case "includes":
|
|
454
|
-
return containsSubstring(tagValue(tags, predicate.key), predicate.substring) || void 0;
|
|
455
|
-
case "hasPrefix":
|
|
456
|
-
return hasPrefix(tagValue(tags, predicate.key), predicate.prefix) || void 0;
|
|
457
|
-
case "hasSuffix":
|
|
458
|
-
return hasSuffix(tagValue(tags, predicate.key), predicate.suffix) || void 0;
|
|
459
|
-
case "hasTagWithPrefix":
|
|
460
|
-
return hasTagWithPrefix(tags, predicate.prefix) || void 0;
|
|
461
|
-
case "and": {
|
|
462
|
-
let hasUndefined = false;
|
|
463
|
-
for (const child of predicate.predicates) {
|
|
464
|
-
const r = evalPredicate(tags, child, macros);
|
|
465
|
-
if (r === false) return false;
|
|
466
|
-
if (r !== true) hasUndefined = true;
|
|
467
|
-
}
|
|
468
|
-
return hasUndefined ? void 0 : true;
|
|
469
|
-
}
|
|
470
|
-
case "or": {
|
|
471
|
-
let hasUndefined = false;
|
|
472
|
-
for (const child of predicate.predicates) {
|
|
473
|
-
const r = evalPredicate(tags, child, macros);
|
|
474
|
-
if (r === true) return true;
|
|
475
|
-
if (r !== false) hasUndefined = true;
|
|
476
|
-
}
|
|
477
|
-
return hasUndefined ? void 0 : false;
|
|
478
|
-
}
|
|
479
|
-
case "not": {
|
|
480
|
-
const r = evalPredicate(tags, predicate.predicate, macros);
|
|
481
|
-
if (r === true) return false;
|
|
482
|
-
if (r === false) return true;
|
|
483
|
-
return void 0;
|
|
484
|
-
}
|
|
485
|
-
case "macro": {
|
|
486
|
-
const fn = macros[predicate.name];
|
|
487
|
-
if (!fn) throw new Error(`Unknown predicate macro: ${predicate.name}`);
|
|
488
|
-
return fn(tags);
|
|
489
|
-
}
|
|
490
|
-
case "literal":
|
|
491
|
-
return predicate.value;
|
|
492
|
-
default: {
|
|
493
|
-
const _exhaustive = predicate;
|
|
494
|
-
throw new Error(`Unknown predicate op: ${_exhaustive.op}`);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
function evalPredicateStrict(tags, predicate, macros) {
|
|
499
|
-
const r = evalPredicate(tags, predicate, macros);
|
|
500
|
-
return r === true;
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// src/helpers/extract-value-from-lanes.ts
|
|
504
|
-
function parseLanesValue(lanesValue) {
|
|
505
|
-
return lanesValue.split("|");
|
|
506
|
-
}
|
|
507
|
-
function findLaneIndex(tags) {
|
|
508
|
-
const cyclewayLanes = tags["cycleway:lanes"];
|
|
509
|
-
if (cyclewayLanes != null) {
|
|
510
|
-
const i = parseLanesValue(cyclewayLanes).indexOf("lane");
|
|
511
|
-
if (i !== -1) return i;
|
|
512
|
-
}
|
|
513
|
-
const bicycleLanes = tags["bicycle:lanes"];
|
|
514
|
-
if (bicycleLanes != null) {
|
|
515
|
-
const i = parseLanesValue(bicycleLanes).indexOf("designated");
|
|
516
|
-
if (i !== -1) return i;
|
|
517
|
-
}
|
|
518
|
-
return null;
|
|
519
|
-
}
|
|
520
|
-
function extractValueFromLanes(lanesTag, tags) {
|
|
521
|
-
const laneIndex = findLaneIndex(tags);
|
|
522
|
-
if (laneIndex == null) return void 0;
|
|
523
|
-
const raw = tags[lanesTag];
|
|
524
|
-
if (raw != null) {
|
|
525
|
-
const values = parseLanesValue(raw);
|
|
526
|
-
if (values[laneIndex] != null && values[laneIndex] !== "") return values[laneIndex];
|
|
527
|
-
}
|
|
528
|
-
return void 0;
|
|
529
|
-
}
|
|
530
|
-
function extractLastValueFromLanes(lanesValue) {
|
|
531
|
-
if (lanesValue == null) return void 0;
|
|
532
|
-
const lanes = parseLanesValue(lanesValue);
|
|
533
|
-
if (lanes.length > 0) return lanes[lanes.length - 1];
|
|
534
|
-
return void 0;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
// src/helpers/sanitize-string.ts
|
|
538
|
-
function sanitizeString(value) {
|
|
539
|
-
if (value == null) return void 0;
|
|
540
|
-
let out = value.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "");
|
|
541
|
-
out = out.replace(/<\s*\/?\s*[A-Za-z][^>]*?>/g, (tag) => tag.replace(/</g, "(").replace(/>/g, ")"));
|
|
542
|
-
return out;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
// src/helpers/sanitize-traffic-sign.ts
|
|
546
|
-
function stripWhitespaces(trafficSign) {
|
|
547
|
-
return trafficSign.replace(/, /g, ",").replace(/; /g, ";");
|
|
548
|
-
}
|
|
549
|
-
function sanitizeValue(value) {
|
|
550
|
-
return sanitizeString(stripWhitespaces(value));
|
|
551
|
-
}
|
|
552
|
-
function sanitizeTrafficSign(trafficSign) {
|
|
553
|
-
if (trafficSign == null) return void 0;
|
|
554
|
-
if (trafficSign === "no" || trafficSign === "none") return "none";
|
|
555
|
-
if (/^DE:\S/.test(trafficSign)) {
|
|
556
|
-
return sanitizeValue(trafficSign);
|
|
557
|
-
}
|
|
558
|
-
const substitutions = [
|
|
559
|
-
[/^DE: /, "DE:"],
|
|
560
|
-
[/^DE\./, "DE:"],
|
|
561
|
-
[/^D:/, "DE:"],
|
|
562
|
-
[/^D\./, "DE:"],
|
|
563
|
-
[/^de:/, "DE:"],
|
|
564
|
-
[/^DE1/, "DE:1"],
|
|
565
|
-
[/^DE2/, "DE:2"],
|
|
566
|
-
[/^2/, "DE:2"],
|
|
567
|
-
[/^1/, "DE:1"]
|
|
568
|
-
];
|
|
569
|
-
for (const [pattern, replacement] of substitutions) {
|
|
570
|
-
if (pattern.test(trafficSign)) {
|
|
571
|
-
return sanitizeValue(trafficSign.replace(pattern, replacement));
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
return sanitizeString(trafficSign);
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// src/derive/derive-traffic-signs.ts
|
|
578
|
-
function deriveTrafficSigns(tags) {
|
|
579
|
-
if (tags == null) {
|
|
580
|
-
return { traffic_sign: void 0, "traffic_sign:forward": void 0, "traffic_sign:backward": void 0 };
|
|
581
|
-
}
|
|
582
|
-
return {
|
|
583
|
-
traffic_sign: sanitizeTrafficSign(tags.traffic_sign ?? tags["traffic_sign:both"]),
|
|
584
|
-
"traffic_sign:forward": sanitizeTrafficSign(tags["traffic_sign:forward"]),
|
|
585
|
-
"traffic_sign:backward": sanitizeTrafficSign(tags["traffic_sign:backward"])
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
// src/categories/refine-predicates.ts
|
|
590
|
-
var CATEGORY_IS_SIDEPATH_PRED = pred.or(
|
|
591
|
-
pred.eq("is_sidepath", "yes"),
|
|
592
|
-
pred.exists("_parent_highway"),
|
|
593
|
-
pred.eq("footway", "sidewalk"),
|
|
594
|
-
pred.eq("path", "sidewalk"),
|
|
595
|
-
pred.eq("path", "sidepath"),
|
|
596
|
-
pred.eq("cycleway", "sidepath"),
|
|
597
|
-
pred.eq("steps", "sidewalk")
|
|
598
|
-
);
|
|
599
|
-
var SIDEPATH_ADJOINING_PRED = pred.and(
|
|
600
|
-
CATEGORY_IS_SIDEPATH_PRED,
|
|
601
|
-
pred.neq("is_sidepath", "no")
|
|
602
|
-
);
|
|
603
|
-
var SIDEPATH_ISOLATED_PRED = pred.or(
|
|
604
|
-
pred.eq("is_sidepath", "no"),
|
|
605
|
-
pred.eq("highway", "service"),
|
|
606
|
-
pred.eq("highway", "track")
|
|
607
|
-
);
|
|
608
|
-
var SIDEPATH_UNKNOWN_PRED = pred.and(
|
|
609
|
-
pred.neq("is_sidepath", "yes"),
|
|
610
|
-
pred.notExists("_parent_highway"),
|
|
611
|
-
pred.neq("footway", "sidewalk"),
|
|
612
|
-
pred.neq("path", "sidewalk"),
|
|
613
|
-
pred.neq("path", "sidepath"),
|
|
614
|
-
pred.neq("cycleway", "sidepath"),
|
|
615
|
-
pred.neq("steps", "sidewalk"),
|
|
616
|
-
pred.neq("is_sidepath", "no"),
|
|
617
|
-
pred.notIn("highway", ["service", "track"])
|
|
618
|
-
);
|
|
619
|
-
function advisoryOrExclusiveRefining(laneKey = "lane") {
|
|
620
|
-
return [
|
|
621
|
-
{ idSuffix: "_advisory", match: pred.eq(laneKey, "advisory"), implicitOneWayConfidence: "high" },
|
|
622
|
-
{ idSuffix: "_exclusive", match: pred.eq(laneKey, "exclusive"), implicitOneWayConfidence: "high" },
|
|
623
|
-
{
|
|
624
|
-
idSuffix: "_advisoryOrExclusive",
|
|
625
|
-
match: pred.or(pred.notExists(laneKey), pred.notIn(laneKey, ["advisory", "exclusive"]))
|
|
626
|
-
}
|
|
627
|
-
];
|
|
628
|
-
}
|
|
629
|
-
var ADJOINING_OR_ISOLATED_REFINING = [
|
|
630
|
-
{ idSuffix: "_adjoining", match: SIDEPATH_ADJOINING_PRED },
|
|
631
|
-
{ idSuffix: "_isolated", match: SIDEPATH_ISOLATED_PRED },
|
|
632
|
-
{ idSuffix: "_adjoiningOrIsolated", match: SIDEPATH_UNKNOWN_PRED }
|
|
633
|
-
];
|
|
282
|
+
};
|
|
634
283
|
|
|
635
284
|
// src/categories/category-is-sidepath.ts
|
|
636
285
|
function categoryIsSidepath(tags) {
|
|
@@ -644,15 +293,20 @@ function hasBetweenLanesConditions(tags) {
|
|
|
644
293
|
if (containsSubstring(tags["cycleway:lanes"], "|lane|")) return true;
|
|
645
294
|
if (containsSubstring(tags["bicycle:lanes"], "|designated|")) return true;
|
|
646
295
|
if (containsSubstring(tags.lanes, "|lane|")) return true;
|
|
647
|
-
if (tags._parent && containsSubstring(tags._parent["bicycle:lanes"], "|designated|"))
|
|
296
|
+
if (tags._parent && containsSubstring(tags._parent["bicycle:lanes"], "|designated|"))
|
|
297
|
+
return true;
|
|
648
298
|
}
|
|
649
299
|
return false;
|
|
650
300
|
}
|
|
651
301
|
function isCrossingPattern(tags) {
|
|
652
|
-
if (tags.highway === "cycleway" && tags.cycleway === "lane" && tags.lane === "crossing")
|
|
653
|
-
|
|
654
|
-
if (tags.highway === "
|
|
655
|
-
|
|
302
|
+
if (tags.highway === "cycleway" && tags.cycleway === "lane" && tags.lane === "crossing")
|
|
303
|
+
return true;
|
|
304
|
+
if (tags.highway === "cycleway" && (tags.cycleway === "crossing" || tags.cycleway === "traffic_island"))
|
|
305
|
+
return true;
|
|
306
|
+
if (tags.highway === "path" && (tags.path === "crossing" || tags.path === "traffic_island") && (tags.bicycle === "yes" || tags.bicycle === "designated"))
|
|
307
|
+
return true;
|
|
308
|
+
if (tags.highway === "footway" && (tags.footway === "crossing" || tags.footway === "traffic_island") && (tags.bicycle === "yes" || tags.bicycle === "designated"))
|
|
309
|
+
return true;
|
|
656
310
|
return false;
|
|
657
311
|
}
|
|
658
312
|
function bicycleRoadBase(tags) {
|
|
@@ -665,8 +319,16 @@ function bicycleRoadVehicleDestination(tags) {
|
|
|
665
319
|
if (!bicycleRoadBase(tags)) return void 0;
|
|
666
320
|
const trafficSign = sanitizeTrafficSign(tags.traffic_sign);
|
|
667
321
|
if (containsSubstring(trafficSign, "1020-30")) return true;
|
|
668
|
-
if (containsSubstring(trafficSign, "Kraftfahrzeuge-frei") || containsSubstring(trafficSign, "Kfz-Verkehr frei") || containsSubstring(trafficSign, "KFZ frei"))
|
|
669
|
-
|
|
322
|
+
if (containsSubstring(trafficSign, "Kraftfahrzeuge-frei") || containsSubstring(trafficSign, "Kfz-Verkehr frei") || containsSubstring(trafficSign, "KFZ frei"))
|
|
323
|
+
return true;
|
|
324
|
+
if (tags.vehicle === "destination" || tags.motor_vehicle === "destination" || tags.vehicle === "yes" || tags.motor_vehicle === "yes")
|
|
325
|
+
return true;
|
|
326
|
+
return void 0;
|
|
327
|
+
}
|
|
328
|
+
function unsignedCycleway(tags) {
|
|
329
|
+
if (tags.highway === "cycleway" && sanitizeTrafficSign(tags.traffic_sign) === "none" && // the side object of a lane between the car lanes (tilda-geo 34fb8457d)
|
|
330
|
+
!hasBetweenLanesConditions(tags))
|
|
331
|
+
return true;
|
|
670
332
|
return void 0;
|
|
671
333
|
}
|
|
672
334
|
function footwayBicycleYes(tags) {
|
|
@@ -689,15 +351,16 @@ function crossing(tags) {
|
|
|
689
351
|
}
|
|
690
352
|
function implicitOneWay(tags) {
|
|
691
353
|
let result = tags._prefix === "cycleway" && tags._infix === "";
|
|
692
|
-
result = result && tags._parent?.
|
|
693
|
-
result = result && tags._side === "left";
|
|
354
|
+
result = result && tags._parent?.["oneway:bicycle"] !== "no";
|
|
355
|
+
result = result && (tags._parent?.oneway === "yes" && tags._side === "left" || tags._parent?.oneway === "-1" && tags._side === "right");
|
|
694
356
|
return result || void 0;
|
|
695
357
|
}
|
|
696
358
|
function cyclewayOnHighwayAdvisoryOrExclusiveBase(tags) {
|
|
697
359
|
if (tags.highway === "cycleway") {
|
|
698
360
|
if (hasBetweenLanesConditions(tags)) {
|
|
699
361
|
if (containsSubstring(tags.lanes, "|lane|") && !hasSuffix(tags.lanes, "|lane")) return false;
|
|
700
|
-
if (tags._parent != null && containsSubstring(tags._parent["bicycle:lanes"], "|designated|") && !hasSuffix(tags._parent["bicycle:lanes"], "|designated"))
|
|
362
|
+
if (tags._parent != null && containsSubstring(tags._parent["bicycle:lanes"], "|designated|") && !hasSuffix(tags._parent["bicycle:lanes"], "|designated"))
|
|
363
|
+
return false;
|
|
701
364
|
const sourceWidth = tags._parent ? extractLastValueFromLanes(tags._parent["width:lanes"]) : void 0;
|
|
702
365
|
tags.width = tags.width ?? sourceWidth;
|
|
703
366
|
}
|
|
@@ -717,17 +380,7 @@ function cyclewayOnHighwayProtected(tags) {
|
|
|
717
380
|
if (!categoryIsSidepath(tags)) return false;
|
|
718
381
|
if (tags.lane === "advisory") return false;
|
|
719
382
|
if (tags.cycleway === "share_busway" || tags.cycleway === "opposite_share_busway") return false;
|
|
720
|
-
const allowedSeparation =
|
|
721
|
-
"bollard",
|
|
722
|
-
"flex_post",
|
|
723
|
-
"vertical_panel",
|
|
724
|
-
"studs",
|
|
725
|
-
"bump",
|
|
726
|
-
"planter",
|
|
727
|
-
"fence",
|
|
728
|
-
"jersey_barrier",
|
|
729
|
-
"guard_rail"
|
|
730
|
-
]);
|
|
383
|
+
const allowedSeparation = new Set(PROTECTIVE_SEPARATION);
|
|
731
384
|
const trafficModeRight = tags.traffic_mode_right;
|
|
732
385
|
const separationLeft = tags.separation_left;
|
|
733
386
|
if (separationLeft != null && allowedSeparation.has(separationLeft)) {
|
|
@@ -751,7 +404,8 @@ function sharedBusLaneBusWithBike(tags) {
|
|
|
751
404
|
if (tags.highway !== "cycleway") return void 0;
|
|
752
405
|
const trafficSign = sanitizeTrafficSign(tags.traffic_sign);
|
|
753
406
|
const parentTrafficSign = tags._parent ? sanitizeTrafficSign(tags._parent.traffic_sign) : void 0;
|
|
754
|
-
if (tags.cycleway === "share_busway" || tags.cycleway === "opposite_share_busway" || hasPrefix(trafficSign, "DE:245") && (containsSubstring(trafficSign, "1022-10") || containsSubstring(trafficSign, "1022-14")) || hasPrefix(parentTrafficSign, "DE:245") && (containsSubstring(parentTrafficSign, "1022-10") || containsSubstring(parentTrafficSign, "1022-14")))
|
|
407
|
+
if (tags.cycleway === "share_busway" || tags.cycleway === "opposite_share_busway" || hasPrefix(trafficSign, "DE:245") && (containsSubstring(trafficSign, "1022-10") || containsSubstring(trafficSign, "1022-14")) || hasPrefix(parentTrafficSign, "DE:245") && (containsSubstring(parentTrafficSign, "1022-10") || containsSubstring(parentTrafficSign, "1022-14")))
|
|
408
|
+
return true;
|
|
755
409
|
return void 0;
|
|
756
410
|
}
|
|
757
411
|
function sharedBusLaneBikeWithBus(tags) {
|
|
@@ -759,7 +413,8 @@ function sharedBusLaneBikeWithBus(tags) {
|
|
|
759
413
|
if (tags.highway !== "cycleway") return void 0;
|
|
760
414
|
const trafficSign = sanitizeTrafficSign(tags.traffic_sign);
|
|
761
415
|
const parentTrafficSign = tags._parent ? sanitizeTrafficSign(tags._parent.traffic_sign) : void 0;
|
|
762
|
-
if (tags.lane === "share_busway" || hasPrefix(trafficSign, "DE:237") && (containsSubstring(trafficSign, "1024-14") || containsSubstring(trafficSign, "1026-32")) || hasPrefix(parentTrafficSign, "DE:237") && (containsSubstring(parentTrafficSign, "1024-14") || containsSubstring(parentTrafficSign, "1026-32")))
|
|
416
|
+
if (tags.lane === "share_busway" || hasPrefix(trafficSign, "DE:237") && (containsSubstring(trafficSign, "1024-14") || containsSubstring(trafficSign, "1026-32")) || hasPrefix(parentTrafficSign, "DE:237") && (containsSubstring(parentTrafficSign, "1024-14") || containsSubstring(parentTrafficSign, "1026-32")))
|
|
417
|
+
return true;
|
|
763
418
|
return void 0;
|
|
764
419
|
}
|
|
765
420
|
function needsClarification(tags) {
|
|
@@ -768,7 +423,14 @@ function needsClarification(tags) {
|
|
|
768
423
|
if (tags.highway === "cycleway") return true;
|
|
769
424
|
if (tags.highway === "path" && tags.bicycle === "designated") {
|
|
770
425
|
if (tags.foot === "no") {
|
|
771
|
-
const excludedSurfaces = /* @__PURE__ */ new Set([
|
|
426
|
+
const excludedSurfaces = /* @__PURE__ */ new Set([
|
|
427
|
+
"ground",
|
|
428
|
+
"dirt",
|
|
429
|
+
"fine_gravel",
|
|
430
|
+
"gravel",
|
|
431
|
+
"pebblestone",
|
|
432
|
+
"earth"
|
|
433
|
+
]);
|
|
772
434
|
if (hasTagWithPrefix(tags, "mtb:") || tags.mtb === "yes" || tags.surface != null && excludedSurfaces.has(tags.surface)) {
|
|
773
435
|
return false;
|
|
774
436
|
}
|
|
@@ -780,15 +442,150 @@ function needsClarification(tags) {
|
|
|
780
442
|
return void 0;
|
|
781
443
|
}
|
|
782
444
|
|
|
783
|
-
// src/categories/
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
|
|
445
|
+
// src/categories/tag-predicate.ts
|
|
446
|
+
var pred = {
|
|
447
|
+
eq: (key, value) => ({ op: "eq", key, value }),
|
|
448
|
+
neq: (key, value) => ({ op: "neq", key, value }),
|
|
449
|
+
in: (key, values) => ({ op: "in", key, values }),
|
|
450
|
+
notIn: (key, values) => ({ op: "notIn", key, values }),
|
|
451
|
+
exists: (key) => ({ op: "exists", key }),
|
|
452
|
+
notExists: (key) => ({ op: "notExists", key }),
|
|
453
|
+
includes: (key, substring) => ({ op: "includes", key, substring }),
|
|
454
|
+
hasPrefix: (key, prefix) => ({ op: "hasPrefix", key, prefix }),
|
|
455
|
+
hasSuffix: (key, suffix) => ({ op: "hasSuffix", key, suffix }),
|
|
456
|
+
hasTagWithPrefix: (prefix) => ({ op: "hasTagWithPrefix", prefix }),
|
|
457
|
+
and: (...predicates) => ({ op: "and", predicates }),
|
|
458
|
+
or: (...predicates) => ({ op: "or", predicates }),
|
|
459
|
+
not: (predicate) => ({ op: "not", predicate }),
|
|
460
|
+
macro: (name) => ({ op: "macro", name }),
|
|
461
|
+
literal: (value) => ({ op: "literal", value })
|
|
462
|
+
};
|
|
463
|
+
function tagValue(tags, key) {
|
|
464
|
+
return tags[key];
|
|
465
|
+
}
|
|
466
|
+
function evalPredicate(tags, predicate, macros) {
|
|
467
|
+
switch (predicate.op) {
|
|
468
|
+
case "eq":
|
|
469
|
+
return tagValue(tags, predicate.key) === predicate.value || void 0;
|
|
470
|
+
case "neq":
|
|
471
|
+
return tagValue(tags, predicate.key) !== predicate.value || void 0;
|
|
472
|
+
case "in": {
|
|
473
|
+
const v = tagValue(tags, predicate.key);
|
|
474
|
+
return v != null && predicate.values.includes(v) || void 0;
|
|
475
|
+
}
|
|
476
|
+
case "notIn": {
|
|
477
|
+
const v = tagValue(tags, predicate.key);
|
|
478
|
+
return v != null && !predicate.values.includes(v) || void 0;
|
|
479
|
+
}
|
|
480
|
+
case "exists":
|
|
481
|
+
return tagValue(tags, predicate.key) != null || void 0;
|
|
482
|
+
case "notExists":
|
|
483
|
+
return tagValue(tags, predicate.key) == null || void 0;
|
|
484
|
+
case "includes":
|
|
485
|
+
return containsSubstring(tagValue(tags, predicate.key), predicate.substring) || void 0;
|
|
486
|
+
case "hasPrefix":
|
|
487
|
+
return hasPrefix(tagValue(tags, predicate.key), predicate.prefix) || void 0;
|
|
488
|
+
case "hasSuffix":
|
|
489
|
+
return hasSuffix(tagValue(tags, predicate.key), predicate.suffix) || void 0;
|
|
490
|
+
case "hasTagWithPrefix":
|
|
491
|
+
return hasTagWithPrefix(tags, predicate.prefix) || void 0;
|
|
492
|
+
case "and": {
|
|
493
|
+
let hasUndefined = false;
|
|
494
|
+
for (const child of predicate.predicates) {
|
|
495
|
+
const r = evalPredicate(tags, child, macros);
|
|
496
|
+
if (r === false) return false;
|
|
497
|
+
if (r !== true) hasUndefined = true;
|
|
498
|
+
}
|
|
499
|
+
return hasUndefined ? void 0 : true;
|
|
500
|
+
}
|
|
501
|
+
case "or": {
|
|
502
|
+
let hasUndefined = false;
|
|
503
|
+
for (const child of predicate.predicates) {
|
|
504
|
+
const r = evalPredicate(tags, child, macros);
|
|
505
|
+
if (r === true) return true;
|
|
506
|
+
if (r !== false) hasUndefined = true;
|
|
507
|
+
}
|
|
508
|
+
return hasUndefined ? void 0 : false;
|
|
509
|
+
}
|
|
510
|
+
case "not": {
|
|
511
|
+
const r = evalPredicate(tags, predicate.predicate, macros);
|
|
512
|
+
if (r === true) return false;
|
|
513
|
+
if (r === false) return true;
|
|
514
|
+
return void 0;
|
|
515
|
+
}
|
|
516
|
+
case "macro": {
|
|
517
|
+
const fn = macros[predicate.name];
|
|
518
|
+
if (!fn) throw new Error(`Unknown predicate macro: ${predicate.name}`);
|
|
519
|
+
return fn(tags);
|
|
520
|
+
}
|
|
521
|
+
case "literal":
|
|
522
|
+
return predicate.value;
|
|
523
|
+
default: {
|
|
524
|
+
const _exhaustive = predicate;
|
|
525
|
+
throw new Error(`Unknown predicate op: ${_exhaustive.op}`);
|
|
526
|
+
}
|
|
790
527
|
}
|
|
791
528
|
}
|
|
529
|
+
function evalPredicateStrict(tags, predicate, macros) {
|
|
530
|
+
const r = evalPredicate(tags, predicate, macros);
|
|
531
|
+
return r === true;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// src/categories/refine-predicates.ts
|
|
535
|
+
var CATEGORY_IS_SIDEPATH_PRED = pred.or(
|
|
536
|
+
pred.eq("is_sidepath", "yes"),
|
|
537
|
+
pred.exists("_parent_highway"),
|
|
538
|
+
pred.eq("footway", "sidewalk"),
|
|
539
|
+
pred.eq("path", "sidewalk"),
|
|
540
|
+
pred.eq("path", "sidepath"),
|
|
541
|
+
pred.eq("cycleway", "sidepath"),
|
|
542
|
+
pred.eq("steps", "sidewalk")
|
|
543
|
+
);
|
|
544
|
+
var SIDEPATH_ADJOINING_PRED = pred.and(
|
|
545
|
+
CATEGORY_IS_SIDEPATH_PRED,
|
|
546
|
+
pred.neq("is_sidepath", "no")
|
|
547
|
+
);
|
|
548
|
+
var SIDEPATH_ISOLATED_PRED = pred.or(
|
|
549
|
+
pred.eq("is_sidepath", "no"),
|
|
550
|
+
pred.eq("highway", "service"),
|
|
551
|
+
pred.eq("highway", "track")
|
|
552
|
+
);
|
|
553
|
+
var SIDEPATH_UNKNOWN_PRED = pred.and(
|
|
554
|
+
pred.neq("is_sidepath", "yes"),
|
|
555
|
+
pred.notExists("_parent_highway"),
|
|
556
|
+
pred.neq("footway", "sidewalk"),
|
|
557
|
+
pred.neq("path", "sidewalk"),
|
|
558
|
+
pred.neq("path", "sidepath"),
|
|
559
|
+
pred.neq("cycleway", "sidepath"),
|
|
560
|
+
pred.neq("steps", "sidewalk"),
|
|
561
|
+
pred.neq("is_sidepath", "no"),
|
|
562
|
+
pred.notIn("highway", ["service", "track"])
|
|
563
|
+
);
|
|
564
|
+
function advisoryOrExclusiveRefining(laneKey = "lane") {
|
|
565
|
+
return [
|
|
566
|
+
{
|
|
567
|
+
idSuffix: "_advisory",
|
|
568
|
+
match: pred.eq(laneKey, "advisory"),
|
|
569
|
+
implicitOneWayConfidence: "high"
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
idSuffix: "_exclusive",
|
|
573
|
+
match: pred.eq(laneKey, "exclusive"),
|
|
574
|
+
implicitOneWayConfidence: "high"
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
idSuffix: "_advisoryOrExclusive",
|
|
578
|
+
match: pred.or(pred.notExists(laneKey), pred.notIn(laneKey, ["advisory", "exclusive"]))
|
|
579
|
+
}
|
|
580
|
+
];
|
|
581
|
+
}
|
|
582
|
+
var ADJOINING_OR_ISOLATED_REFINING = [
|
|
583
|
+
{ idSuffix: "_adjoining", match: SIDEPATH_ADJOINING_PRED },
|
|
584
|
+
{ idSuffix: "_isolated", match: SIDEPATH_ISOLATED_PRED },
|
|
585
|
+
{ idSuffix: "_adjoiningOrIsolated", match: SIDEPATH_UNKNOWN_PRED }
|
|
586
|
+
];
|
|
587
|
+
|
|
588
|
+
// src/categories/category-specs.ts
|
|
792
589
|
function cyclewayOnHighwayBetweenLanesProcess(tags) {
|
|
793
590
|
const width = extractValueFromLanes("width:lanes", tags);
|
|
794
591
|
if (width) tags.width = width;
|
|
@@ -829,14 +626,54 @@ var LANE_GAP = [
|
|
|
829
626
|
}
|
|
830
627
|
];
|
|
831
628
|
var NEEDS_CLARIFICATION_GAP_DISCRIMINATORS = [
|
|
832
|
-
{
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
{
|
|
839
|
-
|
|
629
|
+
{
|
|
630
|
+
key: "segregated",
|
|
631
|
+
values: ["yes"],
|
|
632
|
+
unlocksCategory: "footAndCyclewaySegregated",
|
|
633
|
+
reason: "Segregated foot/cycle path"
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
key: "traffic_sign",
|
|
637
|
+
values: ["DE:241"],
|
|
638
|
+
unlocksCategory: "footAndCyclewaySegregated",
|
|
639
|
+
reason: "German segregated foot/cycle sign"
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
key: "segregated",
|
|
643
|
+
values: ["no"],
|
|
644
|
+
unlocksCategory: "footAndCyclewayShared",
|
|
645
|
+
reason: "Shared foot/cycle path"
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
key: "traffic_sign",
|
|
649
|
+
values: ["DE:240"],
|
|
650
|
+
unlocksCategory: "footAndCyclewayShared",
|
|
651
|
+
reason: "German shared foot/cycle sign"
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
key: "traffic_sign",
|
|
655
|
+
values: ["DE:237", "none"],
|
|
656
|
+
unlocksCategory: "cycleway",
|
|
657
|
+
reason: "German cycleway sign; on highway=cycleway also traffic_sign=none (unsigned cycleway, anderer Radweg)"
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
key: "cycleway",
|
|
661
|
+
values: ["track", "opposite_track"],
|
|
662
|
+
unlocksCategory: "cycleway",
|
|
663
|
+
reason: "Separated cycle track tagging"
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
key: "cycleway",
|
|
667
|
+
values: ["lane", "opposite_lane"],
|
|
668
|
+
unlocksCategory: "cyclewayOnHighway_advisoryOrExclusive",
|
|
669
|
+
reason: "On-highway cycle lane"
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
key: "bicycle",
|
|
673
|
+
values: ["yes"],
|
|
674
|
+
unlocksCategory: "footwayBicycleYes",
|
|
675
|
+
reason: "Bicycle allowed on footway"
|
|
676
|
+
}
|
|
840
677
|
];
|
|
841
678
|
var FOOT_AND_CYCLEWAY_HIGHWAYS = ["cycleway", "path", "footway", "service", "track"];
|
|
842
679
|
var FOOT_AND_CYCLEWAY_SHARED_MATCH = pred.or(
|
|
@@ -848,7 +685,11 @@ var FOOT_AND_CYCLEWAY_SHARED_MATCH = pred.or(
|
|
|
848
685
|
pred.and(
|
|
849
686
|
pred.in("highway", [...FOOT_AND_CYCLEWAY_HIGHWAYS]),
|
|
850
687
|
pred.or(
|
|
851
|
-
pred.and(
|
|
688
|
+
pred.and(
|
|
689
|
+
pred.eq("segregated", "no"),
|
|
690
|
+
pred.eq("bicycle", "designated"),
|
|
691
|
+
pred.eq("foot", "designated")
|
|
692
|
+
),
|
|
852
693
|
pred.and(pred.eq("segregated", "no"), pred.eq("bicycle", "yes"), pred.eq("foot", "yes")),
|
|
853
694
|
pred.includes("traffic_sign", "240")
|
|
854
695
|
)
|
|
@@ -863,7 +704,11 @@ var FOOT_AND_CYCLEWAY_SEGREGATED_MATCH = pred.or(
|
|
|
863
704
|
pred.and(
|
|
864
705
|
pred.in("highway", ["cycleway", "path", "footway"]),
|
|
865
706
|
pred.or(
|
|
866
|
-
pred.and(
|
|
707
|
+
pred.and(
|
|
708
|
+
pred.eq("segregated", "yes"),
|
|
709
|
+
pred.eq("bicycle", "designated"),
|
|
710
|
+
pred.eq("foot", "designated")
|
|
711
|
+
),
|
|
867
712
|
pred.and(pred.eq("segregated", "yes"), pred.eq("bicycle", "yes"), pred.eq("foot", "yes")),
|
|
868
713
|
pred.and(pred.includes("traffic_sign", "241"), pred.neq("highway", "footway"))
|
|
869
714
|
)
|
|
@@ -879,6 +724,8 @@ var CYCLEWAY_SEPARATED_BASE_MATCH = pred.or(
|
|
|
879
724
|
pred.exists("is_sidepath")
|
|
880
725
|
)
|
|
881
726
|
),
|
|
727
|
+
// Unsigned cycleway: `highway=cycleway` + `traffic_sign=none` (tilda-geo 98e649800).
|
|
728
|
+
pred.macro("unsigned_cycleway"),
|
|
882
729
|
pred.and(
|
|
883
730
|
pred.in("highway", [
|
|
884
731
|
"living_street",
|
|
@@ -951,6 +798,7 @@ var CATEGORY_SPECS = [
|
|
|
951
798
|
implicitOneWay: false,
|
|
952
799
|
implicitOneWayConfidence: "high",
|
|
953
800
|
copySurfaceSmoothnessFromParent: true,
|
|
801
|
+
bicycleSurface: "strip",
|
|
954
802
|
// Requires sanitizeTrafficSign for DE:244 prefix and German text variants.
|
|
955
803
|
match: pred.macro("bicycle_road_vehicle_destination")
|
|
956
804
|
},
|
|
@@ -960,6 +808,7 @@ var CATEGORY_SPECS = [
|
|
|
960
808
|
implicitOneWay: false,
|
|
961
809
|
implicitOneWayConfidence: "high",
|
|
962
810
|
copySurfaceSmoothnessFromParent: true,
|
|
811
|
+
bicycleSurface: "strip",
|
|
963
812
|
// Requires sanitizeTrafficSign for DE:244 prefix.
|
|
964
813
|
match: pred.macro("bicycle_road_base")
|
|
965
814
|
},
|
|
@@ -989,10 +838,8 @@ var CATEGORY_SPECS = [
|
|
|
989
838
|
implicitOneWay: false,
|
|
990
839
|
implicitOneWayConfidence: "high",
|
|
991
840
|
copySurfaceSmoothnessFromParent: false,
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
pred.in("bicycle", ["yes", "designated"])
|
|
995
|
-
)
|
|
841
|
+
bicycleSurface: "strip",
|
|
842
|
+
match: pred.and(pred.eq("highway", "pedestrian"), pred.in("bicycle", ["yes", "designated"]))
|
|
996
843
|
},
|
|
997
844
|
{
|
|
998
845
|
id: "sharedMotorVehicleLane",
|
|
@@ -1000,6 +847,7 @@ var CATEGORY_SPECS = [
|
|
|
1000
847
|
implicitOneWay: false,
|
|
1001
848
|
implicitOneWayConfidence: "high",
|
|
1002
849
|
copySurfaceSmoothnessFromParent: true,
|
|
850
|
+
bicycleSurface: "strip",
|
|
1003
851
|
match: pred.and(pred.eq("highway", "cycleway"), pred.eq("cycleway", "shared_lane"))
|
|
1004
852
|
},
|
|
1005
853
|
{
|
|
@@ -1018,9 +866,9 @@ var CATEGORY_SPECS = [
|
|
|
1018
866
|
implicitOneWay: true,
|
|
1019
867
|
implicitOneWayConfidence: "low",
|
|
1020
868
|
copySurfaceSmoothnessFromParent: false,
|
|
869
|
+
bicycleSurface: "whole_way",
|
|
1021
870
|
excludes: [pred.macro("is_crossing_pattern")],
|
|
1022
871
|
match: FOOT_AND_CYCLEWAY_SHARED_MATCH,
|
|
1023
|
-
process: footAndCyclewaySharedProcess,
|
|
1024
872
|
refining: [...ADJOINING_OR_ISOLATED_REFINING],
|
|
1025
873
|
gapDiscriminators: SIDEpath_GAP
|
|
1026
874
|
},
|
|
@@ -1030,6 +878,7 @@ var CATEGORY_SPECS = [
|
|
|
1030
878
|
implicitOneWay: true,
|
|
1031
879
|
implicitOneWayConfidence: "low",
|
|
1032
880
|
copySurfaceSmoothnessFromParent: false,
|
|
881
|
+
bicycleSurface: "whole_way",
|
|
1033
882
|
excludes: [pred.macro("is_crossing_pattern")],
|
|
1034
883
|
match: FOOT_AND_CYCLEWAY_SEGREGATED_MATCH,
|
|
1035
884
|
refining: [...ADJOINING_OR_ISOLATED_REFINING],
|
|
@@ -1041,6 +890,7 @@ var CATEGORY_SPECS = [
|
|
|
1041
890
|
implicitOneWay: false,
|
|
1042
891
|
implicitOneWayConfidence: "low",
|
|
1043
892
|
copySurfaceSmoothnessFromParent: false,
|
|
893
|
+
bicycleSurface: "whole_way",
|
|
1044
894
|
excludes: [pred.macro("is_crossing_pattern"), pred.eq("cycleway", "lane")],
|
|
1045
895
|
match: CYCLEWAY_SEPARATED_BASE_MATCH,
|
|
1046
896
|
refining: [...ADJOINING_OR_ISOLATED_REFINING],
|
|
@@ -1063,6 +913,7 @@ var CATEGORY_SPECS = [
|
|
|
1063
913
|
implicitOneWay: true,
|
|
1064
914
|
implicitOneWayConfidence: "low",
|
|
1065
915
|
copySurfaceSmoothnessFromParent: false,
|
|
916
|
+
bicycleSurface: "whole_way",
|
|
1066
917
|
// mtb:scale numeric parsing and sanitizeTrafficSign for 1022-10.
|
|
1067
918
|
match: pred.macro("footway_bicycle_yes"),
|
|
1068
919
|
refining: [...ADJOINING_OR_ISOLATED_REFINING],
|
|
@@ -1092,7 +943,8 @@ var CATEGORY_MACROS = {
|
|
|
1092
943
|
shared_bus_lane_bus_with_bike: sharedBusLaneBusWithBike,
|
|
1093
944
|
shared_bus_lane_bike_with_bus: sharedBusLaneBikeWithBus,
|
|
1094
945
|
needs_clarification: needsClarification,
|
|
1095
|
-
footway_bicycle_yes: footwayBicycleYes
|
|
946
|
+
footway_bicycle_yes: footwayBicycleYes,
|
|
947
|
+
unsigned_cycleway: unsignedCycleway
|
|
1096
948
|
};
|
|
1097
949
|
function footAndCyclewaySegregatedSeparation(tags) {
|
|
1098
950
|
const separationRight = tags.separation_right;
|
|
@@ -1125,6 +977,44 @@ function specsWithGapDiscriminators() {
|
|
|
1125
977
|
return CATEGORY_SPECS.filter((s) => s.gapDiscriminators != null && s.gapDiscriminators.length > 0);
|
|
1126
978
|
}
|
|
1127
979
|
|
|
980
|
+
// src/categories/decision-view.ts
|
|
981
|
+
var IS_DECISION_VIEW = /* @__PURE__ */ Symbol("isDecisionView");
|
|
982
|
+
function resolveSided(source, key) {
|
|
983
|
+
let base;
|
|
984
|
+
let side;
|
|
985
|
+
if (key.endsWith("_left")) {
|
|
986
|
+
base = key.slice(0, -"_left".length);
|
|
987
|
+
side = "left";
|
|
988
|
+
} else if (key.endsWith("_right")) {
|
|
989
|
+
base = key.slice(0, -"_right".length);
|
|
990
|
+
side = "right";
|
|
991
|
+
}
|
|
992
|
+
if (base === void 0 || side === void 0) return { handled: false };
|
|
993
|
+
const sanitizer = SIDED_SANITIZERS[base];
|
|
994
|
+
if (!sanitizer) return { handled: false };
|
|
995
|
+
const value = sanitizer(source, side);
|
|
996
|
+
if (value === DISALLOWED) return { handled: true, value: void 0 };
|
|
997
|
+
return { handled: true, value };
|
|
998
|
+
}
|
|
999
|
+
function decisionTagsView(source) {
|
|
1000
|
+
if (source[IS_DECISION_VIEW]) return source;
|
|
1001
|
+
return new Proxy(source, {
|
|
1002
|
+
get(target, key) {
|
|
1003
|
+
if (key === IS_DECISION_VIEW) return true;
|
|
1004
|
+
if (typeof key !== "string") return target[key];
|
|
1005
|
+
const sided2 = resolveSided(target, key);
|
|
1006
|
+
if (sided2.handled) return sided2.value;
|
|
1007
|
+
const value = target[key];
|
|
1008
|
+
return value === DISALLOWED ? void 0 : value;
|
|
1009
|
+
},
|
|
1010
|
+
set(target, key, value) {
|
|
1011
|
+
if (typeof key === "string") target[key] = value;
|
|
1012
|
+
else target[key] = value;
|
|
1013
|
+
return true;
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1128
1018
|
// src/categories/compile-category-specs.ts
|
|
1129
1019
|
var MACROS = { ...CATEGORY_MACROS };
|
|
1130
1020
|
function compileMatch(spec) {
|
|
@@ -1140,13 +1030,14 @@ function compileMatch(spec) {
|
|
|
1140
1030
|
function compileRefiningMatch(predicate) {
|
|
1141
1031
|
return (tags) => evalPredicateStrict(tags, predicate, MACROS);
|
|
1142
1032
|
}
|
|
1143
|
-
function mkCategory(spec, id, condition
|
|
1033
|
+
function mkCategory(spec, id, condition) {
|
|
1144
1034
|
return {
|
|
1145
1035
|
id,
|
|
1146
1036
|
infrastructureExists: spec.infrastructureExists,
|
|
1147
1037
|
implicitOneWay: spec.implicitOneWay,
|
|
1148
1038
|
implicitOneWayConfidence: spec.implicitOneWayConfidence,
|
|
1149
|
-
copySurfaceSmoothnessFromParent:
|
|
1039
|
+
copySurfaceSmoothnessFromParent: spec.copySurfaceSmoothnessFromParent,
|
|
1040
|
+
bicycleSurface: spec.bicycleSurface,
|
|
1150
1041
|
condition,
|
|
1151
1042
|
process: spec.process
|
|
1152
1043
|
};
|
|
@@ -1163,8 +1054,7 @@ function expandRefining(spec, baseMatch) {
|
|
|
1163
1054
|
const refineMatch = compileRefiningMatch(child.match);
|
|
1164
1055
|
const condition = (tags) => baseMatch(tags) && refineMatch(tags) || void 0;
|
|
1165
1056
|
const childSpec = child.implicitOneWayConfidence ? { ...spec, implicitOneWayConfidence: child.implicitOneWayConfidence } : spec;
|
|
1166
|
-
|
|
1167
|
-
return mkCategory(childSpec, resolveRefinedId2(spec, child), condition, copyFromParent);
|
|
1057
|
+
return mkCategory(childSpec, resolveRefinedId2(spec, child), condition);
|
|
1168
1058
|
});
|
|
1169
1059
|
}
|
|
1170
1060
|
function expandSpec(spec) {
|
|
@@ -1172,40 +1062,295 @@ function expandSpec(spec) {
|
|
|
1172
1062
|
if (!spec.refining?.length) {
|
|
1173
1063
|
return [mkCategory(spec, spec.id, baseMatch)];
|
|
1174
1064
|
}
|
|
1175
|
-
return expandRefining(spec, baseMatch);
|
|
1176
|
-
}
|
|
1177
|
-
var COMPILED_CATEGORY_DEFINITIONS = CATEGORY_SPECS.flatMap(expandSpec);
|
|
1178
|
-
function sidepathDiscriminatorKnown(tags) {
|
|
1179
|
-
if (tags.is_sidepath === "yes" || tags.is_sidepath === "no") return true;
|
|
1180
|
-
if (tags.highway === "service" || tags.highway === "track") return true;
|
|
1181
|
-
return false;
|
|
1182
|
-
}
|
|
1183
|
-
function laneDiscriminatorKnown(tags) {
|
|
1184
|
-
return tags.lane === "advisory" || tags.lane === "exclusive";
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
// src/categories/bikelane-categories.ts
|
|
1188
|
-
var CATEGORY_DEFINITIONS = COMPILED_CATEGORY_DEFINITIONS;
|
|
1189
|
-
function categorizeBikelane(tags) {
|
|
1190
|
-
for (const category of CATEGORY_DEFINITIONS) {
|
|
1191
|
-
if (category.condition(decisionTagsView(tags))) {
|
|
1192
|
-
category.process?.(tags);
|
|
1193
|
-
return category;
|
|
1065
|
+
return expandRefining(spec, baseMatch);
|
|
1066
|
+
}
|
|
1067
|
+
var COMPILED_CATEGORY_DEFINITIONS = CATEGORY_SPECS.flatMap(expandSpec);
|
|
1068
|
+
function sidepathDiscriminatorKnown(tags) {
|
|
1069
|
+
if (tags.is_sidepath === "yes" || tags.is_sidepath === "no") return true;
|
|
1070
|
+
if (tags.highway === "service" || tags.highway === "track") return true;
|
|
1071
|
+
return false;
|
|
1072
|
+
}
|
|
1073
|
+
function laneDiscriminatorKnown(tags) {
|
|
1074
|
+
return tags.lane === "advisory" || tags.lane === "exclusive";
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
// src/categories/bikelane-categories.ts
|
|
1078
|
+
var CATEGORY_DEFINITIONS = COMPILED_CATEGORY_DEFINITIONS;
|
|
1079
|
+
function categorizeBikelane(tags) {
|
|
1080
|
+
for (const category of CATEGORY_DEFINITIONS) {
|
|
1081
|
+
if (category.condition(decisionTagsView(tags))) {
|
|
1082
|
+
category.process?.(tags);
|
|
1083
|
+
return category;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
return null;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// src/derive/bikelane-todos.ts
|
|
1090
|
+
var missingTrafficSignVehicleDestination = {
|
|
1091
|
+
id: "missing_traffic_sign_vehicle_destination",
|
|
1092
|
+
desc: "Expecting tag traffic_sign 'Anlieger frei' `traffic_sign=DE:244.1,1020-30` or similar.",
|
|
1093
|
+
todoTableOnly: true,
|
|
1094
|
+
condition: (tags) => tags.bicycle_road === "yes" && (tags.vehicle === "destination" || tags.motor_vehicle === "destination") && !containsSubstring(tags.traffic_sign, "1020-30")
|
|
1095
|
+
};
|
|
1096
|
+
var missingTrafficSign244 = {
|
|
1097
|
+
id: "missing_traffic_sign_244",
|
|
1098
|
+
desc: "Expecting tag `traffic_sign=DE:244.1` or similar.",
|
|
1099
|
+
todoTableOnly: true,
|
|
1100
|
+
condition: (tags, result) => tags.bicycle_road === "yes" && !containsSubstring(tags.traffic_sign, "244") && !missingTrafficSignVehicleDestination.condition(tags, result)
|
|
1101
|
+
};
|
|
1102
|
+
var missingAccessTagBicycleRoad = {
|
|
1103
|
+
id: "missing_access_tag_bicycle_road",
|
|
1104
|
+
desc: "Expected access tag `bicycle=designated` that is required for routing.",
|
|
1105
|
+
todoTableOnly: false,
|
|
1106
|
+
// Only check `vehicle` because `motor_vehicle` does allow `bicycle` already.
|
|
1107
|
+
condition: (tags) => tags.bicycle_road === "yes" && (tags.vehicle === "no" || tags.vehicle === "destination") && tags.bicycle !== "designated"
|
|
1108
|
+
};
|
|
1109
|
+
var malformedTrafficSign = {
|
|
1110
|
+
id: "malformed_traffic_sign",
|
|
1111
|
+
desc: "Traffic sign tag needs cleaning up.",
|
|
1112
|
+
todoTableOnly: true,
|
|
1113
|
+
// Compare raw with sanitized tag.
|
|
1114
|
+
condition: (tags) => ["traffic_sign", "traffic_sign:both", "traffic_sign:forward", "traffic_sign:backward"].some(
|
|
1115
|
+
(key) => tags[key] !== sanitizeTrafficSign(tags[key])
|
|
1116
|
+
)
|
|
1117
|
+
};
|
|
1118
|
+
var missingTrafficSign = {
|
|
1119
|
+
id: "missing_traffic_sign",
|
|
1120
|
+
desc: "Expected tag `traffic_sign=DE:*` or `traffic_sign=none`.",
|
|
1121
|
+
todoTableOnly: true,
|
|
1122
|
+
condition: (tags, result) => {
|
|
1123
|
+
const trafficSign = tags.traffic_sign ?? tags["traffic_sign:forward"] ?? tags["traffic_sign:backward"];
|
|
1124
|
+
return trafficSign === void 0 && // Add any new missing_traffic_sign_* here so we only trigger this todo when no other
|
|
1125
|
+
// traffic_sign todo is present.
|
|
1126
|
+
!(missingTrafficSign244.condition(tags, result) || missingTrafficSignVehicleDestination.condition(tags, result)) && result.category !== "cyclewayLink" && result.category !== "crossing" && result.category !== "needsClarification";
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
var missingAccessTag240 = {
|
|
1130
|
+
id: "missing_access_tag_240",
|
|
1131
|
+
desc: "Expected tag `bicycle=designated` and `foot=designated`.",
|
|
1132
|
+
todoTableOnly: false,
|
|
1133
|
+
condition: (tags) => (containsSubstring(tags.traffic_sign, "240") || containsSubstring(tags.traffic_sign, "241")) && // either one missing (tilda-geo 61252e31f; before, only when both were missing)
|
|
1134
|
+
(tags.bicycle !== "designated" || tags.foot !== "designated") && tags.cycleway !== "track" && tags.cycleway !== "lane"
|
|
1135
|
+
};
|
|
1136
|
+
var SEGREGATED_VALUES = /* @__PURE__ */ new Set(["yes", "no"]);
|
|
1137
|
+
var missingSegregated = {
|
|
1138
|
+
id: "missing_segregated",
|
|
1139
|
+
desc: "Expected tag `segregated=yes` or `segregated=no`.",
|
|
1140
|
+
todoTableOnly: false,
|
|
1141
|
+
condition: (tags, result) => result.category === "needsClarification" && // neither `yes` nor `no` (tilda-geo ed8478350)
|
|
1142
|
+
!SEGREGATED_VALUES.has(tags.segregated ?? "") && (tags.bicycle === "designated" && tags.foot === "designated" || containsSubstring(tags.traffic_sign, "240") || containsSubstring(tags.traffic_sign, "241"))
|
|
1143
|
+
};
|
|
1144
|
+
var unexpectedBicycleAccessOnFootway = {
|
|
1145
|
+
id: "unexpected_bicycle_access_on_footway",
|
|
1146
|
+
desc: "Expected `highway=path+bicycle=designated` (unsigned/explicit DE:240) or `highway=footway+bicycle=yes` (unsigned/explicit DE:239,1022-10); Add traffic_sign=none to specify unsigned path.",
|
|
1147
|
+
todoTableOnly: true,
|
|
1148
|
+
condition: (tags, result) => tags.highway === "footway" && tags.bicycle === "designated" && result.category === "needsClarification"
|
|
1149
|
+
};
|
|
1150
|
+
var EXCLUDED_SURFACES = /* @__PURE__ */ new Set([
|
|
1151
|
+
"ground",
|
|
1152
|
+
"dirt",
|
|
1153
|
+
"fine_gravel",
|
|
1154
|
+
"gravel",
|
|
1155
|
+
"pebblestone",
|
|
1156
|
+
"earth"
|
|
1157
|
+
]);
|
|
1158
|
+
var unexpectedHighwayPath = {
|
|
1159
|
+
id: "unexpected_highway_path",
|
|
1160
|
+
desc: "Expected `highway=cycleway` (unsigned/explicit DE:237)",
|
|
1161
|
+
todoTableOnly: true,
|
|
1162
|
+
// REFERENCE: See conditions in the `needsClarification` category.
|
|
1163
|
+
condition: (tags) => tags.highway === "path" && tags.bicycle === "designated" && tags.foot === "no" && !(hasTagWithPrefix(tags, "mtb:") || tags.mtb === "yes" || tags.surface !== void 0 && EXCLUDED_SURFACES.has(tags.surface))
|
|
1164
|
+
};
|
|
1165
|
+
var crossingTooLong = {
|
|
1166
|
+
id: "crossing_too_long",
|
|
1167
|
+
desc: "Crossing longer than 100 m, guidance form unclear. Please review and correct.",
|
|
1168
|
+
todoTableOnly: false,
|
|
1169
|
+
condition: (tags, result) => result.category === "needsClarification" && isCrossingPattern(tags) && tags._length != null && tags._length > 100
|
|
1170
|
+
};
|
|
1171
|
+
var needsClarification2 = {
|
|
1172
|
+
id: "needs_clarification",
|
|
1173
|
+
desc: "Tagging insufficient to categorize the bike infrastructure.",
|
|
1174
|
+
todoTableOnly: false,
|
|
1175
|
+
condition: (tags, result) => result.category === "needsClarification" && !(tags.cycleway === "shared" || // Handled by the road todo `deprecated_cycleway_shared`
|
|
1176
|
+
unexpectedBicycleAccessOnFootway.condition(tags, result) || crossingTooLong.condition(tags, result) || missingSegregated.condition(tags, result))
|
|
1177
|
+
};
|
|
1178
|
+
var adjoiningOrIsolated = {
|
|
1179
|
+
id: "adjoining_or_isolated",
|
|
1180
|
+
desc: "Only for category=cycleway_adjoiningOrIsolated for now. Expected tag `is_sidepath=yes` or `is_sidepath=no`.",
|
|
1181
|
+
todoTableOnly: false,
|
|
1182
|
+
condition: (_tags, result) => result.category === "cycleway_adjoiningOrIsolated"
|
|
1183
|
+
};
|
|
1184
|
+
var advisoryOrExclusive = {
|
|
1185
|
+
id: "advisory_or_exclusive",
|
|
1186
|
+
desc: "Expected tag `cycleway:*:lane=advisory` or `exclusive`.",
|
|
1187
|
+
todoTableOnly: false,
|
|
1188
|
+
condition: (_tags, result) => containsSubstring(result.category, "_advisoryOrExclusive")
|
|
1189
|
+
};
|
|
1190
|
+
var needsClarificationTrack = {
|
|
1191
|
+
id: "needs_clarification_track",
|
|
1192
|
+
desc: "Tagging `cycleway=track` insufficient to categorize the bike infrastructure`.",
|
|
1193
|
+
todoTableOnly: false,
|
|
1194
|
+
condition: (tags, result) => {
|
|
1195
|
+
if (result.category === "cyclewayOnHighwayProtected") return false;
|
|
1196
|
+
if (tags._parent == null) return false;
|
|
1197
|
+
if (tags.segregated === "yes" || tags.segregated === "no") return false;
|
|
1198
|
+
if (containsSubstring(tags.traffic_sign, "237")) return false;
|
|
1199
|
+
if (containsSubstring(tags.traffic_sign, "240")) return false;
|
|
1200
|
+
if (containsSubstring(tags.traffic_sign, "241")) return false;
|
|
1201
|
+
return tags.cycleway === "track";
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
var mixedCyclewayBoth = {
|
|
1205
|
+
id: "mixed_cycleway_both",
|
|
1206
|
+
desc: "Mixed tagging of cycleway=* or cycleway:both=* with cycleway:SIDE",
|
|
1207
|
+
todoTableOnly: false,
|
|
1208
|
+
condition: (tags) => {
|
|
1209
|
+
const parent = tags._parent;
|
|
1210
|
+
if (parent == null) return false;
|
|
1211
|
+
const hasSide = parent["cycleway:left"] !== void 0 || parent["cycleway:right"] !== void 0;
|
|
1212
|
+
return parent["cycleway:both"] !== void 0 && hasSide || parent.cycleway !== void 0 && hasSide;
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
var MAX_USUAL_WIDTH = 50;
|
|
1216
|
+
var REVIEWED_KEYS = [
|
|
1217
|
+
"check_date",
|
|
1218
|
+
"check_date:width",
|
|
1219
|
+
"survey:date",
|
|
1220
|
+
"survey:date:width",
|
|
1221
|
+
"survey_date"
|
|
1222
|
+
];
|
|
1223
|
+
function hasReviewedKey(tags) {
|
|
1224
|
+
if (tags == null) return false;
|
|
1225
|
+
return REVIEWED_KEYS.some((key) => tags[key] !== void 0);
|
|
1226
|
+
}
|
|
1227
|
+
function isUnusualWidth(tags, result) {
|
|
1228
|
+
if (tags.width === void 0) return false;
|
|
1229
|
+
if (hasReviewedKey(tags) || hasReviewedKey(tags._parent)) return false;
|
|
1230
|
+
return result.width == null || result.width > MAX_USUAL_WIDTH;
|
|
1231
|
+
}
|
|
1232
|
+
var missingWidth = {
|
|
1233
|
+
id: "missing_width",
|
|
1234
|
+
desc: "Ways without `width`",
|
|
1235
|
+
todoTableOnly: true,
|
|
1236
|
+
condition: (_tags, result) => result.width == null && result.category !== "cyclewayLink" && result.category !== "crossing" && result.category !== "pedestrianAreaBicycleYes" && result.category !== "needsClarification" && !containsSubstring(result.category, "cyclewayOnHighway") && !containsSubstring(result.category, "sharedBusLane")
|
|
1237
|
+
};
|
|
1238
|
+
var unusualWidth = {
|
|
1239
|
+
id: "unusual_width",
|
|
1240
|
+
desc: "Width that we cannot read or that is unusually high. Fix `width`, or confirm it with `check_date=*` or `check_date:width=*`.",
|
|
1241
|
+
todoTableOnly: true,
|
|
1242
|
+
condition: (tags, result) => isUnusualWidth(tags, result)
|
|
1243
|
+
};
|
|
1244
|
+
var missingSurface = {
|
|
1245
|
+
id: "missing_surface",
|
|
1246
|
+
desc: "Ways without `surface`",
|
|
1247
|
+
todoTableOnly: true,
|
|
1248
|
+
// Either the surface is missing. But also surface values that are not derived from the osm tag
|
|
1249
|
+
// should be added.
|
|
1250
|
+
condition: (_tags, result) => (result.surface == null || result.surface_source !== "tag") && result.category !== "cyclewayLink" && result.category !== "needsClarification" && !containsSubstring(result.category, "cyclewayOnHighway") && !containsSubstring(result.category, "sharedBusLane")
|
|
1251
|
+
};
|
|
1252
|
+
var missingOneway = {
|
|
1253
|
+
id: "missing_oneway",
|
|
1254
|
+
desc: "Ways without explicit `oneway`",
|
|
1255
|
+
todoTableOnly: false,
|
|
1256
|
+
condition: (tags, result) => {
|
|
1257
|
+
if (needsClarificationTrack.condition(tags, result)) return false;
|
|
1258
|
+
if (needsClarification2.condition(tags, result)) return false;
|
|
1259
|
+
if (tags._parent != null) return false;
|
|
1260
|
+
if (result.category === "crossing") return false;
|
|
1261
|
+
if (result.category === "cyclewayLink") return false;
|
|
1262
|
+
if (!(result.oneway === "assumed_no" || result.oneway === "implicit_yes")) return false;
|
|
1263
|
+
return result.implicitOneWayConfidence === "low";
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1266
|
+
var AGAINST_SIDE_TRAFFIC = {
|
|
1267
|
+
left: /* @__PURE__ */ new Set(["yes", "1"]),
|
|
1268
|
+
right: /* @__PURE__ */ new Set(["-1"])
|
|
1269
|
+
};
|
|
1270
|
+
function againstSideTrafficKeys(tags) {
|
|
1271
|
+
const parent = tags._parent;
|
|
1272
|
+
const prefix = tags._prefix;
|
|
1273
|
+
const bothKey = `${prefix}:both:oneway`;
|
|
1274
|
+
const unsidedKey = `${prefix}:oneway`;
|
|
1275
|
+
const sharedKey = parent[bothKey] !== void 0 ? bothKey : parent[unsidedKey] !== void 0 ? unsidedKey : void 0;
|
|
1276
|
+
const keys = {};
|
|
1277
|
+
for (const side of ["left", "right"]) {
|
|
1278
|
+
const against = AGAINST_SIDE_TRAFFIC[side];
|
|
1279
|
+
const sideKey = `${prefix}:${side}:oneway`;
|
|
1280
|
+
const sideValue = parent[sideKey];
|
|
1281
|
+
if (sideValue !== void 0) {
|
|
1282
|
+
if (against.has(sideValue)) keys[side] = sideKey;
|
|
1283
|
+
} else if (sharedKey !== void 0 && against.has(parent[sharedKey])) {
|
|
1284
|
+
keys[side] = sharedKey;
|
|
1194
1285
|
}
|
|
1195
1286
|
}
|
|
1196
|
-
return
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1287
|
+
return keys;
|
|
1288
|
+
}
|
|
1289
|
+
var unexpectedOnewayDirection = {
|
|
1290
|
+
id: "unexpected_oneway_direction",
|
|
1291
|
+
desc: "Lane or track tagged to run against the traffic of its side (`cycleway:left:oneway=yes`, `cycleway:both:oneway=yes`, `cycleway:right:oneway=-1`).",
|
|
1292
|
+
todoTableOnly: false,
|
|
1293
|
+
condition: (tags) => {
|
|
1294
|
+
const parent = tags._parent;
|
|
1295
|
+
if (parent == null) return false;
|
|
1296
|
+
if (parent.oneway === "yes" || parent.oneway === "-1") return false;
|
|
1297
|
+
const keys = againstSideTrafficKeys(tags);
|
|
1298
|
+
for (const side of ["left", "right"]) {
|
|
1299
|
+
const key = keys[side];
|
|
1300
|
+
if (key === void 0) continue;
|
|
1301
|
+
if (side === tags._side || !key.includes(`:${side}:`)) return true;
|
|
1302
|
+
}
|
|
1303
|
+
return false;
|
|
1304
|
+
},
|
|
1305
|
+
// Removing the tag restores the default direction of the side. Only proposed for the left side:
|
|
1306
|
+
// `yes` there is the usual mix-up of "one direction" with "direction of the way".
|
|
1307
|
+
// The same list on both sides of a way, so MapRoulette gets one task per way.
|
|
1308
|
+
tagFix: (tags) => {
|
|
1309
|
+
const keys = againstSideTrafficKeys(tags);
|
|
1310
|
+
if (keys.left === void 0 || keys.right !== void 0) return void 0;
|
|
1311
|
+
return { unset: [keys.left] };
|
|
1204
1312
|
}
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1313
|
+
};
|
|
1314
|
+
var BIKELANE_TODOS = [
|
|
1315
|
+
// Infrastructure
|
|
1316
|
+
crossingTooLong,
|
|
1317
|
+
needsClarification2,
|
|
1318
|
+
adjoiningOrIsolated,
|
|
1319
|
+
advisoryOrExclusive,
|
|
1320
|
+
needsClarificationTrack,
|
|
1321
|
+
mixedCyclewayBoth,
|
|
1322
|
+
unexpectedHighwayPath,
|
|
1323
|
+
// Bicycle roads
|
|
1324
|
+
missingTrafficSignVehicleDestination,
|
|
1325
|
+
missingTrafficSign244,
|
|
1326
|
+
missingAccessTagBicycleRoad,
|
|
1327
|
+
// Traffic signs
|
|
1328
|
+
missingTrafficSign,
|
|
1329
|
+
malformedTrafficSign,
|
|
1330
|
+
// Bike- and foot path
|
|
1331
|
+
missingAccessTag240,
|
|
1332
|
+
missingSegregated,
|
|
1333
|
+
unexpectedBicycleAccessOnFootway,
|
|
1334
|
+
// Other
|
|
1335
|
+
missingWidth,
|
|
1336
|
+
unusualWidth,
|
|
1337
|
+
missingSurface,
|
|
1338
|
+
missingOneway,
|
|
1339
|
+
unexpectedOnewayDirection
|
|
1340
|
+
];
|
|
1341
|
+
function deriveBikelaneTodos(tags, result) {
|
|
1342
|
+
const todos = [];
|
|
1343
|
+
let todoTagFixes;
|
|
1344
|
+
for (const todo of BIKELANE_TODOS) {
|
|
1345
|
+
if (!todo.condition(tags, result)) continue;
|
|
1346
|
+
todos.push(todo.id);
|
|
1347
|
+
const fix = todo.tagFix?.(tags, result);
|
|
1348
|
+
if (fix) {
|
|
1349
|
+
todoTagFixes ??= {};
|
|
1350
|
+
todoTagFixes[todo.id] = fix;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
return todoTagFixes ? { todos, todoTagFixes } : { todos };
|
|
1209
1354
|
}
|
|
1210
1355
|
|
|
1211
1356
|
// src/sanitize/sanitize-surface.ts
|
|
@@ -1263,27 +1408,10 @@ function sanitizeSurface(tags) {
|
|
|
1263
1408
|
}
|
|
1264
1409
|
return sanitizeForLogging(tags.surface, SURFACE_ALLOWED, SURFACE_IGNORED);
|
|
1265
1410
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
const surface = sanitizeSurface(tags);
|
|
1271
|
-
if (surface === DISALLOWED) return {};
|
|
1272
|
-
return { surface, surface_source: "tag", surface_confidence: "high" };
|
|
1273
|
-
}
|
|
1274
|
-
function deriveBikelaneSurface(tags, category) {
|
|
1275
|
-
const own = deriveSurface(tags);
|
|
1276
|
-
if (own.surface != null) {
|
|
1277
|
-
return { surface: own.surface, surface_source: "tag", surface_confidence: "high" };
|
|
1278
|
-
}
|
|
1279
|
-
const parent = tags._parent;
|
|
1280
|
-
if (category.copySurfaceSmoothnessFromParent && parent != null) {
|
|
1281
|
-
const parentSurface = deriveSurface(parent);
|
|
1282
|
-
if (parentSurface.surface != null) {
|
|
1283
|
-
return { surface: parentSurface.surface, surface_source: "parent_highway_tag", surface_confidence: "high" };
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
return {};
|
|
1411
|
+
function allowedSurface(value, tags) {
|
|
1412
|
+
if (value == null) return void 0;
|
|
1413
|
+
const surface = sanitizeSurface({ surface: value, "sett:length": tags["sett:length"] });
|
|
1414
|
+
return surface === DISALLOWED ? void 0 : surface;
|
|
1287
1415
|
}
|
|
1288
1416
|
|
|
1289
1417
|
// src/derive/derive-smoothness.ts
|
|
@@ -1296,9 +1424,15 @@ var SMOOTHNESS_NORMALIZATION = {
|
|
|
1296
1424
|
};
|
|
1297
1425
|
function normalizeSmoothness(smoothness) {
|
|
1298
1426
|
if (smoothness != null) {
|
|
1299
|
-
if (SMOOTHNESS_DIRECT.has(smoothness))
|
|
1427
|
+
if (SMOOTHNESS_DIRECT.has(smoothness))
|
|
1428
|
+
return { smoothness, smoothness_source: "tag", smoothness_confidence: "high" };
|
|
1300
1429
|
const normalized = SMOOTHNESS_NORMALIZATION[smoothness];
|
|
1301
|
-
if (normalized)
|
|
1430
|
+
if (normalized)
|
|
1431
|
+
return {
|
|
1432
|
+
smoothness: normalized,
|
|
1433
|
+
smoothness_source: "tag_normalized",
|
|
1434
|
+
smoothness_confidence: "high"
|
|
1435
|
+
};
|
|
1302
1436
|
}
|
|
1303
1437
|
return {};
|
|
1304
1438
|
}
|
|
@@ -1380,7 +1514,12 @@ var SURFACE_TO_SMOOTHNESS_NON_STANDARD = {
|
|
|
1380
1514
|
function deriveSmoothnessFromSurface(surface) {
|
|
1381
1515
|
if (!surface) return {};
|
|
1382
1516
|
const smoothness = SURFACE_TO_SMOOTHNESS[surface] ?? SURFACE_TO_SMOOTHNESS_NON_STANDARD[surface];
|
|
1383
|
-
if (smoothness)
|
|
1517
|
+
if (smoothness)
|
|
1518
|
+
return {
|
|
1519
|
+
smoothness,
|
|
1520
|
+
smoothness_source: "surface_to_smoothness",
|
|
1521
|
+
smoothness_confidence: "medium"
|
|
1522
|
+
};
|
|
1384
1523
|
return {};
|
|
1385
1524
|
}
|
|
1386
1525
|
var TRACKTYPE_TO_SMOOTHNESS = {
|
|
@@ -1393,15 +1532,28 @@ var TRACKTYPE_TO_SMOOTHNESS = {
|
|
|
1393
1532
|
function deriveSmoothnessFromTrackType(type) {
|
|
1394
1533
|
if (!type) return {};
|
|
1395
1534
|
const smoothness = TRACKTYPE_TO_SMOOTHNESS[type];
|
|
1396
|
-
if (smoothness)
|
|
1535
|
+
if (smoothness)
|
|
1536
|
+
return {
|
|
1537
|
+
smoothness,
|
|
1538
|
+
smoothness_source: "tracktype_to_smoothness",
|
|
1539
|
+
smoothness_confidence: "medium"
|
|
1540
|
+
};
|
|
1397
1541
|
return {};
|
|
1398
1542
|
}
|
|
1399
1543
|
function deriveSmoothnessFromMtbScale(scale) {
|
|
1400
1544
|
if (!scale) return {};
|
|
1401
1545
|
if (scale === "0" || scale === "0+" || scale === "0-") {
|
|
1402
|
-
return {
|
|
1546
|
+
return {
|
|
1547
|
+
smoothness: "bad",
|
|
1548
|
+
smoothness_source: "mtb:scale_to_smoothness",
|
|
1549
|
+
smoothness_confidence: "medium"
|
|
1550
|
+
};
|
|
1403
1551
|
}
|
|
1404
|
-
return {
|
|
1552
|
+
return {
|
|
1553
|
+
smoothness: "very_bad",
|
|
1554
|
+
smoothness_source: "mtb:scale_to_smoothness",
|
|
1555
|
+
smoothness_confidence: "medium"
|
|
1556
|
+
};
|
|
1405
1557
|
}
|
|
1406
1558
|
function deriveSmoothness(tags) {
|
|
1407
1559
|
let result = normalizeSmoothness(tags.smoothness);
|
|
@@ -1429,47 +1581,539 @@ function deriveBikelaneSmoothness(tags, category) {
|
|
|
1429
1581
|
smoothness_confidence = parentResult.smoothness_confidence;
|
|
1430
1582
|
}
|
|
1431
1583
|
}
|
|
1432
|
-
if (smoothness != null && smoothness_source != null && smoothness_confidence != null) {
|
|
1433
|
-
return { smoothness, smoothness_source, smoothness_confidence };
|
|
1584
|
+
if (smoothness != null && smoothness_source != null && smoothness_confidence != null) {
|
|
1585
|
+
return { smoothness, smoothness_source, smoothness_confidence };
|
|
1586
|
+
}
|
|
1587
|
+
return {};
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
// src/derive/derive-directional-surface.ts
|
|
1591
|
+
var SURFACE_KEYS = [
|
|
1592
|
+
{ key: "surface:bicycle", token: "surface_bicycle" },
|
|
1593
|
+
{ key: "surface:bicycle:right", token: "surface_bicycle_right" },
|
|
1594
|
+
{ key: "surface:bicycle:forward", token: "surface_bicycle_right" },
|
|
1595
|
+
{ key: "surface:bicycle:left", token: "surface_bicycle_left" },
|
|
1596
|
+
{ key: "surface:bicycle:backward", token: "surface_bicycle_left" },
|
|
1597
|
+
{ key: "surface:right", token: "surface_right" },
|
|
1598
|
+
{ key: "surface:forward", token: "surface_right" },
|
|
1599
|
+
{ key: "surface:left", token: "surface_left" },
|
|
1600
|
+
{ key: "surface:backward", token: "surface_left" }
|
|
1601
|
+
];
|
|
1602
|
+
var SMOOTHNESS_RANK = {
|
|
1603
|
+
excellent: 1,
|
|
1604
|
+
good: 2,
|
|
1605
|
+
intermediate: 3,
|
|
1606
|
+
bad: 4,
|
|
1607
|
+
very_bad: 5
|
|
1608
|
+
};
|
|
1609
|
+
function badness(rawSurface) {
|
|
1610
|
+
const smoothness = deriveSmoothness({ surface: rawSurface }).smoothness;
|
|
1611
|
+
return smoothness && SMOOTHNESS_RANK[smoothness] || 0;
|
|
1612
|
+
}
|
|
1613
|
+
function worstDirectionalSurface(tags) {
|
|
1614
|
+
if (allowedSurface(tags.surface, tags) != null) return void 0;
|
|
1615
|
+
const seenTokens = /* @__PURE__ */ new Set();
|
|
1616
|
+
let worst;
|
|
1617
|
+
for (const { key, token } of SURFACE_KEYS) {
|
|
1618
|
+
const raw = tags[key];
|
|
1619
|
+
if (raw == null || seenTokens.has(token) || allowedSurface(raw, tags) == null) continue;
|
|
1620
|
+
seenTokens.add(token);
|
|
1621
|
+
if (worst == null || badness(raw) > badness(worst)) worst = raw;
|
|
1622
|
+
}
|
|
1623
|
+
return worst;
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
// src/derive/derive-bikelane-surface-tags.ts
|
|
1627
|
+
function choose(tags) {
|
|
1628
|
+
const bicycle = allowedSurface(tags["surface:bicycle"], tags) ? tags["surface:bicycle"] : void 0;
|
|
1629
|
+
const bicycleSmoothness = tags["smoothness:bicycle"];
|
|
1630
|
+
if (bicycle) {
|
|
1631
|
+
return { surface: bicycle, smoothness: bicycleSmoothness, directional: false };
|
|
1632
|
+
}
|
|
1633
|
+
if (allowedSurface(tags.surface, tags)) {
|
|
1634
|
+
return {
|
|
1635
|
+
surface: tags.surface,
|
|
1636
|
+
smoothness: bicycleSmoothness ?? tags.smoothness,
|
|
1637
|
+
directional: false
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
const fallback = worstDirectionalSurface(tags);
|
|
1641
|
+
if (fallback) {
|
|
1642
|
+
return {
|
|
1643
|
+
surface: fallback,
|
|
1644
|
+
smoothness: bicycleSmoothness ?? tags.smoothness,
|
|
1645
|
+
directional: true
|
|
1646
|
+
};
|
|
1647
|
+
}
|
|
1648
|
+
return {
|
|
1649
|
+
surface: void 0,
|
|
1650
|
+
smoothness: bicycleSmoothness ?? tags.smoothness,
|
|
1651
|
+
directional: false
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
var SIDE_TO_DIRECTION = { right: "forward", left: "backward" };
|
|
1655
|
+
function chooseForSide(parent, side) {
|
|
1656
|
+
if (allowedSurface(parent["surface:bicycle"], parent)) return choose(parent);
|
|
1657
|
+
const twoWay = parent.oneway !== "yes" && parent.oneway !== "-1";
|
|
1658
|
+
const direction = SIDE_TO_DIRECTION[side];
|
|
1659
|
+
const allowed = (key) => allowedSurface(parent[key], parent) ? parent[key] : void 0;
|
|
1660
|
+
const surface = allowed(`surface:bicycle:${side}`) ?? (twoWay ? allowed(`surface:bicycle:${direction}`) : void 0) ?? allowed(`surface:${side}`) ?? (twoWay ? allowed(`surface:${direction}`) : void 0);
|
|
1661
|
+
if (surface) {
|
|
1662
|
+
return { surface, smoothness: parent["smoothness:bicycle"], directional: true };
|
|
1663
|
+
}
|
|
1664
|
+
return choose(parent);
|
|
1665
|
+
}
|
|
1666
|
+
function override(tags, choice, parent) {
|
|
1667
|
+
const result = { ...tags };
|
|
1668
|
+
result.surface = choice.surface;
|
|
1669
|
+
result.smoothness = choice.smoothness;
|
|
1670
|
+
result._parent = parent;
|
|
1671
|
+
return result;
|
|
1672
|
+
}
|
|
1673
|
+
function deriveBikelaneSurfaceTags(tags, category) {
|
|
1674
|
+
let parent;
|
|
1675
|
+
let parentDirectional = false;
|
|
1676
|
+
if (category.copySurfaceSmoothnessFromParent && typeof tags._parent === "object" && tags._parent) {
|
|
1677
|
+
const side = tags._side;
|
|
1678
|
+
const parentChoice = side === "left" || side === "right" ? chooseForSide(tags._parent, side) : choose(tags._parent);
|
|
1679
|
+
parent = override(tags._parent, parentChoice);
|
|
1680
|
+
parentDirectional = parentChoice.directional;
|
|
1681
|
+
}
|
|
1682
|
+
if (category.bicycleSurface == null) {
|
|
1683
|
+
if (parent == null) return { tags, directional: false, parentDirectional: false };
|
|
1684
|
+
return {
|
|
1685
|
+
tags: override(
|
|
1686
|
+
tags,
|
|
1687
|
+
{ surface: tags.surface, smoothness: tags.smoothness},
|
|
1688
|
+
parent
|
|
1689
|
+
),
|
|
1690
|
+
directional: false,
|
|
1691
|
+
parentDirectional
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
const choice = choose(tags);
|
|
1695
|
+
return {
|
|
1696
|
+
tags: override(tags, choice, parent),
|
|
1697
|
+
directional: choice.directional,
|
|
1698
|
+
parentDirectional
|
|
1699
|
+
};
|
|
1700
|
+
}
|
|
1701
|
+
function bikelaneSurfaceSource(surfaceTags, surfaceSource) {
|
|
1702
|
+
if (surfaceSource === "tag" && surfaceTags.directional) return "tag_directional";
|
|
1703
|
+
if (surfaceSource === "parent_highway_tag" && surfaceTags.parentDirectional) {
|
|
1704
|
+
return "parent_highway_tag_directional";
|
|
1705
|
+
}
|
|
1706
|
+
return surfaceSource;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// src/derive/derive-oneway.ts
|
|
1710
|
+
var WITH_WAY = /* @__PURE__ */ new Set(["yes", "1"]);
|
|
1711
|
+
var AGAINST_WAY = /* @__PURE__ */ new Set(["-1"]);
|
|
1712
|
+
var isWithWay = (value) => value != null && WITH_WAY.has(value);
|
|
1713
|
+
var isAgainstWay = (value) => value != null && AGAINST_WAY.has(value);
|
|
1714
|
+
function sideDefaultAgainstWay(tags) {
|
|
1715
|
+
return defaultSideRunsAgainstWay(tags._parent ?? {}, tags._side);
|
|
1716
|
+
}
|
|
1717
|
+
function defaultSideRunsAgainstWay(road, side) {
|
|
1718
|
+
const contraflowAllowed = road["oneway:bicycle"] === "no";
|
|
1719
|
+
if (isWithWay(road.oneway)) {
|
|
1720
|
+
return contraflowAllowed && side === "left";
|
|
1721
|
+
}
|
|
1722
|
+
if (isAgainstWay(road.oneway)) {
|
|
1723
|
+
return !(contraflowAllowed && side === "right");
|
|
1724
|
+
}
|
|
1725
|
+
return side === "left";
|
|
1726
|
+
}
|
|
1727
|
+
function onewayValue(tags, category) {
|
|
1728
|
+
const oneway = tags.oneway;
|
|
1729
|
+
const onewayBicycle = tags["oneway:bicycle"];
|
|
1730
|
+
const isSide = tags._side === "left" || tags._side === "right";
|
|
1731
|
+
if (isWithWay(onewayBicycle) || isAgainstWay(onewayBicycle)) {
|
|
1732
|
+
return "yes";
|
|
1733
|
+
} else if (onewayBicycle === "no") {
|
|
1734
|
+
return isWithWay(oneway) || isAgainstWay(oneway) ? "car_not_bike" : "no";
|
|
1735
|
+
}
|
|
1736
|
+
if (isWithWay(oneway) || isAgainstWay(oneway)) return "yes";
|
|
1737
|
+
if (oneway === "no") return "no";
|
|
1738
|
+
if (isSide) return "implicit_yes";
|
|
1739
|
+
if (tags.highway === "service" || tags.highway === "track") return "assumed_no";
|
|
1740
|
+
if (category.implicitOneWay) return "implicit_yes";
|
|
1741
|
+
return "assumed_no";
|
|
1742
|
+
}
|
|
1743
|
+
function deriveOnewayDirection(tags, category) {
|
|
1744
|
+
const oneway = onewayValue(tags, category);
|
|
1745
|
+
if (tags._side !== "left" && tags._side !== "right") {
|
|
1746
|
+
return {
|
|
1747
|
+
oneway,
|
|
1748
|
+
lineReversed: isAgainstWay(tags.oneway) || isAgainstWay(tags["oneway:bicycle"])
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
if (oneway !== "yes" && oneway !== "implicit_yes") {
|
|
1752
|
+
return { oneway, lineReversed: tags._side === "left" };
|
|
1753
|
+
}
|
|
1754
|
+
if (isAgainstWay(tags["oneway:bicycle"]) || isAgainstWay(tags.oneway)) {
|
|
1755
|
+
return { oneway, lineReversed: true };
|
|
1756
|
+
} else if (isWithWay(tags.oneway)) {
|
|
1757
|
+
return { oneway, lineReversed: false };
|
|
1758
|
+
}
|
|
1759
|
+
return { oneway, lineReversed: sideDefaultAgainstWay(tags) };
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
// src/derive/derive-surface.ts
|
|
1763
|
+
function deriveSurface(tags) {
|
|
1764
|
+
if (tags.surface == null) return {};
|
|
1765
|
+
const surface = sanitizeSurface(tags);
|
|
1766
|
+
if (surface === DISALLOWED) return {};
|
|
1767
|
+
return { surface, surface_source: "tag", surface_confidence: "high" };
|
|
1768
|
+
}
|
|
1769
|
+
function deriveBikelaneSurface(tags, category) {
|
|
1770
|
+
const own = deriveSurface(tags);
|
|
1771
|
+
if (own.surface != null) {
|
|
1772
|
+
return { surface: own.surface, surface_source: "tag", surface_confidence: "high" };
|
|
1773
|
+
}
|
|
1774
|
+
const parent = tags._parent;
|
|
1775
|
+
if (category.copySurfaceSmoothnessFromParent && parent != null) {
|
|
1776
|
+
const parentSurface = deriveSurface(parent);
|
|
1777
|
+
if (parentSurface.surface != null) {
|
|
1778
|
+
return {
|
|
1779
|
+
surface: parentSurface.surface,
|
|
1780
|
+
surface_source: "parent_highway_tag",
|
|
1781
|
+
surface_confidence: "high"
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
return {};
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
// src/derive/derive-traffic-mode.ts
|
|
1789
|
+
var DIRECTIONAL_PARKING_INFERENCE_CATEGORIES = /* @__PURE__ */ new Set([
|
|
1790
|
+
"cyclewayOnHighway_advisory",
|
|
1791
|
+
"cyclewayOnHighway_advisoryOrExclusive",
|
|
1792
|
+
"cyclewayOnHighway_exclusive",
|
|
1793
|
+
"cyclewayOnHighwayBetweenLanes",
|
|
1794
|
+
"cyclewayOnHighwayProtected"
|
|
1795
|
+
]);
|
|
1796
|
+
var PARKING_ALLOWED = [
|
|
1797
|
+
"no",
|
|
1798
|
+
"yes",
|
|
1799
|
+
"lane",
|
|
1800
|
+
"street_side",
|
|
1801
|
+
"on_kerb",
|
|
1802
|
+
"half_on_kerb",
|
|
1803
|
+
"shoulder",
|
|
1804
|
+
"separate"
|
|
1805
|
+
];
|
|
1806
|
+
function sanitizeParking(value) {
|
|
1807
|
+
if (value == null) return void 0;
|
|
1808
|
+
return sanitizeForLogging(value, PARKING_ALLOWED);
|
|
1809
|
+
}
|
|
1810
|
+
function inferTrafficModeFromParking(centerlineTags, side) {
|
|
1811
|
+
const raw = centerlineTags[`parking:${side}`] ?? centerlineTags["parking:both"];
|
|
1812
|
+
const value = sanitizeParking(raw);
|
|
1813
|
+
if (removeDisallowedValue(value) == null) return void 0;
|
|
1814
|
+
if (value === "no") return void 0;
|
|
1815
|
+
return "parking";
|
|
1816
|
+
}
|
|
1817
|
+
function deriveTrafficMode(bikelaneTags, centerlineTags, categoryId, side) {
|
|
1818
|
+
const left = removeDisallowedValue(trafficMode(bikelaneTags, "left"));
|
|
1819
|
+
const right = removeDisallowedValue(trafficMode(bikelaneTags, "right"));
|
|
1820
|
+
if (left != null || right != null) {
|
|
1821
|
+
return { traffic_mode_left: left, traffic_mode_right: right };
|
|
1822
|
+
}
|
|
1823
|
+
const inferredLeft = inferTrafficModeFromParking(centerlineTags, "left");
|
|
1824
|
+
const inferredRight = inferTrafficModeFromParking(centerlineTags, "right");
|
|
1825
|
+
if (categoryId === "bicycleRoad" || categoryId === "bicycleRoad_vehicleDestination") {
|
|
1826
|
+
return { traffic_mode_left: inferredLeft, traffic_mode_right: inferredRight };
|
|
1827
|
+
}
|
|
1828
|
+
if (DIRECTIONAL_PARKING_INFERENCE_CATEGORIES.has(categoryId)) {
|
|
1829
|
+
return {
|
|
1830
|
+
traffic_mode_left: void 0,
|
|
1831
|
+
traffic_mode_right: inferTrafficModeFromParking(centerlineTags, side)
|
|
1832
|
+
};
|
|
1833
|
+
}
|
|
1834
|
+
return { traffic_mode_left: left, traffic_mode_right: right };
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
// src/helpers/road-width.ts
|
|
1838
|
+
var STREET_WIDTHS = {
|
|
1839
|
+
primary: 10,
|
|
1840
|
+
secondary: 8,
|
|
1841
|
+
tertiary: 6,
|
|
1842
|
+
residential: 6
|
|
1843
|
+
};
|
|
1844
|
+
function roadWidth(tags) {
|
|
1845
|
+
const width = parseWidth(tags.width) ?? parseWidth(tags.est_width);
|
|
1846
|
+
if (width !== void 0) return width;
|
|
1847
|
+
const byHighway = tags.highway === void 0 ? void 0 : STREET_WIDTHS[tags.highway];
|
|
1848
|
+
return byHighway ?? 8;
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
// src/helpers/highway-classes.ts
|
|
1852
|
+
var TRUNK_MOTORWAY_CLASSES = ["motorway", "motorway_link", "trunk", "trunk_link"];
|
|
1853
|
+
var MAJOR_ROAD_CLASSES = [
|
|
1854
|
+
"primary",
|
|
1855
|
+
"primary_link",
|
|
1856
|
+
"secondary",
|
|
1857
|
+
"secondary_link",
|
|
1858
|
+
"tertiary",
|
|
1859
|
+
"tertiary_link"
|
|
1860
|
+
];
|
|
1861
|
+
var MINOR_ROAD_CLASSES = [
|
|
1862
|
+
"unclassified",
|
|
1863
|
+
"residential",
|
|
1864
|
+
"road",
|
|
1865
|
+
"living_street",
|
|
1866
|
+
"pedestrian",
|
|
1867
|
+
"service"
|
|
1868
|
+
];
|
|
1869
|
+
var PATH_CLASSES = ["track", "path", "footway", "cycleway", "steps"];
|
|
1870
|
+
var SIDEPATH_HIGHWAY_CLASSES = /* @__PURE__ */ new Set([...PATH_CLASSES, "pedestrian"]);
|
|
1871
|
+
var ALLOWED_HIGHWAYS = /* @__PURE__ */ new Set([
|
|
1872
|
+
...TRUNK_MOTORWAY_CLASSES,
|
|
1873
|
+
...MAJOR_ROAD_CLASSES,
|
|
1874
|
+
...MINOR_ROAD_CLASSES,
|
|
1875
|
+
...PATH_CLASSES
|
|
1876
|
+
]);
|
|
1877
|
+
|
|
1878
|
+
// src/transform/prepare-tags.ts
|
|
1879
|
+
function restrictedAccessTags(tags) {
|
|
1880
|
+
const restricted = [];
|
|
1881
|
+
if (tags.access === "no") restricted.push("access");
|
|
1882
|
+
if (tags.highway === "cycleway" && tags.bicycle === "no") restricted.push("bicycle");
|
|
1883
|
+
if (tags.highway === "footway" && tags.foot === "no") restricted.push("foot");
|
|
1884
|
+
return restricted;
|
|
1885
|
+
}
|
|
1886
|
+
function transformLifecycleTags(tags) {
|
|
1887
|
+
if (!tags.highway) return;
|
|
1888
|
+
if (tags.construction != null && ALLOWED_HIGHWAYS.has(tags.construction)) {
|
|
1889
|
+
tags.highway = tags.construction;
|
|
1890
|
+
tags.lifecycle = "construction";
|
|
1891
|
+
tags.construction = void 0;
|
|
1892
|
+
}
|
|
1893
|
+
const constructionRestricted = restrictedAccessTags(tags);
|
|
1894
|
+
if (constructionRestricted.length > 0) {
|
|
1895
|
+
const text = `${tags["access:reason"] ?? ""} ${tags.description ?? ""} ${tags.note ?? ""}`.toLowerCase();
|
|
1896
|
+
if (containsSubstring(text, "construction") || containsSubstring(text, "baustelle")) {
|
|
1897
|
+
tags.lifecycle = "construction_no_access";
|
|
1898
|
+
for (const t of constructionRestricted) tags[t] = void 0;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
const blockedTerms = [
|
|
1902
|
+
"sperrung",
|
|
1903
|
+
"gesperrt",
|
|
1904
|
+
"blockiert",
|
|
1905
|
+
"blocked",
|
|
1906
|
+
"closure",
|
|
1907
|
+
"closed",
|
|
1908
|
+
"blocked off"
|
|
1909
|
+
];
|
|
1910
|
+
const blockedRestricted = restrictedAccessTags(tags);
|
|
1911
|
+
if (blockedRestricted.length > 0) {
|
|
1912
|
+
const text = `${tags.description ?? ""} ${tags.note ?? ""}`.toLowerCase();
|
|
1913
|
+
if (blockedTerms.some((term) => containsSubstring(text, term))) {
|
|
1914
|
+
tags.lifecycle = "blocked";
|
|
1915
|
+
for (const t of blockedRestricted) tags[t] = void 0;
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
transformTemporary(tags);
|
|
1919
|
+
}
|
|
1920
|
+
var TEMPORARY_SIDE_PREFIXES = ["cycleway", "sidewalk"].flatMap(
|
|
1921
|
+
(prefix) => ["", ":left", ":right", ":both"].map((infix) => `${prefix}${infix}`)
|
|
1922
|
+
);
|
|
1923
|
+
function transformTemporary(tags) {
|
|
1924
|
+
if (tags.temporary === "yes") {
|
|
1925
|
+
tags.temporary = void 0;
|
|
1926
|
+
tags.lifecycle ??= "temporary";
|
|
1927
|
+
}
|
|
1928
|
+
for (const prefix of TEMPORARY_SIDE_PREFIXES) {
|
|
1929
|
+
if (tags[`${prefix}:temporary`] !== "yes") continue;
|
|
1930
|
+
tags[`${prefix}:temporary`] = void 0;
|
|
1931
|
+
tags[`${prefix}:lifecycle`] ??= "temporary";
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
var CONTRAFLOW = {
|
|
1935
|
+
yes: { side: "left", otherSide: "right", oneway: "-1" },
|
|
1936
|
+
"-1": { side: "right", otherSide: "left", oneway: "yes" }
|
|
1937
|
+
};
|
|
1938
|
+
var OPPOSITE_INFRASTRUCTURE = {
|
|
1939
|
+
opposite_lane: "lane",
|
|
1940
|
+
opposite_track: "track"
|
|
1941
|
+
};
|
|
1942
|
+
function transformCyclewayOppositeSchema(tags) {
|
|
1943
|
+
const direction = tags.oneway === void 0 ? void 0 : CONTRAFLOW[tags.oneway];
|
|
1944
|
+
if (direction === void 0) return;
|
|
1945
|
+
if (tags.cycleway === "opposite") {
|
|
1946
|
+
tags.cycleway = "no";
|
|
1947
|
+
tags["oneway:bicycle"] = "no";
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
const infrastructure = tags.cycleway === void 0 ? void 0 : OPPOSITE_INFRASTRUCTURE[tags.cycleway];
|
|
1951
|
+
if (infrastructure !== void 0) {
|
|
1952
|
+
const sideKey = `cycleway:${direction.side}`;
|
|
1953
|
+
const sideOnewayKey = `${sideKey}:oneway`;
|
|
1954
|
+
tags.cycleway = void 0;
|
|
1955
|
+
tags[`cycleway:${direction.otherSide}`] = "no";
|
|
1956
|
+
tags[sideKey] = infrastructure;
|
|
1957
|
+
tags[sideOnewayKey] = tags[sideOnewayKey] ?? direction.oneway;
|
|
1958
|
+
tags["oneway:bicycle"] = "no";
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
function transformConstructionPrefix(tags) {
|
|
1962
|
+
const constructionKeys = [];
|
|
1963
|
+
for (const key of Object.keys(tags)) {
|
|
1964
|
+
const value = tags[key];
|
|
1965
|
+
if (value !== void 0 && key.startsWith("construction:")) constructionKeys.push([key, value]);
|
|
1966
|
+
}
|
|
1967
|
+
for (const [key, value] of constructionKeys) {
|
|
1968
|
+
const baseTag = key.slice("construction:".length);
|
|
1969
|
+
tags[baseTag] = value;
|
|
1970
|
+
tags[key] = void 0;
|
|
1971
|
+
if (/^(cycleway|sidewalk)(:|$)/.test(baseTag)) {
|
|
1972
|
+
tags[`${baseTag}:lifecycle`] = "construction";
|
|
1973
|
+
} else {
|
|
1974
|
+
tags.lifecycle = "construction";
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
function transformCyclewayBothPostfix(tags) {
|
|
1979
|
+
if (tags.cycleway === "no" && tags["cycleway:both"] == null && tags["cycleway:left"] == null && tags["cycleway:right"] == null) {
|
|
1980
|
+
tags["cycleway:both"] = "no";
|
|
1981
|
+
tags.cycleway = void 0;
|
|
1434
1982
|
}
|
|
1435
|
-
|
|
1983
|
+
}
|
|
1984
|
+
function prepareTags(tags) {
|
|
1985
|
+
transformLifecycleTags(tags);
|
|
1986
|
+
transformCyclewayOppositeSchema(tags);
|
|
1987
|
+
transformConstructionPrefix(tags);
|
|
1988
|
+
transformCyclewayBothPostfix(tags);
|
|
1436
1989
|
}
|
|
1437
1990
|
|
|
1438
|
-
// src/
|
|
1439
|
-
var
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
"
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1991
|
+
// src/transform/transformations.ts
|
|
1992
|
+
var SIDES = ["left", "right"];
|
|
1993
|
+
var META_PREFIXES = ["source:", "note:"];
|
|
1994
|
+
function unnestPrefixedTags(tags, prefix, infix, dest, metaPrefix) {
|
|
1995
|
+
const metaPrefixString = metaPrefix ?? "";
|
|
1996
|
+
const fullPrefix = metaPrefixString + prefix + infix;
|
|
1997
|
+
const prefixLen = fullPrefix.length;
|
|
1998
|
+
for (const key of Object.keys(tags)) {
|
|
1999
|
+
const val = tags[key];
|
|
2000
|
+
if (val === void 0) continue;
|
|
2001
|
+
if (!key.startsWith(fullPrefix)) continue;
|
|
2002
|
+
if (key === fullPrefix) {
|
|
2003
|
+
const destinationKey = metaPrefix ? metaPrefixString.slice(0, -1) : prefix;
|
|
2004
|
+
dest[destinationKey] = val;
|
|
2005
|
+
dest._infix = infix;
|
|
2006
|
+
} else {
|
|
2007
|
+
const extractedSuffix = key.slice(prefixLen + 1);
|
|
2008
|
+
const suffixKey = extractedSuffix.match(/^[^:]*/)[0];
|
|
2009
|
+
if (infix !== "" || !(suffixKey === "left" || suffixKey === "right" || suffixKey === "both")) {
|
|
2010
|
+
const destinationKey = metaPrefix ? metaPrefixString + extractedSuffix : extractedSuffix;
|
|
2011
|
+
dest[destinationKey] = val;
|
|
2012
|
+
dest._infix = infix;
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
return dest;
|
|
1450
2017
|
}
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
2018
|
+
var DIRECTED_PARENT_TAGS = ["cycleway:lanes", "bicycle:lanes"];
|
|
2019
|
+
var DIRECTED_SELF_TAGS = ["traffic_sign"];
|
|
2020
|
+
var SIDE_TO_DIRECTION2 = {
|
|
2021
|
+
"": "",
|
|
2022
|
+
both: "",
|
|
2023
|
+
left: ":backward",
|
|
2024
|
+
right: ":forward"
|
|
2025
|
+
};
|
|
2026
|
+
function convertDirectedTags(cycleway, directionReference) {
|
|
2027
|
+
const parent = cycleway._parent;
|
|
2028
|
+
const side = cycleway._side ?? "";
|
|
2029
|
+
for (const key of DIRECTED_PARENT_TAGS) {
|
|
2030
|
+
const directedKey = key + SIDE_TO_DIRECTION2[side];
|
|
2031
|
+
cycleway[key] = cycleway[key] ?? parent[key] ?? parent[directedKey];
|
|
2032
|
+
}
|
|
2033
|
+
for (const key of DIRECTED_SELF_TAGS) {
|
|
2034
|
+
if (directionReference === "self") {
|
|
2035
|
+
cycleway[key] = cycleway[key] ?? cycleway[`${key}:forward`];
|
|
2036
|
+
} else {
|
|
2037
|
+
const directedKey = key + SIDE_TO_DIRECTION2[side];
|
|
2038
|
+
cycleway[key] = cycleway[key] ?? cycleway[directedKey];
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
return cycleway;
|
|
1457
2042
|
}
|
|
1458
|
-
function
|
|
1459
|
-
const
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
2043
|
+
function getTransformedObjects(tags, transformations) {
|
|
2044
|
+
const center = { ...tags, _side: "self" };
|
|
2045
|
+
if (tags.highway != null && SIDEPATH_HIGHWAY_CLASSES.has(tags.highway)) {
|
|
2046
|
+
unnestPrefixedTags(tags, "cycleway", "", center);
|
|
2047
|
+
for (const mp of META_PREFIXES) unnestPrefixedTags(tags, "cycleway", "", center, mp);
|
|
2048
|
+
if (center.oneway === "yes" && tags["oneway:bicycle"] !== "no") {
|
|
2049
|
+
center.traffic_sign = center.traffic_sign ?? center["traffic_sign:forward"];
|
|
2050
|
+
}
|
|
2051
|
+
if (center.oneway === "-1" && tags["oneway:bicycle"] !== "no") {
|
|
2052
|
+
center.traffic_sign = center.traffic_sign ?? center["traffic_sign:backward"];
|
|
2053
|
+
}
|
|
2054
|
+
return [center];
|
|
1463
2055
|
}
|
|
1464
|
-
const
|
|
1465
|
-
const
|
|
1466
|
-
|
|
1467
|
-
|
|
2056
|
+
const results = [center];
|
|
2057
|
+
for (const transformation of transformations) {
|
|
2058
|
+
for (const side of SIDES) {
|
|
2059
|
+
if (tags.highway === transformation.highway) continue;
|
|
2060
|
+
const prefix = transformation.prefix;
|
|
2061
|
+
const newObj = {
|
|
2062
|
+
_prefix: prefix,
|
|
2063
|
+
_side: side,
|
|
2064
|
+
_parent_highway: tags.highway,
|
|
2065
|
+
highway: transformation.highway
|
|
2066
|
+
};
|
|
2067
|
+
newObj._parent = tags;
|
|
2068
|
+
unnestPrefixedTags(tags, prefix, "", newObj);
|
|
2069
|
+
unnestPrefixedTags(tags, prefix, ":both", newObj);
|
|
2070
|
+
unnestPrefixedTags(tags, prefix, `:${side}`, newObj);
|
|
2071
|
+
for (const mp of META_PREFIXES) {
|
|
2072
|
+
unnestPrefixedTags(tags, prefix, "", newObj, mp);
|
|
2073
|
+
unnestPrefixedTags(tags, prefix, ":both", newObj, mp);
|
|
2074
|
+
unnestPrefixedTags(tags, prefix, `:${side}`, newObj, mp);
|
|
2075
|
+
}
|
|
2076
|
+
if (newObj._infix !== void 0 && transformation.filter(newObj)) {
|
|
2077
|
+
convertDirectedTags(newObj, transformation.direction_reference);
|
|
2078
|
+
results.push(newObj);
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
1468
2081
|
}
|
|
1469
|
-
|
|
1470
|
-
|
|
2082
|
+
return results;
|
|
2083
|
+
}
|
|
2084
|
+
var BIKELANE_TRANSFORMATIONS = [
|
|
2085
|
+
{ highway: "cycleway", prefix: "cycleway", direction_reference: "self", filter: () => true },
|
|
2086
|
+
{
|
|
2087
|
+
highway: "footway",
|
|
2088
|
+
prefix: "sidewalk",
|
|
2089
|
+
direction_reference: "parent",
|
|
2090
|
+
filter: (t) => !(t.footway === "no" || t.footway === "separate")
|
|
1471
2091
|
}
|
|
1472
|
-
|
|
2092
|
+
];
|
|
2093
|
+
|
|
2094
|
+
// src/derive/road-todos.ts
|
|
2095
|
+
var SHARED_KEYS = ["cycleway", "cycleway:both", "cycleway:left", "cycleway:right"];
|
|
2096
|
+
var deprecatedCyclewayShared = {
|
|
2097
|
+
id: "deprecated_cycleway_shared",
|
|
2098
|
+
desc: "The tagging `cycleway=shared` (also `cycleway:both|left|right=shared`) is deprecated and should be replaced or removed.",
|
|
2099
|
+
todoTableOnly: false,
|
|
2100
|
+
condition: (tags) => SHARED_KEYS.some((key) => tags[key] === "shared")
|
|
2101
|
+
};
|
|
2102
|
+
var unusualWidth2 = {
|
|
2103
|
+
id: "unusual_width",
|
|
2104
|
+
desc: "Width that we cannot read or that is unusually high. Fix `width`, or confirm it with `check_date=*` or `check_date:width=*`.",
|
|
2105
|
+
todoTableOnly: true,
|
|
2106
|
+
// One todo per way: skip it when the self row in `bikelanes` has it already. A self row can read
|
|
2107
|
+
// another value (`cycleway:width`, `width:lanes`), so a self row alone is not enough.
|
|
2108
|
+
condition: (tags, result) => !result.selfBikelaneHasUnusualWidth && isUnusualWidth(tags, result)
|
|
2109
|
+
};
|
|
2110
|
+
var ROAD_TODOS = [deprecatedCyclewayShared, unusualWidth2];
|
|
2111
|
+
function deriveRoadTodos(tags, result = {}) {
|
|
2112
|
+
const resolved = {
|
|
2113
|
+
...result,
|
|
2114
|
+
width: result.width !== void 0 ? result.width : parseWidth(tags.width) ?? null
|
|
2115
|
+
};
|
|
2116
|
+
return ROAD_TODOS.filter((todo) => todo.condition(tags, resolved)).map((todo) => todo.id);
|
|
1473
2117
|
}
|
|
1474
2118
|
|
|
1475
2119
|
// src/categories/analyze-category-gaps.ts
|
|
@@ -1536,6 +2180,41 @@ function analyzeCategoryGaps(wayTags, results) {
|
|
|
1536
2180
|
}
|
|
1537
2181
|
|
|
1538
2182
|
// src/categories/plan-tags-for-category.ts
|
|
2183
|
+
var TAG_REASON_CODES = [
|
|
2184
|
+
/** `{category}`: a tag the category needs */
|
|
2185
|
+
"required_for_category",
|
|
2186
|
+
/** `{category}`: a tag that tells the refined category apart */
|
|
2187
|
+
"discriminator_for_category",
|
|
2188
|
+
"fixed_by_mapping_target",
|
|
2189
|
+
"bicycle_road",
|
|
2190
|
+
"bicycle_road_sign",
|
|
2191
|
+
"vehicle_destination",
|
|
2192
|
+
"bicycle_road_sign_vehicle_destination",
|
|
2193
|
+
"unsigned_cycleway",
|
|
2194
|
+
"unsigned_cycleway_no_sign",
|
|
2195
|
+
"footway_bicycles_allowed",
|
|
2196
|
+
"bicycle_allowed_on_footway",
|
|
2197
|
+
"footway_sign_bicycles_allowed",
|
|
2198
|
+
"on_highway_cycle_lane",
|
|
2199
|
+
"bus_lane_with_bicycles",
|
|
2200
|
+
"cycle_lane_shared_with_buses",
|
|
2201
|
+
"protected_lane_separation",
|
|
2202
|
+
"protected_lane_parking",
|
|
2203
|
+
"protected_lane_sidepath",
|
|
2204
|
+
"cycleway_crossing",
|
|
2205
|
+
/** `{from}`: `cycleway:both` (or `cycleway`) split into `cycleway:left` and `cycleway:right` */
|
|
2206
|
+
"split_both_sides",
|
|
2207
|
+
/** `{key}`: the `cycleway:<side>` (or `sidewalk:<side>`) value the category needs on that side */
|
|
2208
|
+
"side_presence",
|
|
2209
|
+
/** `{lifecycle}`: the lifecycle a mapping target asks for (`temporary=yes`, `construction:*`) */
|
|
2210
|
+
"lifecycle",
|
|
2211
|
+
/** conflict, `{lifecycle}` `{result}`: the side keeps another lifecycle (an existing one wins) */
|
|
2212
|
+
"lifecycle_not_reached",
|
|
2213
|
+
/** conflict, `{target}` `{result}`: the suggested edits do not reach the target */
|
|
2214
|
+
"plan_not_enough",
|
|
2215
|
+
/** conflict, `{target}` `{result}`: nothing could be derived */
|
|
2216
|
+
"plan_no_edits"
|
|
2217
|
+
];
|
|
1539
2218
|
function isPreciseTargetCategoryId(id) {
|
|
1540
2219
|
const def = CATEGORY_DEFINITIONS.find((c) => c.id === id);
|
|
1541
2220
|
return def != null && def.infrastructureExists && !isIncompleteCategoryId(id);
|
|
@@ -1555,109 +2234,343 @@ function resolveRefinedIdFromSpec(spec, idSuffix) {
|
|
|
1555
2234
|
const base = spec.id.replace(/_advisoryOrExclusive$/, "");
|
|
1556
2235
|
return `${base}${idSuffix}`;
|
|
1557
2236
|
}
|
|
1558
|
-
function findTransformedTags2(wayTags, side) {
|
|
2237
|
+
function findTransformedTags2(wayTags, side, prefix) {
|
|
1559
2238
|
const tags = { ...wayTags };
|
|
1560
2239
|
prepareTags(tags);
|
|
1561
|
-
const
|
|
1562
|
-
|
|
2240
|
+
const ofSide = getTransformedObjects(tags, BIKELANE_TRANSFORMATIONS).filter(
|
|
2241
|
+
(t) => (t._side ?? "self") === side
|
|
2242
|
+
);
|
|
2243
|
+
return ofSide.find((t) => t._prefix === prefix) ?? ofSide[0];
|
|
2244
|
+
}
|
|
2245
|
+
function categorySidePrefix(categoryId) {
|
|
2246
|
+
return SIDEWALK_CATEGORY.test(categoryId) ? "sidewalk" : "cycleway";
|
|
1563
2247
|
}
|
|
1564
|
-
function
|
|
1565
|
-
|
|
2248
|
+
function sidePrefixFor(targetCategoryId, side) {
|
|
2249
|
+
return side === "self" ? void 0 : categorySidePrefix(targetCategoryId);
|
|
2250
|
+
}
|
|
2251
|
+
function lifecycleOfSide(wayTags, side, prefix) {
|
|
2252
|
+
const road = { ...wayTags };
|
|
2253
|
+
prepareTags(road);
|
|
2254
|
+
return findTransformedTags2(wayTags, side, prefix)?.lifecycle ?? road.lifecycle;
|
|
2255
|
+
}
|
|
2256
|
+
function categorizeSide(wayTags, side, prefix) {
|
|
2257
|
+
const transformed = findTransformedTags2(wayTags, side, prefix);
|
|
1566
2258
|
if (!transformed) return null;
|
|
1567
2259
|
const category = categorizeBikelane(transformed);
|
|
1568
2260
|
return category?.id ?? null;
|
|
1569
2261
|
}
|
|
1570
2262
|
function writeKeyForSide(transformedKey, side, prefix) {
|
|
1571
|
-
if (side === "self"
|
|
2263
|
+
if (side === "self") return transformedKey;
|
|
2264
|
+
prefix ??= "cycleway";
|
|
1572
2265
|
if (prefix === "cycleway" || prefix === "sidewalk") {
|
|
2266
|
+
if (transformedKey === prefix) return `${prefix}:${side}`;
|
|
1573
2267
|
return `${prefix}:${side}:${transformedKey}`;
|
|
1574
2268
|
}
|
|
1575
2269
|
return transformedKey;
|
|
1576
2270
|
}
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
2271
|
+
var SIDE_PRESENCE = {
|
|
2272
|
+
cyclewayOnHighway_advisory: "lane",
|
|
2273
|
+
cyclewayOnHighway_exclusive: "lane",
|
|
2274
|
+
cyclewayOnHighway_advisoryOrExclusive: "lane",
|
|
2275
|
+
cyclewayOnHighwayBetweenLanes: "lane",
|
|
2276
|
+
cyclewayOnHighwayProtected: ["track", "lane"],
|
|
2277
|
+
cycleway_adjoining: "track",
|
|
2278
|
+
cycleway_isolated: "track",
|
|
2279
|
+
cycleway_adjoiningOrIsolated: "track",
|
|
2280
|
+
footAndCyclewayShared_adjoining: "track",
|
|
2281
|
+
footAndCyclewayShared_adjoiningOrIsolated: "track",
|
|
2282
|
+
footAndCyclewaySegregated_adjoining: "track",
|
|
2283
|
+
footAndCyclewaySegregated_adjoiningOrIsolated: "track",
|
|
2284
|
+
sharedMotorVehicleLane: "shared_lane",
|
|
2285
|
+
sharedBusLaneBusWithBike: "share_busway",
|
|
2286
|
+
sharedBusLaneBikeWithBus: "lane"
|
|
2287
|
+
};
|
|
2288
|
+
var SIDEWALK_CATEGORY = /^footwayBicycleYes_/;
|
|
2289
|
+
function setUpRoadSide(wayTags, side, targetCategoryId) {
|
|
2290
|
+
const tags = { ...wayTags };
|
|
2291
|
+
const add = [];
|
|
2292
|
+
const change = [];
|
|
2293
|
+
const remove = [];
|
|
2294
|
+
const bothKey = SIDEWALK_CATEGORY.test(targetCategoryId) ? void 0 : ["cycleway:both", "cycleway"].find((key) => tags[key] !== void 0);
|
|
2295
|
+
if (bothKey) {
|
|
2296
|
+
const moved = Object.keys(tags).filter(
|
|
2297
|
+
(key) => key === bothKey || key.startsWith(`${bothKey}:`) && !/^(left|right|both)(:|$)/.test(key.slice(bothKey.length + 1))
|
|
2298
|
+
);
|
|
2299
|
+
for (const from of moved) {
|
|
2300
|
+
const value = tags[from];
|
|
2301
|
+
const suffix = from.slice(bothKey.length);
|
|
2302
|
+
delete tags[from];
|
|
2303
|
+
remove.push(from);
|
|
2304
|
+
for (const each of ["left", "right"]) {
|
|
2305
|
+
const key = `cycleway:${each}${suffix}`;
|
|
2306
|
+
if (tags[key] !== void 0) continue;
|
|
2307
|
+
tags[key] = value;
|
|
2308
|
+
add.push({
|
|
2309
|
+
key,
|
|
2310
|
+
value,
|
|
2311
|
+
reason: `Split ${from} into the two sides`,
|
|
2312
|
+
reasonCode: "split_both_sides",
|
|
2313
|
+
reasonParams: { from }
|
|
2314
|
+
});
|
|
2315
|
+
}
|
|
1587
2316
|
}
|
|
1588
|
-
case "and":
|
|
1589
|
-
return predicate.predicates.reduce((sum, p) => sum + positiveMatchScore(tags, p), 0);
|
|
1590
|
-
case "or":
|
|
1591
|
-
return Math.max(0, ...predicate.predicates.map((p) => positiveMatchScore(tags, p)));
|
|
1592
|
-
default:
|
|
1593
|
-
return 0;
|
|
1594
2317
|
}
|
|
2318
|
+
const setSide = (key, value, why) => {
|
|
2319
|
+
const reason = { reason: why, reasonCode: "side_presence", reasonParams: { key } };
|
|
2320
|
+
const planned = add.find((entry) => entry.key === key);
|
|
2321
|
+
if (planned) Object.assign(planned, { value }, reason);
|
|
2322
|
+
else if (tags[key] === void 0) add.push({ key, value, ...reason });
|
|
2323
|
+
else change.push({ key, from: tags[key], to: value, ...reason });
|
|
2324
|
+
tags[key] = value;
|
|
2325
|
+
};
|
|
2326
|
+
const presence = [SIDE_PRESENCE[targetCategoryId] ?? []].flat();
|
|
2327
|
+
const presenceKey = `cycleway:${side}`;
|
|
2328
|
+
const current = tags[presenceKey];
|
|
2329
|
+
if (presence[0] && (current === void 0 || !presence.includes(current))) {
|
|
2330
|
+
setSide(presenceKey, presence[0], `The category needs ${presenceKey}=${presence[0]}`);
|
|
2331
|
+
}
|
|
2332
|
+
if (SIDEWALK_CATEGORY.test(targetCategoryId)) {
|
|
2333
|
+
const key = `sidewalk:${side}`;
|
|
2334
|
+
const present = [key, "sidewalk:both", "sidewalk"].some(
|
|
2335
|
+
(k) => tags[k] !== void 0 && tags[k] !== "no" && tags[k] !== "separate"
|
|
2336
|
+
);
|
|
2337
|
+
if (!present) setSide(key, "yes", `The category needs a sidewalk (${key}=yes)`);
|
|
2338
|
+
}
|
|
2339
|
+
return { tags, add, change, remove };
|
|
2340
|
+
}
|
|
2341
|
+
function isNoSign(value) {
|
|
2342
|
+
return value === "none" || value === "no";
|
|
2343
|
+
}
|
|
2344
|
+
var eqAtom = (key, value, reason, reasonCode) => ({
|
|
2345
|
+
key,
|
|
2346
|
+
accepts: (v) => v === value,
|
|
2347
|
+
value,
|
|
2348
|
+
reason,
|
|
2349
|
+
reasonCode
|
|
2350
|
+
});
|
|
2351
|
+
var pblSidepath = {
|
|
2352
|
+
key: "is_sidepath",
|
|
2353
|
+
accepts: (v) => v === "yes",
|
|
2354
|
+
holdsOn: categoryIsSidepath,
|
|
2355
|
+
value: "yes",
|
|
2356
|
+
reason: "Protected cycle lane: runs along a road",
|
|
2357
|
+
reasonCode: "protected_lane_sidepath"
|
|
2358
|
+
};
|
|
2359
|
+
var footwayOrPath = {
|
|
2360
|
+
key: "highway",
|
|
2361
|
+
accepts: (v) => v === "footway" || v === "path",
|
|
2362
|
+
value: "footway",
|
|
2363
|
+
reason: "Footway with bicycles allowed",
|
|
2364
|
+
reasonCode: "footway_bicycles_allowed"
|
|
2365
|
+
};
|
|
2366
|
+
var MACRO_PLAN_ALTERNATIVES = {
|
|
2367
|
+
bicycle_road_base: [
|
|
2368
|
+
[eqAtom("bicycle_road", "yes", "Fahrradstra\xDFe / bicycle road", "bicycle_road")],
|
|
2369
|
+
[
|
|
2370
|
+
{
|
|
2371
|
+
key: "traffic_sign",
|
|
2372
|
+
accepts: (v) => hasPrefix(v, "DE:244"),
|
|
2373
|
+
value: "DE:244.1",
|
|
2374
|
+
reason: "Fahrradstra\xDFe sign (DE:244.1)",
|
|
2375
|
+
reasonCode: "bicycle_road_sign"
|
|
2376
|
+
}
|
|
2377
|
+
]
|
|
2378
|
+
],
|
|
2379
|
+
bicycle_road_vehicle_destination: [
|
|
2380
|
+
[
|
|
2381
|
+
eqAtom("bicycle_road", "yes", "Fahrradstra\xDFe / bicycle road", "bicycle_road"),
|
|
2382
|
+
eqAtom(
|
|
2383
|
+
"vehicle",
|
|
2384
|
+
"destination",
|
|
2385
|
+
"Motor vehicles only for destination traffic (Anlieger frei)",
|
|
2386
|
+
"vehicle_destination"
|
|
2387
|
+
)
|
|
2388
|
+
],
|
|
2389
|
+
[
|
|
2390
|
+
{
|
|
2391
|
+
key: "traffic_sign",
|
|
2392
|
+
accepts: (v) => hasPrefix(v, "DE:244") && containsSubstring(v, "1020-30"),
|
|
2393
|
+
value: "DE:244.1,1020-30",
|
|
2394
|
+
reason: "Fahrradstra\xDFe sign with Anlieger frei (DE:244.1,1020-30)",
|
|
2395
|
+
reasonCode: "bicycle_road_sign_vehicle_destination"
|
|
2396
|
+
}
|
|
2397
|
+
]
|
|
2398
|
+
],
|
|
2399
|
+
unsigned_cycleway: [
|
|
2400
|
+
[
|
|
2401
|
+
eqAtom("highway", "cycleway", "Unsigned cycleway", "unsigned_cycleway"),
|
|
2402
|
+
{
|
|
2403
|
+
key: "traffic_sign",
|
|
2404
|
+
accepts: isNoSign,
|
|
2405
|
+
value: "none",
|
|
2406
|
+
reason: "Unsigned cycleway (traffic_sign=none)",
|
|
2407
|
+
reasonCode: "unsigned_cycleway_no_sign"
|
|
2408
|
+
}
|
|
2409
|
+
]
|
|
2410
|
+
],
|
|
2411
|
+
footway_bicycle_yes: [
|
|
2412
|
+
[
|
|
2413
|
+
footwayOrPath,
|
|
2414
|
+
eqAtom("bicycle", "yes", "Bicycle allowed on footway", "bicycle_allowed_on_footway")
|
|
2415
|
+
],
|
|
2416
|
+
[
|
|
2417
|
+
footwayOrPath,
|
|
2418
|
+
{
|
|
2419
|
+
key: "traffic_sign",
|
|
2420
|
+
accepts: (v) => containsSubstring(v, "1022-10"),
|
|
2421
|
+
value: "DE:239,1022-10",
|
|
2422
|
+
reason: "Footway sign with bicycles allowed (DE:239,1022-10)",
|
|
2423
|
+
reasonCode: "footway_sign_bicycles_allowed"
|
|
2424
|
+
}
|
|
2425
|
+
]
|
|
2426
|
+
],
|
|
2427
|
+
cycleway_on_highway_advisory_or_exclusive_base: [
|
|
2428
|
+
[
|
|
2429
|
+
eqAtom("highway", "cycleway", "On-highway cycle lane", "on_highway_cycle_lane"),
|
|
2430
|
+
{
|
|
2431
|
+
key: "cycleway",
|
|
2432
|
+
accepts: (v) => v === "lane" || v === "opposite_lane",
|
|
2433
|
+
value: "lane",
|
|
2434
|
+
reason: "On-highway cycle lane",
|
|
2435
|
+
reasonCode: "on_highway_cycle_lane"
|
|
2436
|
+
}
|
|
2437
|
+
]
|
|
2438
|
+
],
|
|
2439
|
+
shared_bus_lane_bus_with_bike: [
|
|
2440
|
+
[
|
|
2441
|
+
eqAtom("highway", "cycleway", "Bus lane with bicycles allowed", "bus_lane_with_bicycles"),
|
|
2442
|
+
eqAtom(
|
|
2443
|
+
"cycleway",
|
|
2444
|
+
"share_busway",
|
|
2445
|
+
"Bus lane with bicycles allowed",
|
|
2446
|
+
"bus_lane_with_bicycles"
|
|
2447
|
+
)
|
|
2448
|
+
]
|
|
2449
|
+
],
|
|
2450
|
+
shared_bus_lane_bike_with_bus: [
|
|
2451
|
+
[
|
|
2452
|
+
eqAtom("highway", "cycleway", "Cycle lane shared with buses", "cycle_lane_shared_with_buses"),
|
|
2453
|
+
eqAtom(
|
|
2454
|
+
"lane",
|
|
2455
|
+
"share_busway",
|
|
2456
|
+
"Cycle lane shared with buses",
|
|
2457
|
+
"cycle_lane_shared_with_buses"
|
|
2458
|
+
)
|
|
2459
|
+
]
|
|
2460
|
+
],
|
|
2461
|
+
cycleway_on_highway_protected: [
|
|
2462
|
+
[
|
|
2463
|
+
pblSidepath,
|
|
2464
|
+
{
|
|
2465
|
+
key: "separation:left",
|
|
2466
|
+
accepts: (v) => v != null && PROTECTIVE_SEPARATION.includes(v),
|
|
2467
|
+
value: PROTECTIVE_SEPARATION[0],
|
|
2468
|
+
reason: "Protected cycle lane: physical separation towards the road",
|
|
2469
|
+
reasonCode: "protected_lane_separation"
|
|
2470
|
+
}
|
|
2471
|
+
],
|
|
2472
|
+
[
|
|
2473
|
+
pblSidepath,
|
|
2474
|
+
eqAtom(
|
|
2475
|
+
"traffic_mode:left",
|
|
2476
|
+
"parking",
|
|
2477
|
+
"Protected cycle lane: parking towards the road",
|
|
2478
|
+
"protected_lane_parking"
|
|
2479
|
+
)
|
|
2480
|
+
]
|
|
2481
|
+
],
|
|
2482
|
+
crossing: [
|
|
2483
|
+
[
|
|
2484
|
+
eqAtom("highway", "cycleway", "Cycleway crossing", "cycleway_crossing"),
|
|
2485
|
+
eqAtom("cycleway", "crossing", "Cycleway crossing", "cycleway_crossing")
|
|
2486
|
+
]
|
|
2487
|
+
]
|
|
2488
|
+
};
|
|
2489
|
+
function valueForSubstring(key, substring) {
|
|
2490
|
+
if (key === "traffic_sign" && /^\d/.test(substring)) return `DE:${substring}`;
|
|
2491
|
+
return substring;
|
|
1595
2492
|
}
|
|
1596
|
-
function
|
|
2493
|
+
function alternativesOf(predicate, why) {
|
|
2494
|
+
const { reason, reasonCode, reasonParams } = why;
|
|
1597
2495
|
switch (predicate.op) {
|
|
1598
2496
|
case "eq":
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
return
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
const score = positiveMatchScore(tags, child);
|
|
1615
|
-
const leaves = countEqInLeaves(child);
|
|
1616
|
-
if (score > bestScore || score === bestScore && leaves > bestLeaves) {
|
|
1617
|
-
bestScore = score;
|
|
1618
|
-
bestLeaves = leaves;
|
|
1619
|
-
best = child;
|
|
2497
|
+
return [[{ ...eqAtom(predicate.key, predicate.value, reason, reasonCode), reasonParams }]];
|
|
2498
|
+
case "in": {
|
|
2499
|
+
const values = predicate.values;
|
|
2500
|
+
return [
|
|
2501
|
+
[
|
|
2502
|
+
{
|
|
2503
|
+
key: predicate.key,
|
|
2504
|
+
accepts: (v) => v != null && values.includes(v),
|
|
2505
|
+
value: values[0],
|
|
2506
|
+
reason,
|
|
2507
|
+
reasonCode,
|
|
2508
|
+
reasonParams
|
|
2509
|
+
}
|
|
2510
|
+
]
|
|
2511
|
+
];
|
|
1620
2512
|
}
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
2513
|
+
case "includes": {
|
|
2514
|
+
const { key, substring } = predicate;
|
|
2515
|
+
return [
|
|
2516
|
+
[
|
|
2517
|
+
{
|
|
2518
|
+
key,
|
|
2519
|
+
accepts: (v) => containsSubstring(v, substring),
|
|
2520
|
+
value: valueForSubstring(key, substring),
|
|
2521
|
+
reason,
|
|
2522
|
+
reasonCode,
|
|
2523
|
+
reasonParams
|
|
2524
|
+
}
|
|
2525
|
+
]
|
|
2526
|
+
];
|
|
2527
|
+
}
|
|
2528
|
+
case "hasPrefix": {
|
|
2529
|
+
const { key, prefix } = predicate;
|
|
2530
|
+
return [
|
|
2531
|
+
[
|
|
2532
|
+
{
|
|
2533
|
+
key,
|
|
2534
|
+
accepts: (v) => hasPrefix(v, prefix),
|
|
2535
|
+
value: prefix,
|
|
2536
|
+
reason,
|
|
2537
|
+
reasonCode,
|
|
2538
|
+
reasonParams
|
|
2539
|
+
}
|
|
2540
|
+
]
|
|
2541
|
+
];
|
|
2542
|
+
}
|
|
2543
|
+
case "exists":
|
|
2544
|
+
return [[{ key: predicate.key, accepts: (v) => v != null, reason, reasonCode, reasonParams }]];
|
|
2545
|
+
case "and": {
|
|
2546
|
+
let result = [[]];
|
|
1633
2547
|
for (const child of predicate.predicates) {
|
|
1634
|
-
|
|
2548
|
+
const childAlternatives = alternativesOf(child, why);
|
|
2549
|
+
const next = [];
|
|
2550
|
+
for (const left of result) {
|
|
2551
|
+
for (const right of childAlternatives) next.push([...left, ...right]);
|
|
2552
|
+
}
|
|
2553
|
+
result = next;
|
|
1635
2554
|
}
|
|
1636
|
-
return;
|
|
1637
|
-
case "or": {
|
|
1638
|
-
const best = pickOrBranch(tags, predicate.predicates);
|
|
1639
|
-
if (best) collectFromPredicate(best, tags, reason, out);
|
|
1640
|
-
return;
|
|
2555
|
+
return result;
|
|
1641
2556
|
}
|
|
2557
|
+
case "or":
|
|
2558
|
+
return predicate.predicates.flatMap((child) => alternativesOf(child, why));
|
|
1642
2559
|
case "macro":
|
|
2560
|
+
return MACRO_PLAN_ALTERNATIVES[predicate.name] ?? [[]];
|
|
1643
2561
|
case "literal":
|
|
1644
|
-
|
|
1645
|
-
case "notExists":
|
|
2562
|
+
return predicate.value ? [[]] : [];
|
|
1646
2563
|
case "neq":
|
|
1647
2564
|
case "notIn":
|
|
1648
|
-
case "
|
|
1649
|
-
case "hasPrefix":
|
|
2565
|
+
case "notExists":
|
|
1650
2566
|
case "hasSuffix":
|
|
1651
2567
|
case "hasTagWithPrefix":
|
|
1652
2568
|
case "not":
|
|
1653
|
-
return;
|
|
2569
|
+
return [[]];
|
|
1654
2570
|
default:
|
|
1655
|
-
return;
|
|
2571
|
+
return [[]];
|
|
1656
2572
|
}
|
|
1657
2573
|
}
|
|
1658
|
-
function discriminatorBaseId(targetCategoryId) {
|
|
1659
|
-
return targetCategoryId.replace(/_adjoining$/, "").replace(/_isolated$/, "").replace(/_advisory$/, "").replace(/_exclusive$/, "");
|
|
1660
|
-
}
|
|
1661
2574
|
function findParentSpecAndRefining(targetCategoryId) {
|
|
1662
2575
|
for (const parent of CATEGORY_SPECS) {
|
|
1663
2576
|
if (parent.id === targetCategoryId) return { parent };
|
|
@@ -1668,66 +2581,79 @@ function findParentSpecAndRefining(targetCategoryId) {
|
|
|
1668
2581
|
}
|
|
1669
2582
|
return void 0;
|
|
1670
2583
|
}
|
|
1671
|
-
function
|
|
1672
|
-
if (!parent.gapDiscriminators?.length) return [];
|
|
1673
|
-
const baseId = discriminatorBaseId(targetCategoryId);
|
|
1674
|
-
return parent.gapDiscriminators.filter((d) => {
|
|
1675
|
-
const unlocked = resolveUnlockCategory2(baseId, d.unlocksCategory);
|
|
1676
|
-
return unlocked === targetCategoryId;
|
|
1677
|
-
});
|
|
1678
|
-
}
|
|
1679
|
-
function requirementsFromSpec(targetCategoryId, tags) {
|
|
2584
|
+
function targetAlternatives(targetCategoryId) {
|
|
1680
2585
|
const resolved = findParentSpecAndRefining(targetCategoryId);
|
|
1681
2586
|
if (!resolved) return [];
|
|
1682
2587
|
const { parent, refining } = resolved;
|
|
1683
|
-
const
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
2588
|
+
const base = parent.match ? alternativesOf(parent.match, {
|
|
2589
|
+
reason: `Required for ${targetCategoryId}`,
|
|
2590
|
+
reasonCode: "required_for_category",
|
|
2591
|
+
reasonParams: { category: targetCategoryId }
|
|
2592
|
+
}) : [[]];
|
|
2593
|
+
if (!refining) return base;
|
|
2594
|
+
const refined = alternativesOf(refining.match, {
|
|
2595
|
+
reason: `Discriminator for ${targetCategoryId}`,
|
|
2596
|
+
reasonCode: "discriminator_for_category",
|
|
2597
|
+
reasonParams: { category: targetCategoryId }
|
|
2598
|
+
});
|
|
2599
|
+
return base.flatMap((left) => refined.map((right) => [...left, ...right]));
|
|
2600
|
+
}
|
|
2601
|
+
function categorySignOptions(categoryId) {
|
|
2602
|
+
const signs = /* @__PURE__ */ new Set();
|
|
2603
|
+
let unsignedPossible = false;
|
|
2604
|
+
for (const alternative of targetAlternatives(categoryId)) {
|
|
2605
|
+
const signAtoms = alternative.filter(
|
|
2606
|
+
(atom) => atom.key === "traffic_sign" && atom.value != null && !isNoSign(atom.value)
|
|
2607
|
+
);
|
|
2608
|
+
for (const atom of signAtoms) signs.add(atom.value);
|
|
2609
|
+
if (signAtoms.length === 0) unsignedPossible = true;
|
|
1698
2610
|
}
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
requirements.push({
|
|
1707
|
-
key: disc.key,
|
|
1708
|
-
values: [value],
|
|
1709
|
-
reason: disc.reason
|
|
1710
|
-
});
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
2611
|
+
return { signs: [...signs], unsignedPossible };
|
|
2612
|
+
}
|
|
2613
|
+
function editCost(key, from, to, side) {
|
|
2614
|
+
if (key === "highway") return 10;
|
|
2615
|
+
if (key === "traffic_sign") {
|
|
2616
|
+
if (from == null) return isNoSign(to) ? 1 : 4;
|
|
2617
|
+
return 5;
|
|
1713
2618
|
}
|
|
1714
|
-
return
|
|
2619
|
+
if (from != null) return 3;
|
|
2620
|
+
if (key === "cycleway" && side === "self") return 3;
|
|
2621
|
+
return 1;
|
|
1715
2622
|
}
|
|
1716
|
-
function
|
|
1717
|
-
const
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
const
|
|
1725
|
-
|
|
2623
|
+
function candidateFor(alternative, base, fixedKeys, side) {
|
|
2624
|
+
const edits = /* @__PURE__ */ new Map();
|
|
2625
|
+
const ordered = [...alternative].sort(
|
|
2626
|
+
(a, b) => Number(a.value === void 0) - Number(b.value === void 0)
|
|
2627
|
+
);
|
|
2628
|
+
let cost = 0;
|
|
2629
|
+
for (const atom of ordered) {
|
|
2630
|
+
const planned = edits.get(atom.key)?.value;
|
|
2631
|
+
const current = planned ?? base[atom.key];
|
|
2632
|
+
if (atom.accepts(current)) continue;
|
|
2633
|
+
if (planned === void 0 && atom.holdsOn?.(base)) continue;
|
|
2634
|
+
if (planned !== void 0) return void 0;
|
|
2635
|
+
if (atom.value === void 0) return void 0;
|
|
2636
|
+
if (atom.key.startsWith("_")) return void 0;
|
|
2637
|
+
if (atom.key === "highway" && side !== "self") return void 0;
|
|
2638
|
+
if (fixedKeys.has(atom.key)) return void 0;
|
|
2639
|
+
if (atom.key === "traffic_sign" && isNoSign(base.traffic_sign)) return void 0;
|
|
2640
|
+
edits.set(atom.key, {
|
|
2641
|
+
value: atom.value,
|
|
2642
|
+
reason: atom.reason,
|
|
2643
|
+
reasonCode: atom.reasonCode,
|
|
2644
|
+
reasonParams: atom.reasonParams
|
|
2645
|
+
});
|
|
2646
|
+
cost += editCost(atom.key, base[atom.key], atom.value, side);
|
|
1726
2647
|
}
|
|
1727
|
-
return
|
|
2648
|
+
return { edits, cost };
|
|
2649
|
+
}
|
|
2650
|
+
function reasonOf(why) {
|
|
2651
|
+
const { reason, reasonCode, reasonParams } = why;
|
|
2652
|
+
return reasonParams ? { reason, reasonCode, reasonParams } : { reason, reasonCode };
|
|
1728
2653
|
}
|
|
1729
|
-
function applyPlanToWayTags(wayTags, add, change) {
|
|
2654
|
+
function applyPlanToWayTags(wayTags, add, change, remove = []) {
|
|
1730
2655
|
const next = { ...wayTags };
|
|
2656
|
+
for (const key of remove) delete next[key];
|
|
1731
2657
|
for (const entry of change) {
|
|
1732
2658
|
next[entry.key] = entry.to;
|
|
1733
2659
|
}
|
|
@@ -1736,17 +2662,6 @@ function applyPlanToWayTags(wayTags, add, change) {
|
|
|
1736
2662
|
}
|
|
1737
2663
|
return next;
|
|
1738
2664
|
}
|
|
1739
|
-
function trafficSignSatisfied(tags, value) {
|
|
1740
|
-
return tags.traffic_sign?.includes(value) === true;
|
|
1741
|
-
}
|
|
1742
|
-
function pickPreferredValue(req, tags) {
|
|
1743
|
-
if (req.key === "traffic_sign") {
|
|
1744
|
-
return req.values[0];
|
|
1745
|
-
}
|
|
1746
|
-
const current = tagValue2(tags, req.key);
|
|
1747
|
-
if (current != null && req.values.includes(current)) return current;
|
|
1748
|
-
return req.values[0];
|
|
1749
|
-
}
|
|
1750
2665
|
function listTargetCategories(options) {
|
|
1751
2666
|
const all = CATEGORY_DEFINITIONS.map((c) => c.id).filter(isPreciseTargetCategoryId);
|
|
1752
2667
|
const fromCategory = options?.fromCategory;
|
|
@@ -1777,86 +2692,210 @@ var UnknownTargetCategoryError = class extends Error {
|
|
|
1777
2692
|
}
|
|
1778
2693
|
targetCategoryId;
|
|
1779
2694
|
};
|
|
2695
|
+
var FIXED_REASON = {
|
|
2696
|
+
reason: "Fixed tag of the mapping target",
|
|
2697
|
+
reasonCode: "fixed_by_mapping_target"
|
|
2698
|
+
};
|
|
1780
2699
|
function planTagsForCategory(wayTags, targetCategoryId, options) {
|
|
1781
2700
|
const spec = specByCategoryId(targetCategoryId);
|
|
1782
2701
|
if (!spec) {
|
|
1783
2702
|
throw new UnknownTargetCategoryError(targetCategoryId);
|
|
1784
2703
|
}
|
|
1785
2704
|
const side = options?.side ?? "self";
|
|
1786
|
-
const
|
|
1787
|
-
const
|
|
1788
|
-
const currentCategoryId = categorizeSide(wayTags, side);
|
|
1789
|
-
const
|
|
1790
|
-
|
|
2705
|
+
const fixed = options?.fixed ?? {};
|
|
2706
|
+
const sidePrefix = sidePrefixFor(targetCategoryId, side);
|
|
2707
|
+
const currentCategoryId = categorizeSide(wayTags, side, sidePrefix);
|
|
2708
|
+
const noSetup = { tags: wayTags, add: [], change: [], remove: [] };
|
|
2709
|
+
const setup = side === "self" ? noSetup : setUpRoadSide(wayTags, side, targetCategoryId);
|
|
2710
|
+
const working = setup.tags;
|
|
2711
|
+
const transformed = findTransformedTags2(working, side, sidePrefix);
|
|
2712
|
+
const prefix = transformed?._prefix ?? sidePrefix ?? null;
|
|
2713
|
+
const tags = transformed ?? working;
|
|
2714
|
+
const plan = (add2, change2, key, value, why) => {
|
|
2715
|
+
const writeKey = writeKeyForSide(key, side, prefix);
|
|
2716
|
+
const planned = add2.findIndex((entry) => entry.key === writeKey);
|
|
2717
|
+
if (planned >= 0) {
|
|
2718
|
+
add2[planned] = { key: writeKey, value, ...why };
|
|
2719
|
+
return;
|
|
2720
|
+
}
|
|
2721
|
+
const plannedChange = change2.findIndex((entry) => entry.key === writeKey);
|
|
2722
|
+
if (plannedChange >= 0) {
|
|
2723
|
+
const from = change2[plannedChange].from;
|
|
2724
|
+
change2.splice(plannedChange, 1);
|
|
2725
|
+
if (from !== value) change2.push({ key: writeKey, from, to: value, ...why });
|
|
2726
|
+
return;
|
|
2727
|
+
}
|
|
2728
|
+
const current = working[writeKey] ?? tags[key];
|
|
2729
|
+
if (current === value) return;
|
|
2730
|
+
if (current == null) add2.push({ key: writeKey, value, ...why });
|
|
2731
|
+
else change2.push({ key: writeKey, from: current, to: value, ...why });
|
|
2732
|
+
};
|
|
2733
|
+
const fixedAdd = [];
|
|
2734
|
+
const fixedChange = [];
|
|
2735
|
+
for (const [key, value] of Object.entries(fixed)) {
|
|
2736
|
+
plan(fixedAdd, fixedChange, key, value, FIXED_REASON);
|
|
2737
|
+
}
|
|
2738
|
+
const lifecycle = options?.lifecycle;
|
|
2739
|
+
const lifecycleHolds = (next) => lifecycle === void 0 || lifecycleOfSide(next, side, sidePrefix) === lifecycle;
|
|
2740
|
+
const lifecycleWhy = {
|
|
2741
|
+
reason: `The mapping target is ${lifecycle}`,
|
|
2742
|
+
reasonCode: "lifecycle",
|
|
2743
|
+
reasonParams: { lifecycle: lifecycle ?? "" }
|
|
2744
|
+
};
|
|
2745
|
+
const withLifecycle = (add2, change2, remove2) => {
|
|
2746
|
+
if (lifecycle === void 0) return;
|
|
2747
|
+
const next = applyPlanToWayTags(wayTags, add2, change2, remove2);
|
|
2748
|
+
if (lifecycleHolds(next)) return;
|
|
2749
|
+
if (lifecycle === "temporary") {
|
|
2750
|
+
plan(add2, change2, "temporary", "yes", lifecycleWhy);
|
|
2751
|
+
return;
|
|
2752
|
+
}
|
|
2753
|
+
if (side === "self") {
|
|
2754
|
+
const highway = next.highway;
|
|
2755
|
+
if (highway === void 0 || highway === "construction") return;
|
|
2756
|
+
plan(add2, change2, "highway", "construction", lifecycleWhy);
|
|
2757
|
+
plan(add2, change2, "construction", highway, lifecycleWhy);
|
|
2758
|
+
return;
|
|
2759
|
+
}
|
|
2760
|
+
const presenceKey = `${sidePrefix ?? "cycleway"}:${side}`;
|
|
2761
|
+
const value = next[presenceKey] ?? "yes";
|
|
2762
|
+
const plannedAdd = add2.findIndex((entry) => entry.key === presenceKey);
|
|
2763
|
+
if (plannedAdd >= 0) add2.splice(plannedAdd, 1);
|
|
2764
|
+
const plannedChange = change2.findIndex((entry) => entry.key === presenceKey);
|
|
2765
|
+
if (plannedChange >= 0) change2.splice(plannedChange, 1);
|
|
2766
|
+
if (wayTags[presenceKey] !== void 0 && !remove2.includes(presenceKey))
|
|
2767
|
+
remove2.push(presenceKey);
|
|
2768
|
+
add2.push({ key: `construction:${presenceKey}`, value, ...lifecycleWhy });
|
|
2769
|
+
};
|
|
2770
|
+
if (currentCategoryId === targetCategoryId && !fixedAdd.length && !fixedChange.length && lifecycleHolds(wayTags)) {
|
|
1791
2771
|
return {
|
|
1792
2772
|
targetCategoryId,
|
|
1793
2773
|
currentCategoryId,
|
|
1794
2774
|
aligned: true,
|
|
1795
2775
|
add: [],
|
|
1796
2776
|
change: [],
|
|
2777
|
+
remove: [],
|
|
1797
2778
|
conflicts: []
|
|
1798
2779
|
};
|
|
1799
2780
|
}
|
|
1800
|
-
const
|
|
1801
|
-
const
|
|
1802
|
-
const
|
|
1803
|
-
const
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
reason: req.reason
|
|
1820
|
-
});
|
|
1821
|
-
}
|
|
1822
|
-
continue;
|
|
2781
|
+
const base = { ...tags, ...fixed };
|
|
2782
|
+
const fixedKeys = new Set(Object.keys(fixed));
|
|
2783
|
+
const candidates = [{ edits: /* @__PURE__ */ new Map(), cost: 0 }];
|
|
2784
|
+
for (const alternative of targetAlternatives(targetCategoryId)) {
|
|
2785
|
+
const candidate = candidateFor(alternative, base, fixedKeys, side);
|
|
2786
|
+
if (candidate) candidates.push(candidate);
|
|
2787
|
+
}
|
|
2788
|
+
candidates.sort((a, b) => a.cost - b.cost);
|
|
2789
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2790
|
+
let fallback;
|
|
2791
|
+
for (const candidate of candidates) {
|
|
2792
|
+
const signature = [...candidate.edits.entries()].map(([k, v]) => `${k}=${v.value}`).sort().join(";");
|
|
2793
|
+
if (seen.has(signature)) continue;
|
|
2794
|
+
seen.add(signature);
|
|
2795
|
+
const add2 = [...setup.add, ...fixedAdd];
|
|
2796
|
+
const change2 = [...setup.change, ...fixedChange];
|
|
2797
|
+
const remove2 = [...setup.remove];
|
|
2798
|
+
for (const [key, edit] of candidate.edits) {
|
|
2799
|
+
plan(add2, change2, key, edit.value, reasonOf(edit));
|
|
1823
2800
|
}
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
2801
|
+
withLifecycle(add2, change2, remove2);
|
|
2802
|
+
const next = applyPlanToWayTags(wayTags, add2, change2, remove2);
|
|
2803
|
+
const result = categorizeSide(next, side, sidePrefix);
|
|
2804
|
+
if (result === targetCategoryId && lifecycleHolds(next)) {
|
|
2805
|
+
return {
|
|
2806
|
+
targetCategoryId,
|
|
2807
|
+
currentCategoryId,
|
|
2808
|
+
aligned: true,
|
|
2809
|
+
add: add2,
|
|
2810
|
+
change: change2,
|
|
2811
|
+
remove: remove2,
|
|
2812
|
+
conflicts: []
|
|
2813
|
+
};
|
|
1832
2814
|
}
|
|
1833
|
-
if (
|
|
1834
|
-
add
|
|
1835
|
-
key: writeKey,
|
|
1836
|
-
value: pickPreferredValue(req, tags),
|
|
1837
|
-
reason: req.reason
|
|
1838
|
-
});
|
|
2815
|
+
if (!fallback || !fallback.add.length && !fallback.change.length) {
|
|
2816
|
+
fallback = { add: add2, change: change2, remove: remove2, result, next };
|
|
1839
2817
|
}
|
|
1840
2818
|
}
|
|
1841
|
-
const
|
|
1842
|
-
const
|
|
1843
|
-
const
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
2819
|
+
const add = fallback?.add ?? [];
|
|
2820
|
+
const change = fallback?.change ?? [];
|
|
2821
|
+
const remove = fallback?.remove ?? setup.remove;
|
|
2822
|
+
const resultCategory = fallback?.result ?? currentCategoryId;
|
|
2823
|
+
if (resultCategory === targetCategoryId && lifecycle !== void 0) {
|
|
2824
|
+
const result = lifecycleOfSide(fallback?.next ?? wayTags, side, sidePrefix) ?? "none";
|
|
2825
|
+
return {
|
|
2826
|
+
targetCategoryId,
|
|
2827
|
+
currentCategoryId,
|
|
2828
|
+
aligned: false,
|
|
2829
|
+
add,
|
|
2830
|
+
change,
|
|
2831
|
+
remove,
|
|
2832
|
+
conflicts: [
|
|
2833
|
+
{
|
|
2834
|
+
key: "_lifecycle",
|
|
2835
|
+
value: result,
|
|
2836
|
+
reason: `The side keeps lifecycle=${result}; an existing lifecycle wins over ${lifecycle}.`,
|
|
2837
|
+
reasonCode: "lifecycle_not_reached",
|
|
2838
|
+
reasonParams: { lifecycle, result }
|
|
2839
|
+
}
|
|
2840
|
+
]
|
|
2841
|
+
};
|
|
1850
2842
|
}
|
|
2843
|
+
const suggested = add.length > 0 || change.length > 0 ? "Suggested tag edits are not enough to reach that classification." : "No automatic tag edits could be derived for this category (often because it matches via a complex macro).";
|
|
1851
2844
|
return {
|
|
1852
2845
|
targetCategoryId,
|
|
1853
2846
|
currentCategoryId,
|
|
1854
|
-
aligned,
|
|
2847
|
+
aligned: false,
|
|
1855
2848
|
add,
|
|
1856
2849
|
change,
|
|
1857
|
-
|
|
2850
|
+
remove,
|
|
2851
|
+
conflicts: [
|
|
2852
|
+
{
|
|
2853
|
+
key: "_category",
|
|
2854
|
+
value: resultCategory ?? "null",
|
|
2855
|
+
reason: `${suggested} Target \u201C${targetCategoryId}\u201D would still classify as ${resultCategory ?? "none"}.`,
|
|
2856
|
+
reasonCode: add.length > 0 || change.length > 0 ? "plan_not_enough" : "plan_no_edits",
|
|
2857
|
+
reasonParams: { target: targetCategoryId, result: resultCategory ?? "none" }
|
|
2858
|
+
}
|
|
2859
|
+
]
|
|
1858
2860
|
};
|
|
1859
2861
|
}
|
|
2862
|
+
function planSignature(plan) {
|
|
2863
|
+
return [
|
|
2864
|
+
...plan.add.map((e) => `+${e.key}=${e.value}`),
|
|
2865
|
+
...plan.change.map((e) => `~${e.key}=${e.to}`),
|
|
2866
|
+
...plan.remove.map((key) => `-${key}`)
|
|
2867
|
+
].sort().join(";");
|
|
2868
|
+
}
|
|
2869
|
+
function planTagVariantsForCategory(wayTags, targetCategoryId, options) {
|
|
2870
|
+
const first = planTagsForCategory(wayTags, targetCategoryId, options);
|
|
2871
|
+
const variants = [{ ...first, variantId: "default" }];
|
|
2872
|
+
if (options?.fixed?.traffic_sign !== void 0) return variants;
|
|
2873
|
+
const { signs, unsignedPossible } = categorySignOptions(targetCategoryId);
|
|
2874
|
+
if (!signs.length) return variants;
|
|
2875
|
+
const seen = /* @__PURE__ */ new Set([planSignature(first)]);
|
|
2876
|
+
const push = (variantId, fixedSign) => {
|
|
2877
|
+
const plan = planTagsForCategory(wayTags, targetCategoryId, {
|
|
2878
|
+
...options,
|
|
2879
|
+
fixed: { ...options?.fixed, traffic_sign: fixedSign }
|
|
2880
|
+
});
|
|
2881
|
+
const signature = planSignature(plan);
|
|
2882
|
+
if (!plan.aligned || seen.has(signature)) return;
|
|
2883
|
+
seen.add(signature);
|
|
2884
|
+
variants.push({ ...plan, variantId });
|
|
2885
|
+
};
|
|
2886
|
+
const side = options?.side ?? "self";
|
|
2887
|
+
const currentSign = findTransformedTags2(
|
|
2888
|
+
wayTags,
|
|
2889
|
+
side,
|
|
2890
|
+
sidePrefixFor(targetCategoryId, side)
|
|
2891
|
+
)?.traffic_sign;
|
|
2892
|
+
const signHolds = signs.some(
|
|
2893
|
+
(sign) => currentSign != null && containsSubstring(currentSign, sign)
|
|
2894
|
+
);
|
|
2895
|
+
if (!signHolds) push("with_sign", signs[0]);
|
|
2896
|
+
if (unsignedPossible && !isNoSign(currentSign)) push("without_sign", "none");
|
|
2897
|
+
return variants;
|
|
2898
|
+
}
|
|
1860
2899
|
|
|
1861
2900
|
// src/index.ts
|
|
1862
2901
|
function clean(value) {
|
|
@@ -1878,8 +2917,15 @@ function processBikelanes(objectTags) {
|
|
|
1878
2917
|
category: category.id
|
|
1879
2918
|
};
|
|
1880
2919
|
if (category.infrastructureExists) {
|
|
1881
|
-
|
|
1882
|
-
result.
|
|
2920
|
+
const direction = deriveOnewayDirection(t, category);
|
|
2921
|
+
result.oneway = direction.oneway;
|
|
2922
|
+
result._lineReversed = direction.lineReversed;
|
|
2923
|
+
if (t._side === "left" || t._side === "right") {
|
|
2924
|
+
const laneLeftOfLine = t._side === "left" !== direction.lineReversed;
|
|
2925
|
+
result.offset = (laneLeftOfLine ? 1 : -1) * roadWidth(t._parent ?? tags) / 2;
|
|
2926
|
+
}
|
|
2927
|
+
result.lifecycle = t.lifecycle ?? tags.lifecycle ?? null;
|
|
2928
|
+
result.width = parseWidth(t.width) ?? null;
|
|
1883
2929
|
result.surface_color = clean(surfaceColor(t));
|
|
1884
2930
|
result.separation_left = clean(separation(t, "left"));
|
|
1885
2931
|
result.separation_right = clean(separation(t, "right"));
|
|
@@ -1892,18 +2938,29 @@ function processBikelanes(objectTags) {
|
|
|
1892
2938
|
result.traffic_mode_right = tm.traffic_mode_right ?? null;
|
|
1893
2939
|
const ts = deriveTrafficSigns(t);
|
|
1894
2940
|
result.traffic_sign = ts.traffic_sign ?? null;
|
|
1895
|
-
const
|
|
2941
|
+
const surfaceTags = deriveBikelaneSurfaceTags(t, category);
|
|
2942
|
+
const surf = deriveBikelaneSurface(surfaceTags.tags, category);
|
|
1896
2943
|
result.surface = surf.surface ?? null;
|
|
1897
|
-
result.surface_source = surf.surface_source ?? null;
|
|
2944
|
+
result.surface_source = bikelaneSurfaceSource(surfaceTags, surf.surface_source) ?? null;
|
|
1898
2945
|
result.surface_confidence = surf.surface_confidence ?? null;
|
|
1899
|
-
const smooth = deriveBikelaneSmoothness(
|
|
2946
|
+
const smooth = deriveBikelaneSmoothness(surfaceTags.tags, category);
|
|
1900
2947
|
result.smoothness = smooth.smoothness ?? null;
|
|
1901
2948
|
result.smoothness_source = smooth.smoothness_source ?? null;
|
|
1902
2949
|
result.smoothness_confidence = smooth.smoothness_confidence ?? null;
|
|
2950
|
+
const todo = deriveBikelaneTodos(t, {
|
|
2951
|
+
category: category.id,
|
|
2952
|
+
width: result.width,
|
|
2953
|
+
surface: result.surface,
|
|
2954
|
+
surface_source: result.surface_source,
|
|
2955
|
+
oneway: result.oneway,
|
|
2956
|
+
implicitOneWayConfidence: category.implicitOneWayConfidence
|
|
2957
|
+
});
|
|
2958
|
+
result.todos = todo.todos;
|
|
2959
|
+
if (todo.todoTagFixes) result.todoTagFixes = todo.todoTagFixes;
|
|
1903
2960
|
}
|
|
1904
2961
|
results.push(result);
|
|
1905
2962
|
}
|
|
1906
2963
|
return results;
|
|
1907
2964
|
}
|
|
1908
2965
|
|
|
1909
|
-
export { ALLOWED_HIGHWAYS, BIKELANE_TRANSFORMATIONS, CATEGORY_DEFINITIONS, CATEGORY_SPECS, MAJOR_ROAD_CLASSES, MINOR_ROAD_CLASSES, PATH_CLASSES, SIDEPATH_HIGHWAY_CLASSES, TRUNK_MOTORWAY_CLASSES, UnknownTargetCategoryError, analyzeCategoryGaps, categorizeBikelane, getTransformedObjects, isIncompleteCategoryId, listTargetCategories, planTagsForCategory, prepareTags, processBikelanes, specsWithGapDiscriminators, writeKeyForSide };
|
|
2966
|
+
export { ALLOWED_HIGHWAYS, BIKELANE_TODOS, BIKELANE_TRANSFORMATIONS, CATEGORY_DEFINITIONS, CATEGORY_SPECS, DIRECTIONAL_PARKING_INFERENCE_CATEGORIES, MAJOR_ROAD_CLASSES, MARKING_ALLOWED, MINOR_ROAD_CLASSES, PARKING_ALLOWED, PATH_CLASSES, PROTECTIVE_SEPARATION, ROAD_TODOS, SEPARATION_ALLOWED, SIDEPATH_HIGHWAY_CLASSES, SURFACE_ALLOWED, SURFACE_COLOR_ALLOWED, TAG_REASON_CODES, TRAFFIC_MODE_ALLOWED, TRUNK_MOTORWAY_CLASSES, UnknownTargetCategoryError, analyzeCategoryGaps, categorizeBikelane, categorySidePrefix, categorySignOptions, defaultSideRunsAgainstWay, deriveBikelaneTodos, deriveRoadTodos, getTransformedObjects, isIncompleteCategoryId, isUnusualWidth, listTargetCategories, parseLength, parseWidth, planTagVariantsForCategory, planTagsForCategory, prepareTags, processBikelanes, specsWithGapDiscriminators, writeKeyForSide };
|