@tilda-geo/bicycle-infrastructure 0.2.0 → 0.3.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/README.md CHANGED
@@ -19,7 +19,7 @@ npm install @tilda-geo/bicycle-infrastructure
19
19
  3. Returns **1..N features** (centerline `self` plus transformed `left`/`right` sides), each with:
20
20
  - **`category`** — `Radinfrastrukturkategorie` (primary focus; see [`schemas/bicycle-infrastructure-category`](../../schemas/bicycle-infrastructure-category/))
21
21
  - plus surface, smoothness, oneway, separation / buffer / marking, traffic_mode, traffic_sign, surface_color, width
22
- - `_lineReversed` and `offset` (riding direction of the published line, follows tilda-geo-private#34, not merged yet)
22
+ - `_lineReversed` and `offset` (riding direction of the published line of a lane on the road)
23
23
  - `todos` (what is missing or wrong in the tagging) and `todoTagFixes`
24
24
 
25
25
  Disallowed sanitizer values become `null`, matching TILDA’s GeoJSON export.
package/dist/index.d.ts CHANGED
@@ -45,8 +45,8 @@ interface BikelaneResult {
45
45
  lifecycle?: string | null;
46
46
  oneway?: string;
47
47
  /**
48
- * Whether the published line runs against the OSM way (`_line_reversed` in LUA).
49
- * follows tilda-geo-private#34 (not merged yet).
48
+ * Whether the published line of a lane or track tagged on the road runs against the OSM way
49
+ * (`_line_reversed` in LUA, tilda-geo `6ec40d600`). Lines of the way itself keep its direction.
50
50
  */
51
51
  _lineReversed?: boolean;
52
52
  /** Sideways offset in meters of left|right lanes, signed relative to the published line. */
@@ -163,8 +163,11 @@ declare function parseWidth(width: string | number | undefined | null): number |
163
163
  /**
164
164
  * `separation` values that make a lane "protected" (`cyclewayOnHighwayProtected`), as in
165
165
  * `bikelane_categories.lua`. Other allowed values (`kerb`, `greenery`, ...) do not.
166
+ * Ordered by use in Berlin (extract of 2026-11-09, `highway=cycleway`, separation towards the road):
167
+ * bollard 102, flex_post 35, vertical_panel 28, bump 25, fence 9, guard_rail 6; the others 0.
168
+ * Editors offer them in this order, `bollard` as the default.
166
169
  */
167
- declare const PROTECTIVE_SEPARATION: readonly ["bollard", "flex_post", "vertical_panel", "studs", "bump", "planter", "fence", "jersey_barrier", "guard_rail"];
170
+ declare const PROTECTIVE_SEPARATION: readonly ["bollard", "flex_post", "vertical_panel", "bump", "fence", "guard_rail", "planter", "studs", "jersey_barrier"];
168
171
  declare const SEPARATION_ALLOWED: readonly ["no", "bollard", "flex_post", "vertical_panel", "studs", "bump", "planter", "kerb", "fence", "jersey_barrier", "guard_rail", "structure", "ditch", "greenery", "hedge", "tree_row", "cone", "kerb;parking_lane", "kerb;bollard", "yes"];
169
172
  declare const MARKING_ALLOWED: readonly ["solid_line", "dashed_line", "double_solid_line", "barred_area", "pictogram", "surface"];
170
173
  declare const TRAFFIC_MODE_ALLOWED: readonly ["no", "motor_vehicle", "parking", "psv", "bicycle", "foot"];
@@ -181,18 +184,22 @@ declare const DIRECTIONAL_PARKING_INFERENCE_CATEGORIES: Set<string>;
181
184
  declare const PARKING_ALLOWED: readonly ["no", "yes", "lane", "street_side", "on_kerb", "half_on_kerb", "shoulder", "separate"];
182
185
 
183
186
  /**
184
- * Port of topics/roads_bikelanes/bikelanes/derive_oneway.lua as in the tilda-geo branch
185
- * `claude/tilda-oneway-processing-81b448` (follows tilda-geo-private#34, not merged yet).
186
- * It replaces the `develop` version, which has no `-1`, no line direction and no side defaults.
187
+ * Port of topics/roads_bikelanes/bikelanes/derive_oneway.lua and
188
+ * topics/roads_bikelanes/bikelanes/helper/side_line_reversed.lua (tilda-geo `6ec40d600`, `bac701775`).
187
189
  *
188
190
  * OSM `oneway` values are relative to the drawing direction of the way:
189
- * `yes` (or `1`) flows with the way, `-1` against it, `no` in both directions.
191
+ * `yes` flows with the way, `-1` against it, `no` in both directions.
190
192
  * https://wiki.openstreetmap.org/wiki/Key:oneway
193
+ * The tags are expected after `normalizeOnewayTags` (`1`/`true` are `yes`, roundabouts `oneway=yes`).
191
194
  */
192
195
 
193
196
  /**
194
- * Whether bicycles ride against the drawing direction of the road on the `left`|`right` lane of
195
- * `road` when the lane has no `cycleway:<side>:oneway` (the rules above, right-hand traffic).
197
+ * Whether bicycles ride against the drawing direction of `road` on its `left`|`right` lane when the
198
+ * lane has no `cycleway:<side>:oneway`, the wiki default (right-hand traffic):
199
+ * https://wiki.openstreetmap.org/wiki/Key:cycleway:right:oneway#Implicit_values
200
+ * - One-way road: both sides follow the road, so against the way only on `oneway=-1`.
201
+ * `oneway:bicycle=no` changes nothing: a contraflow lane needs `cycleway:left:oneway=-1`.
202
+ * - Other roads: the right side runs with the way, the left side against it.
196
203
  * Exported so editors suggest the same direction the processing derives.
197
204
  */
198
205
  declare function defaultSideRunsAgainstWay(road: OsmTags, side: 'left' | 'right'): boolean;
@@ -243,6 +250,12 @@ interface TagReason {
243
250
  reason: string;
244
251
  reasonCode: TagReasonCode;
245
252
  reasonParams?: Record<string, string>;
253
+ /**
254
+ * Values the mapper can pick instead, when more than one reaches the target (the kind of
255
+ * separation of a protected lane). The planned value (`value` / `to`) is the default and the
256
+ * first entry; the others follow by how often they are mapped.
257
+ */
258
+ choices?: readonly string[];
246
259
  }
247
260
  interface TagPlanEntry extends TagReason {
248
261
  key: string;
@@ -459,7 +472,7 @@ declare const BIKELANE_TRANSFORMATIONS: CenterLineTransformation[];
459
472
  * tags in-place BEFORE `getTransformedObjects`, exactly as `roads_bikelanes.lua` does.
460
473
  */
461
474
 
462
- /** Apply all pre-transforms in the same order as roads_bikelanes.lua. */
475
+ /** Apply all pre-transforms in the same order as roads_bikelanes_ways.lua. */
463
476
  declare function prepareTags(tags: OsmTags): void;
464
477
 
465
478
  /** Port of topics/helper/highway_classes.lua */
package/dist/index.js CHANGED
@@ -166,12 +166,12 @@ var PROTECTIVE_SEPARATION = [
166
166
  "bollard",
167
167
  "flex_post",
168
168
  "vertical_panel",
169
- "studs",
170
169
  "bump",
171
- "planter",
172
170
  "fence",
173
- "jersey_barrier",
174
- "guard_rail"
171
+ "guard_rail",
172
+ "planter",
173
+ "studs",
174
+ "jersey_barrier"
175
175
  ];
176
176
  var SEPARATION_ALLOWED = [
177
177
  "no",
@@ -844,7 +844,10 @@ var CATEGORY_SPECS = [
844
844
  {
845
845
  id: "sharedMotorVehicleLane",
846
846
  infrastructureExists: true,
847
- implicitOneWay: false,
847
+ // `implicit_yes`: each row is one side of the road (`cycleway=shared_lane` without a side also gives
848
+ // a left and a right row), so it is the motor vehicle lane of that side and runs in one direction
849
+ // (tilda-geo `0927094ca`).
850
+ implicitOneWay: true,
848
851
  implicitOneWayConfidence: "high",
849
852
  copySurfaceSmoothnessFromParent: true,
850
853
  bicycleSurface: "strip",
@@ -947,11 +950,12 @@ var CATEGORY_MACROS = {
947
950
  unsigned_cycleway: unsignedCycleway
948
951
  };
949
952
  function footAndCyclewaySegregatedSeparation(tags) {
950
- const separationRight = tags.separation_right;
951
- let separationCondition = true;
952
- if (separationRight != null) separationCondition = separationRight === "no";
953
- const trafficModeCondition = tags.traffic_mode_right === "foot";
954
- if (tags.highway === "cycleway" && trafficModeCondition && separationCondition) return true;
953
+ if (tags.highway !== "cycleway") return void 0;
954
+ const footNextToIt = (side) => {
955
+ const separation2 = tags[`separation_${side}`];
956
+ return tags[`traffic_mode_${side}`] === "foot" && (separation2 == null || separation2 === "no");
957
+ };
958
+ if (footNextToIt("right") || footNextToIt("left")) return true;
955
959
  return void 0;
956
960
  }
957
961
  function specByCategoryId(id) {
@@ -1264,7 +1268,7 @@ var missingOneway = {
1264
1268
  }
1265
1269
  };
1266
1270
  var AGAINST_SIDE_TRAFFIC = {
1267
- left: /* @__PURE__ */ new Set(["yes", "1"]),
1271
+ left: /* @__PURE__ */ new Set(["yes"]),
1268
1272
  right: /* @__PURE__ */ new Set(["-1"])
1269
1273
  };
1270
1274
  function againstSideTrafficKeys(tags) {
@@ -1293,7 +1297,9 @@ var unexpectedOnewayDirection = {
1293
1297
  condition: (tags) => {
1294
1298
  const parent = tags._parent;
1295
1299
  if (parent == null) return false;
1300
+ if (tags._prefix !== "cycleway") return false;
1296
1301
  if (parent.oneway === "yes" || parent.oneway === "-1") return false;
1302
+ if (tags["check_date:oneway"] != null || tags.check_date != null) return false;
1297
1303
  const keys = againstSideTrafficKeys(tags);
1298
1304
  for (const side of ["left", "right"]) {
1299
1305
  const key = keys[side];
@@ -1707,56 +1713,43 @@ function bikelaneSurfaceSource(surfaceTags, surfaceSource) {
1707
1713
  }
1708
1714
 
1709
1715
  // 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
+ var isOneway = (value) => value === "yes" || value === "-1";
1717
+ var ONEWAY_JUNCTIONS = /* @__PURE__ */ new Set(["roundabout", "circular"]);
1718
+ function isOnewayRoad(road) {
1719
+ const oneway = road.oneway;
1720
+ if (oneway === "yes" || oneway === "1" || oneway === "true" || oneway === "-1") return true;
1721
+ return oneway === void 0 && road.junction !== void 0 && ONEWAY_JUNCTIONS.has(road.junction);
1716
1722
  }
1717
1723
  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
- }
1724
+ if (isOnewayRoad(road)) return road.oneway === "-1";
1725
1725
  return side === "left";
1726
1726
  }
1727
1727
  function onewayValue(tags, category) {
1728
1728
  const oneway = tags.oneway;
1729
1729
  const onewayBicycle = tags["oneway:bicycle"];
1730
- const isSide = tags._side === "left" || tags._side === "right";
1731
- if (isWithWay(onewayBicycle) || isAgainstWay(onewayBicycle)) {
1730
+ if (isOneway(onewayBicycle)) {
1732
1731
  return "yes";
1733
1732
  } else if (onewayBicycle === "no") {
1734
- return isWithWay(oneway) || isAgainstWay(oneway) ? "car_not_bike" : "no";
1733
+ return isOneway(oneway) ? "car_not_bike" : "no";
1735
1734
  }
1736
- if (isWithWay(oneway) || isAgainstWay(oneway)) return "yes";
1735
+ if (isOneway(oneway)) return "yes";
1737
1736
  if (oneway === "no") return "no";
1738
- if (isSide) return "implicit_yes";
1739
1737
  if (tags.highway === "service" || tags.highway === "track") return "assumed_no";
1740
1738
  if (category.implicitOneWay) return "implicit_yes";
1741
1739
  return "assumed_no";
1742
1740
  }
1741
+ function sideLineReversed(tags) {
1742
+ const side = tags._side;
1743
+ if (side !== "left" && side !== "right") return false;
1744
+ const direction = tags["oneway:bicycle"] ?? tags.oneway;
1745
+ if (direction === "-1") return true;
1746
+ if (direction === "yes") return false;
1747
+ const parent = tags._parent ?? {};
1748
+ if (direction === void 0 && isOnewayRoad(parent)) return parent.oneway === "-1";
1749
+ return side === "left";
1750
+ }
1743
1751
  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) };
1752
+ return { oneway: onewayValue(tags, category), lineReversed: sideLineReversed(tags) };
1760
1753
  }
1761
1754
 
1762
1755
  // src/derive/derive-surface.ts
@@ -1981,8 +1974,27 @@ function transformCyclewayBothPostfix(tags) {
1981
1974
  tags.cycleway = void 0;
1982
1975
  }
1983
1976
  }
1977
+ var ONEWAY_YES_ALIASES = /* @__PURE__ */ new Set(["1", "true"]);
1978
+ var ONEWAY_JUNCTIONS2 = /* @__PURE__ */ new Set(["roundabout", "circular"]);
1979
+ var ONEWAY_KEYS = (() => {
1980
+ const keys = ["oneway", "oneway:bicycle"];
1981
+ for (const prefix of ["cycleway", "sidewalk"]) {
1982
+ for (const infix of ["", ":left", ":right", ":both"]) keys.push(`${prefix}${infix}:oneway`);
1983
+ }
1984
+ return [...keys, ...keys.map((key) => `construction:${key}`)];
1985
+ })();
1986
+ function normalizeOnewayTags(tags) {
1987
+ for (const key of ONEWAY_KEYS) {
1988
+ const value = tags[key];
1989
+ if (value !== void 0 && ONEWAY_YES_ALIASES.has(value)) tags[key] = "yes";
1990
+ }
1991
+ if (tags.oneway === void 0 && tags.junction !== void 0 && ONEWAY_JUNCTIONS2.has(tags.junction)) {
1992
+ tags.oneway = "yes";
1993
+ }
1994
+ }
1984
1995
  function prepareTags(tags) {
1985
1996
  transformLifecycleTags(tags);
1997
+ normalizeOnewayTags(tags);
1986
1998
  transformCyclewayOppositeSchema(tags);
1987
1999
  transformConstructionPrefix(tags);
1988
2000
  transformCyclewayBothPostfix(tags);
@@ -2465,6 +2477,7 @@ var MACRO_PLAN_ALTERNATIVES = {
2465
2477
  key: "separation:left",
2466
2478
  accepts: (v) => v != null && PROTECTIVE_SEPARATION.includes(v),
2467
2479
  value: PROTECTIVE_SEPARATION[0],
2480
+ choices: PROTECTIVE_SEPARATION,
2468
2481
  reason: "Protected cycle lane: physical separation towards the road",
2469
2482
  reasonCode: "protected_lane_separation"
2470
2483
  }
@@ -2641,15 +2654,21 @@ function candidateFor(alternative, base, fixedKeys, side) {
2641
2654
  value: atom.value,
2642
2655
  reason: atom.reason,
2643
2656
  reasonCode: atom.reasonCode,
2644
- reasonParams: atom.reasonParams
2657
+ reasonParams: atom.reasonParams,
2658
+ choices: atom.choices
2645
2659
  });
2646
2660
  cost += editCost(atom.key, base[atom.key], atom.value, side);
2647
2661
  }
2648
2662
  return { edits, cost };
2649
2663
  }
2650
2664
  function reasonOf(why) {
2651
- const { reason, reasonCode, reasonParams } = why;
2652
- return reasonParams ? { reason, reasonCode, reasonParams } : { reason, reasonCode };
2665
+ const { reason, reasonCode, reasonParams, choices } = why;
2666
+ return {
2667
+ reason,
2668
+ reasonCode,
2669
+ ...reasonParams ? { reasonParams } : {},
2670
+ ...choices ? { choices } : {}
2671
+ };
2653
2672
  }
2654
2673
  function applyPlanToWayTags(wayTags, add, change, remove = []) {
2655
2674
  const next = { ...wayTags };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tilda-geo/bicycle-infrastructure",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "TypeScript port of TILDA's LUA bicycle-infrastructure processing (category + surface/protection/oneway derivations). Runs on plain OSM tag objects (e.g. live Overpass data).",
5
5
  "keywords": [
6
6
  "bicycle",