@truelies/osm-dybuf 0.4.0 → 0.4.2
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 +12 -5
- package/grid_index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,10 +25,10 @@ Current frontend-facing schema notes:
|
|
|
25
25
|
- `place_label` remains in schema IDs for compatibility, but current exports no longer emit place-name labels to the frontend.
|
|
26
26
|
- `label` main feature ID is now reserved for future overlay labels; `sub_id` is intended to carry `label kind` (`worship`, `station`, `custom`, etc.).
|
|
27
27
|
- Current exporter-oriented subtypes are `label_worship` and `label_station`, both derived from existing `building` tasks. Consumers should group all future `label_*` subtypes by `unpackFeatureId(featureId).mainKey === "label"` if they want a single overlay layer.
|
|
28
|
-
- Breaking change in `0.4.
|
|
28
|
+
- Breaking change in `0.4.x`: `GridFeature.featureId` is numeric. Consumers should map it with `ID_TO_FEATURE_KIND[String(featureId)]` or `unpackFeatureId(featureId)` when string/debug output is needed.
|
|
29
29
|
- `road_express` covers motorway corridors plus `trunk` ways tagged with `motorroad=yes` (for example many Taiwan expressway mainlines).
|
|
30
30
|
- `water_wetland` separates marsh / bog / fen / wetland polygons from deeper open water.
|
|
31
|
-
-
|
|
31
|
+
- Geometry payload exports currently stop at `lv13`, but Gridex/index helpers remain valid through `lv16` for higher-detail indexing metadata.
|
|
32
32
|
|
|
33
33
|
## Usage
|
|
34
34
|
|
|
@@ -42,6 +42,7 @@ import { parseOsmDybuf } from "@truelies/osm-dybuf";
|
|
|
42
42
|
import {
|
|
43
43
|
FEATURE_KIND_IDS,
|
|
44
44
|
ID_TO_FEATURE_KIND,
|
|
45
|
+
MAIN_FEATURE_IDS,
|
|
45
46
|
unpackFeatureId,
|
|
46
47
|
REGION_NUMERIC_CODES,
|
|
47
48
|
} from "@truelies/osm-dybuf/schema_ids";
|
|
@@ -55,6 +56,7 @@ if (parsed.format === "flat_v1") {
|
|
|
55
56
|
console.log(parsed.features[0].featureId); // numeric feature id
|
|
56
57
|
console.log(ID_TO_FEATURE_KIND[String(parsed.features[0].featureId)]);
|
|
57
58
|
console.log(unpackFeatureId(parsed.features[0].featureId));
|
|
59
|
+
console.log((parsed.features[0].featureId & 0x3f) === MAIN_FEATURE_IDS.label);
|
|
58
60
|
} else if (parsed.format === "v2_indexed") {
|
|
59
61
|
console.log(parsed.entries.length);
|
|
60
62
|
} else {
|
|
@@ -76,6 +78,11 @@ if (parsed.format === "flat_v1") {
|
|
|
76
78
|
--level 8 --londex 213 --latdex 161 --limit 5
|
|
77
79
|
```
|
|
78
80
|
|
|
81
|
+
Feature ID usage notes:
|
|
82
|
+
- Use `FEATURE_KIND_IDS.*` for exact feature comparison, for example `featureId === FEATURE_KIND_IDS.waterbody`.
|
|
83
|
+
- Use `MAIN_FEATURE_IDS.*` with `featureId & 0x3f` when you want to group all subtypes under the same main feature, for example `(featureId & 0x3f) === MAIN_FEATURE_IDS.label`.
|
|
84
|
+
- Use `unpackFeatureId(featureId)` for debug output or subtype-aware logic where readability matters more than raw hot-path comparisons.
|
|
85
|
+
|
|
79
86
|
### Grid helpers (grid_index)
|
|
80
87
|
|
|
81
88
|
`grid_index.mjs` exposes Gridex helpers (integers, pole triangles) aligned with the exporter:
|
|
@@ -94,7 +101,7 @@ const parent = new GridUnit(9).toUpperLevelGridex(children[0]); // back to level
|
|
|
94
101
|
|
|
95
102
|
- `toLowerLevelGridexes(gridex)`:
|
|
96
103
|
- returns 4 child cells at `level + 1`
|
|
97
|
-
- throws when current unit is already max level (`
|
|
104
|
+
- throws when current unit is already max level (`16`)
|
|
98
105
|
- `toUpperLevelGridex(gridex)`:
|
|
99
106
|
- returns the parent cell at `level - 1`
|
|
100
107
|
- throws when current unit is level `0`
|
|
@@ -110,7 +117,7 @@ npm test # runs unit tests (node:test)
|
|
|
110
117
|
Unit test example (`tests/grid_index.test.mjs`) covers:
|
|
111
118
|
- `gridexesAt` near axis (no zero index cell)
|
|
112
119
|
- `toLowerLevelGridexes` and `toUpperLevelGridex` roundtrip
|
|
113
|
-
- level boundary errors (`lv0` has no upper level, `
|
|
120
|
+
- level boundary errors (`lv0` has no upper level, `lv16` has no lower level)
|
|
114
121
|
|
|
115
122
|
- `npm pack`: build a tarball so other repos can install via `npm install ./path/to/osm-dybuf-*.tgz`
|
|
116
123
|
- `npm link`: link the package locally (`npm link` here, then `npm link @truelies/osm-dybuf` in the consumer repo)
|
|
@@ -132,4 +139,4 @@ Unit test example (`tests/grid_index.test.mjs`) covers:
|
|
|
132
139
|
- `region_numeric_codes.json`: latest region ID table (generated via `scripts/dump_region_codes.py`)
|
|
133
140
|
- `inspect_dybuf.mjs`: CLI tool that uses the package locally
|
|
134
141
|
|
|
135
|
-
When schema IDs or DyBuf layouts change in the exporter, remember to bump the version here and re-publish/install so frontends and tools stay in sync. Version `0.4.
|
|
142
|
+
When schema IDs or DyBuf layouts change in the exporter, remember to bump the version here and re-publish/install so frontends and tools stay in sync. Version `0.4.2` aligns the package with the current `lv0~13` export range, the current frontend feature set (`water_wetland`, `building`, derived `label_*`, no exported `place_label`), and the numeric `featureId` parser contract.
|
package/grid_index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ export const GRID_LV0_UNIT = 30 * INT_COORD_SCALE;
|
|
|
6
6
|
const GRID_LV0_UNIT_FINE = GRID_LV0_UNIT * GRID_FINE_RES;
|
|
7
7
|
const GRID_LV0_LONDEX = 6;
|
|
8
8
|
const GRID_LV0_LATDEX = 3;
|
|
9
|
-
const MAX_LEVEL =
|
|
9
|
+
const MAX_LEVEL = 16;
|
|
10
10
|
const MAX_LONGITUDE_FINE = 180 * INT_COORD_SCALE * GRID_FINE_RES;
|
|
11
11
|
const MIN_LONGITUDE_FINE = -MAX_LONGITUDE_FINE;
|
|
12
12
|
const MAX_LATITUDE_FINE = 90 * INT_COORD_SCALE * GRID_FINE_RES;
|