@truelies/osm-dybuf 0.1.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/osm_dybuf.d.mts +43 -0
- package/osm_dybuf.mjs +237 -0
- package/package.json +38 -0
- package/region_numeric_codes.json +254 -0
- package/schema_ids.d.mts +11 -0
- package/schema_ids.mjs +73 -0
package/osm_dybuf.d.mts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface GridCellRef {
|
|
2
|
+
level: number;
|
|
3
|
+
londex: number;
|
|
4
|
+
latdex: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface GeometryCoordinate {
|
|
8
|
+
lon: number;
|
|
9
|
+
lat: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface GeometrySegment {
|
|
13
|
+
role: string;
|
|
14
|
+
coordinates: GeometryCoordinate[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface GridElement {
|
|
18
|
+
entityType: string;
|
|
19
|
+
entityId: number;
|
|
20
|
+
entityRef: string;
|
|
21
|
+
geometryType: string;
|
|
22
|
+
tags: Record<string, string>;
|
|
23
|
+
segments: GeometrySegment[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface GridFeature {
|
|
27
|
+
featureId: string;
|
|
28
|
+
elements: GridElement[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface RegionChunk {
|
|
32
|
+
id: number;
|
|
33
|
+
name: string;
|
|
34
|
+
features: GridFeature[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface OsmDybuf {
|
|
38
|
+
version: number;
|
|
39
|
+
regions: RegionChunk[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export declare function parseOsmDybuf(data: ArrayBuffer | ArrayBufferView, cell: GridCellRef): OsmDybuf;
|
|
43
|
+
export declare function decodeRegionPayload(payload: ArrayBuffer, cell: GridCellRef): GridFeature[];
|
package/osm_dybuf.mjs
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DyBuf,
|
|
3
|
+
TYPDEX_TYP_BOOL,
|
|
4
|
+
TYPDEX_TYP_INT,
|
|
5
|
+
TYPDEX_TYP_UINT,
|
|
6
|
+
TYPDEX_TYP_STRING,
|
|
7
|
+
TYPDEX_TYP_BYTES,
|
|
8
|
+
TYPDEX_TYP_ARRAY,
|
|
9
|
+
TYPDEX_TYP_MAP,
|
|
10
|
+
} from "dybuf";
|
|
11
|
+
import {
|
|
12
|
+
ID_TO_ENTITY_TYPE,
|
|
13
|
+
ID_TO_FEATURE_KIND,
|
|
14
|
+
ID_TO_GEOMETRY_KIND,
|
|
15
|
+
ID_TO_SEGMENT_ROLE,
|
|
16
|
+
SEGMENT_ROLE_ID_UNSET,
|
|
17
|
+
SEGMENT_ROLE_ID_UNSUPPORTED,
|
|
18
|
+
REGION_NUMERIC_CODES,
|
|
19
|
+
} from "./schema_ids.mjs";
|
|
20
|
+
|
|
21
|
+
const GRID_FINE_RES = 64;
|
|
22
|
+
const INT_COORD_SCALE = 1_000_000_000;
|
|
23
|
+
const GRID_LV0_UNIT = 30 * INT_COORD_SCALE;
|
|
24
|
+
|
|
25
|
+
const GRID_VALUE_FIELD = {
|
|
26
|
+
ENTITY_TYPE: 0,
|
|
27
|
+
ENTITY_ID: 1,
|
|
28
|
+
GEOMETRY_TYPE: 2,
|
|
29
|
+
GEOMETRY_DATA: 3,
|
|
30
|
+
TAGS: 4,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const REGION_ID_TO_NAME = Object.freeze(
|
|
34
|
+
Object.fromEntries(
|
|
35
|
+
Object.entries(REGION_NUMERIC_CODES).map(([name, id]) => [String(id), name])
|
|
36
|
+
)
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Normalize Node.js Buffer/View inputs into an ArrayBuffer slice.
|
|
41
|
+
* @param {ArrayBuffer | ArrayBufferView} data
|
|
42
|
+
* @returns {ArrayBuffer}
|
|
43
|
+
*/
|
|
44
|
+
function toArrayBuffer(data) {
|
|
45
|
+
if (data instanceof ArrayBuffer) {
|
|
46
|
+
return data;
|
|
47
|
+
}
|
|
48
|
+
if (ArrayBuffer.isView(data)) {
|
|
49
|
+
const { buffer, byteOffset, byteLength } = data;
|
|
50
|
+
return buffer.slice(byteOffset, byteOffset + byteLength);
|
|
51
|
+
}
|
|
52
|
+
throw new TypeError("Expected ArrayBuffer or typed array input");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function unitFineForLevel(level) {
|
|
56
|
+
return (GRID_LV0_UNIT * GRID_FINE_RES) / (1 << level);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function gridBounds(level, londex, latdex) {
|
|
60
|
+
const unitFine = unitFineForLevel(level);
|
|
61
|
+
const minLonFine = (londex - (londex > 0 ? 1 : 0)) * unitFine;
|
|
62
|
+
const minLatFine = (latdex - (latdex > 0 ? 1 : 0)) * unitFine;
|
|
63
|
+
const maxLonFine = (londex + (londex > 0 ? 0 : 1)) * unitFine;
|
|
64
|
+
const maxLatFine = (latdex + (latdex > 0 ? 0 : 1)) * unitFine;
|
|
65
|
+
return {
|
|
66
|
+
minLon: minLonFine / GRID_FINE_RES,
|
|
67
|
+
minLat: minLatFine / GRID_FINE_RES,
|
|
68
|
+
maxLon: maxLonFine / GRID_FINE_RES,
|
|
69
|
+
maxLat: maxLatFine / GRID_FINE_RES,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function readVarUint(buf) {
|
|
74
|
+
return Number(buf.getVarULong());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function readVarInt(buf) {
|
|
78
|
+
return Number(buf.getVarLong());
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const textDecoder = new TextDecoder("utf-8");
|
|
82
|
+
|
|
83
|
+
function readVarString(buf) {
|
|
84
|
+
const raw = buf.getVarString();
|
|
85
|
+
if (typeof raw === "string") {
|
|
86
|
+
return raw;
|
|
87
|
+
}
|
|
88
|
+
if (raw == null) {
|
|
89
|
+
return "";
|
|
90
|
+
}
|
|
91
|
+
return textDecoder.decode(raw);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function readVarBytes(buf) {
|
|
95
|
+
return buf.getBytesWithVarLength();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function decodeGeometrySegments(bytes, cell) {
|
|
99
|
+
const buf = new DyBuf(bytes, false);
|
|
100
|
+
const version = buf.getByte();
|
|
101
|
+
if (version !== 1) {
|
|
102
|
+
throw new Error(`Unsupported geometry blob version ${version}`);
|
|
103
|
+
}
|
|
104
|
+
const bounds = gridBounds(cell.level, cell.londex, cell.latdex);
|
|
105
|
+
const segments = [];
|
|
106
|
+
const segmentCount = readVarUint(buf);
|
|
107
|
+
for (let i = 0; i < segmentCount; i += 1) {
|
|
108
|
+
const roleId = buf.getByte();
|
|
109
|
+
let role = "";
|
|
110
|
+
if (roleId === SEGMENT_ROLE_ID_UNSUPPORTED) {
|
|
111
|
+
role = "<unsupported>";
|
|
112
|
+
} else if (roleId !== SEGMENT_ROLE_ID_UNSET) {
|
|
113
|
+
role = ID_TO_SEGMENT_ROLE[String(roleId)] ?? "";
|
|
114
|
+
}
|
|
115
|
+
const pointCount = readVarUint(buf);
|
|
116
|
+
const points = [];
|
|
117
|
+
let prevX;
|
|
118
|
+
let prevY;
|
|
119
|
+
for (let j = 0; j < pointCount; j += 1) {
|
|
120
|
+
const dx = readVarInt(buf);
|
|
121
|
+
const dy = readVarInt(buf);
|
|
122
|
+
const x = prevX === undefined ? bounds.minLon + dx : prevX + dx;
|
|
123
|
+
const y = prevY === undefined ? bounds.minLat + dy : prevY + dy;
|
|
124
|
+
points.push({ lon: x, lat: y });
|
|
125
|
+
prevX = x;
|
|
126
|
+
prevY = y;
|
|
127
|
+
}
|
|
128
|
+
segments.push({ role, coordinates: points });
|
|
129
|
+
}
|
|
130
|
+
return segments;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function decodeGridPayload(bytes, cell) {
|
|
134
|
+
const buf = new DyBuf(bytes, false);
|
|
135
|
+
const version = buf.getByte();
|
|
136
|
+
if (version !== 1) {
|
|
137
|
+
throw new Error(`Unsupported grid payload version ${version}`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let entityTypeId;
|
|
141
|
+
let entityId;
|
|
142
|
+
let geometryType;
|
|
143
|
+
let geometryBlob;
|
|
144
|
+
const tags = {};
|
|
145
|
+
|
|
146
|
+
while (buf.position() < buf.limit()) {
|
|
147
|
+
const { type, index } = buf.getTypdex();
|
|
148
|
+
if (index === GRID_VALUE_FIELD.ENTITY_TYPE && type === TYPDEX_TYP_UINT) {
|
|
149
|
+
entityTypeId = readVarUint(buf);
|
|
150
|
+
} else if (index === GRID_VALUE_FIELD.ENTITY_ID && type === TYPDEX_TYP_UINT) {
|
|
151
|
+
entityId = readVarUint(buf);
|
|
152
|
+
} else if (index === GRID_VALUE_FIELD.GEOMETRY_TYPE && type === TYPDEX_TYP_UINT) {
|
|
153
|
+
const geometryNumeric = readVarUint(buf);
|
|
154
|
+
geometryType =
|
|
155
|
+
ID_TO_GEOMETRY_KIND[String(geometryNumeric)] ?? `geometry:${geometryNumeric}`;
|
|
156
|
+
} else if (index === GRID_VALUE_FIELD.GEOMETRY_DATA && type === TYPDEX_TYP_BYTES) {
|
|
157
|
+
geometryBlob = readVarBytes(buf);
|
|
158
|
+
} else if (index === GRID_VALUE_FIELD.TAGS && type === TYPDEX_TYP_MAP) {
|
|
159
|
+
const count = readVarUint(buf);
|
|
160
|
+
for (let i = 0; i < count; i += 1) {
|
|
161
|
+
const key = readVarString(buf);
|
|
162
|
+
const value = readVarString(buf);
|
|
163
|
+
tags[key] = value;
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
throw new Error(`Unsupported typdex field: index=${index} type=${type}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (
|
|
171
|
+
entityTypeId === undefined ||
|
|
172
|
+
entityId === undefined ||
|
|
173
|
+
!geometryType ||
|
|
174
|
+
!geometryBlob
|
|
175
|
+
) {
|
|
176
|
+
throw new Error("Grid payload missing required fields");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const entityType = ID_TO_ENTITY_TYPE[String(entityTypeId)];
|
|
180
|
+
if (!entityType) {
|
|
181
|
+
throw new Error(`Unknown entity type id ${entityTypeId}`);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const segments = decodeGeometrySegments(geometryBlob, cell);
|
|
185
|
+
return {
|
|
186
|
+
entityType,
|
|
187
|
+
entityId,
|
|
188
|
+
entityRef: `${entityType}:${entityId}`,
|
|
189
|
+
geometryType,
|
|
190
|
+
tags,
|
|
191
|
+
segments,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function decodeRegionPayload(payloadBytes, cell) {
|
|
196
|
+
const buf = new DyBuf(payloadBytes, false);
|
|
197
|
+
const featureCount = readVarUint(buf);
|
|
198
|
+
const features = [];
|
|
199
|
+
for (let i = 0; i < featureCount; i += 1) {
|
|
200
|
+
const featureNumericId = readVarUint(buf);
|
|
201
|
+
const featureId =
|
|
202
|
+
ID_TO_FEATURE_KIND[featureNumericId] ?? `feature:${featureNumericId}`;
|
|
203
|
+
const entryCount = readVarUint(buf);
|
|
204
|
+
const elements = [];
|
|
205
|
+
for (let j = 0; j < entryCount; j += 1) {
|
|
206
|
+
const entryBytes = readVarBytes(buf);
|
|
207
|
+
elements.push(decodeGridPayload(entryBytes, cell));
|
|
208
|
+
}
|
|
209
|
+
features.push({ featureId, elements });
|
|
210
|
+
}
|
|
211
|
+
return features;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Parse a single cell's osm.dybuf payload.
|
|
216
|
+
* @param {ArrayBuffer | ArrayBufferView} data
|
|
217
|
+
* @param {{level: number, londex: number, latdex: number}} cell
|
|
218
|
+
*/
|
|
219
|
+
export function parseOsmDybuf(data, cell) {
|
|
220
|
+
if (!cell || typeof cell.level !== "number" || typeof cell.londex !== "number" || typeof cell.latdex !== "number") {
|
|
221
|
+
throw new TypeError("Cell metadata (level, londex, latdex) is required");
|
|
222
|
+
}
|
|
223
|
+
const buffer = toArrayBuffer(data);
|
|
224
|
+
const buf = new DyBuf(buffer, false);
|
|
225
|
+
const version = buf.getByte();
|
|
226
|
+
const regions = [];
|
|
227
|
+
while (buf.position() < buf.limit()) {
|
|
228
|
+
const regionId = readVarUint(buf);
|
|
229
|
+
const regionName = REGION_ID_TO_NAME[String(regionId)] ?? `region:${regionId}`;
|
|
230
|
+
const regionPayload = readVarBytes(buf);
|
|
231
|
+
const features = decodeRegionPayload(regionPayload, cell);
|
|
232
|
+
regions.push({ id: regionId, name: regionName, features });
|
|
233
|
+
}
|
|
234
|
+
return { version, regions };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export { decodeRegionPayload, decodeGridPayload };
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@truelies/osm-dybuf",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Gridex OSM DyBuf parser and schema utilities",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./osm_dybuf.mjs",
|
|
7
|
+
"module": "./osm_dybuf.mjs",
|
|
8
|
+
"types": "./osm_dybuf.d.mts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./osm_dybuf.mjs",
|
|
12
|
+
"types": "./osm_dybuf.d.mts"
|
|
13
|
+
},
|
|
14
|
+
"./schema_ids": {
|
|
15
|
+
"import": "./schema_ids.mjs",
|
|
16
|
+
"types": "./schema_ids.d.mts"
|
|
17
|
+
},
|
|
18
|
+
"./region_numeric_codes.json": "./region_numeric_codes.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"osm_dybuf.mjs",
|
|
22
|
+
"osm_dybuf.d.mts",
|
|
23
|
+
"schema_ids.mjs",
|
|
24
|
+
"schema_ids.d.mts",
|
|
25
|
+
"region_numeric_codes.json"
|
|
26
|
+
],
|
|
27
|
+
"keywords": [
|
|
28
|
+
"dybuf",
|
|
29
|
+
"osm",
|
|
30
|
+
"gridex",
|
|
31
|
+
"parser"
|
|
32
|
+
],
|
|
33
|
+
"author": "TrueLies",
|
|
34
|
+
"license": "UNLICENSED",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"dybuf": "^0.4.2"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ad": 300,
|
|
3
|
+
"ae": 400,
|
|
4
|
+
"af": 500,
|
|
5
|
+
"ag": 600,
|
|
6
|
+
"ai": 800,
|
|
7
|
+
"al": 1100,
|
|
8
|
+
"am": 1200,
|
|
9
|
+
"ao": 1400,
|
|
10
|
+
"aq": 1600,
|
|
11
|
+
"ar": 1700,
|
|
12
|
+
"as": 1800,
|
|
13
|
+
"at": 1900,
|
|
14
|
+
"au": 2000,
|
|
15
|
+
"aw": 2200,
|
|
16
|
+
"ax": 2300,
|
|
17
|
+
"az": 2500,
|
|
18
|
+
"ba": 2600,
|
|
19
|
+
"bb": 2700,
|
|
20
|
+
"bd": 2900,
|
|
21
|
+
"be": 3000,
|
|
22
|
+
"bf": 3100,
|
|
23
|
+
"bg": 3200,
|
|
24
|
+
"bh": 3300,
|
|
25
|
+
"bi": 3400,
|
|
26
|
+
"bj": 3500,
|
|
27
|
+
"bl": 3700,
|
|
28
|
+
"bm": 3800,
|
|
29
|
+
"bn": 3900,
|
|
30
|
+
"bo": 4000,
|
|
31
|
+
"bq": 4200,
|
|
32
|
+
"br": 4300,
|
|
33
|
+
"bs": 4400,
|
|
34
|
+
"bt": 4500,
|
|
35
|
+
"bv": 4700,
|
|
36
|
+
"bw": 4800,
|
|
37
|
+
"by": 5000,
|
|
38
|
+
"bz": 5100,
|
|
39
|
+
"ca": 5200,
|
|
40
|
+
"cc": 5400,
|
|
41
|
+
"cd": 5500,
|
|
42
|
+
"cf": 5700,
|
|
43
|
+
"cg": 5800,
|
|
44
|
+
"ch": 5900,
|
|
45
|
+
"ci": 6000,
|
|
46
|
+
"ck": 6200,
|
|
47
|
+
"cl": 6300,
|
|
48
|
+
"cm": 6400,
|
|
49
|
+
"cn": 6500,
|
|
50
|
+
"co": 6600,
|
|
51
|
+
"country_land": 0,
|
|
52
|
+
"cr": 6900,
|
|
53
|
+
"cu": 7200,
|
|
54
|
+
"cv": 7300,
|
|
55
|
+
"cw": 7400,
|
|
56
|
+
"cx": 7500,
|
|
57
|
+
"cy": 7600,
|
|
58
|
+
"cz": 7700,
|
|
59
|
+
"de": 8200,
|
|
60
|
+
"dj": 8700,
|
|
61
|
+
"dk": 8800,
|
|
62
|
+
"dm": 9000,
|
|
63
|
+
"do": 9200,
|
|
64
|
+
"dz": 10300,
|
|
65
|
+
"ec": 10600,
|
|
66
|
+
"ee": 10800,
|
|
67
|
+
"eg": 11000,
|
|
68
|
+
"eh": 11100,
|
|
69
|
+
"er": 12100,
|
|
70
|
+
"es": 12200,
|
|
71
|
+
"et": 12300,
|
|
72
|
+
"fi": 13800,
|
|
73
|
+
"fj": 13900,
|
|
74
|
+
"fk": 14000,
|
|
75
|
+
"fm": 14200,
|
|
76
|
+
"fo": 14400,
|
|
77
|
+
"fr": 14700,
|
|
78
|
+
"ga": 15600,
|
|
79
|
+
"gb": 15700,
|
|
80
|
+
"gd": 15900,
|
|
81
|
+
"ge": 16000,
|
|
82
|
+
"gf": 16100,
|
|
83
|
+
"gg": 16200,
|
|
84
|
+
"gh": 16300,
|
|
85
|
+
"gi": 16400,
|
|
86
|
+
"gl": 16700,
|
|
87
|
+
"gm": 16800,
|
|
88
|
+
"gn": 16900,
|
|
89
|
+
"gp": 17100,
|
|
90
|
+
"gq": 17200,
|
|
91
|
+
"gr": 17300,
|
|
92
|
+
"gs": 17400,
|
|
93
|
+
"gt": 17500,
|
|
94
|
+
"gu": 17600,
|
|
95
|
+
"gw": 17800,
|
|
96
|
+
"gy": 18000,
|
|
97
|
+
"hk": 19200,
|
|
98
|
+
"hm": 19400,
|
|
99
|
+
"hn": 19500,
|
|
100
|
+
"hr": 19900,
|
|
101
|
+
"ht": 20100,
|
|
102
|
+
"hu": 20200,
|
|
103
|
+
"id": 21100,
|
|
104
|
+
"ie": 21200,
|
|
105
|
+
"il": 21900,
|
|
106
|
+
"im": 22000,
|
|
107
|
+
"in": 22100,
|
|
108
|
+
"io": 22200,
|
|
109
|
+
"iq": 22400,
|
|
110
|
+
"ir": 22500,
|
|
111
|
+
"is": 22600,
|
|
112
|
+
"it": 22700,
|
|
113
|
+
"je": 23800,
|
|
114
|
+
"jm": 24600,
|
|
115
|
+
"jo": 24800,
|
|
116
|
+
"jp": 24900,
|
|
117
|
+
"jp-hokkaido": 24901,
|
|
118
|
+
"ke": 26400,
|
|
119
|
+
"kg": 26600,
|
|
120
|
+
"kh": 26700,
|
|
121
|
+
"ki": 26800,
|
|
122
|
+
"km": 27200,
|
|
123
|
+
"kn": 27300,
|
|
124
|
+
"kp": 27500,
|
|
125
|
+
"kr": 27700,
|
|
126
|
+
"kw": 28200,
|
|
127
|
+
"ky": 28400,
|
|
128
|
+
"kz": 28500,
|
|
129
|
+
"la": 28600,
|
|
130
|
+
"lb": 28700,
|
|
131
|
+
"lc": 28800,
|
|
132
|
+
"li": 29400,
|
|
133
|
+
"lk": 29600,
|
|
134
|
+
"lr": 30300,
|
|
135
|
+
"ls": 30400,
|
|
136
|
+
"lt": 30500,
|
|
137
|
+
"lu": 30600,
|
|
138
|
+
"lv": 30700,
|
|
139
|
+
"ly": 31000,
|
|
140
|
+
"ma": 31200,
|
|
141
|
+
"mc": 31400,
|
|
142
|
+
"md": 31500,
|
|
143
|
+
"me": 31600,
|
|
144
|
+
"mf": 31700,
|
|
145
|
+
"mg": 31800,
|
|
146
|
+
"mh": 31900,
|
|
147
|
+
"mk": 32200,
|
|
148
|
+
"ml": 32300,
|
|
149
|
+
"mm": 32400,
|
|
150
|
+
"mn": 32500,
|
|
151
|
+
"mo": 32600,
|
|
152
|
+
"mp": 32700,
|
|
153
|
+
"mq": 32800,
|
|
154
|
+
"mr": 32900,
|
|
155
|
+
"ms": 33000,
|
|
156
|
+
"mt": 33100,
|
|
157
|
+
"mu": 33200,
|
|
158
|
+
"mv": 33300,
|
|
159
|
+
"mw": 33400,
|
|
160
|
+
"mx": 33500,
|
|
161
|
+
"my": 33600,
|
|
162
|
+
"mz": 33700,
|
|
163
|
+
"na": 33800,
|
|
164
|
+
"nc": 34000,
|
|
165
|
+
"ne": 34200,
|
|
166
|
+
"nf": 34300,
|
|
167
|
+
"ng": 34400,
|
|
168
|
+
"ni": 34600,
|
|
169
|
+
"nl": 34900,
|
|
170
|
+
"no": 35200,
|
|
171
|
+
"np": 35300,
|
|
172
|
+
"nr": 35500,
|
|
173
|
+
"nu": 35800,
|
|
174
|
+
"nz": 36300,
|
|
175
|
+
"om": 37600,
|
|
176
|
+
"pa": 39000,
|
|
177
|
+
"pe": 39400,
|
|
178
|
+
"pf": 39500,
|
|
179
|
+
"pg": 39600,
|
|
180
|
+
"ph": 39700,
|
|
181
|
+
"pk": 40000,
|
|
182
|
+
"pl": 40100,
|
|
183
|
+
"pm": 40200,
|
|
184
|
+
"pn": 40300,
|
|
185
|
+
"pr": 40700,
|
|
186
|
+
"ps": 40800,
|
|
187
|
+
"pt": 40900,
|
|
188
|
+
"pw": 41200,
|
|
189
|
+
"py": 41400,
|
|
190
|
+
"qa": 41600,
|
|
191
|
+
"re": 44600,
|
|
192
|
+
"ro": 45600,
|
|
193
|
+
"rs": 46000,
|
|
194
|
+
"ru": 46200,
|
|
195
|
+
"rw": 46400,
|
|
196
|
+
"sa": 46800,
|
|
197
|
+
"sb": 46900,
|
|
198
|
+
"sc": 47000,
|
|
199
|
+
"sd": 47100,
|
|
200
|
+
"se": 47200,
|
|
201
|
+
"sg": 47400,
|
|
202
|
+
"sh": 47500,
|
|
203
|
+
"si": 47600,
|
|
204
|
+
"sj": 47700,
|
|
205
|
+
"sk": 47800,
|
|
206
|
+
"sl": 47900,
|
|
207
|
+
"sm": 48000,
|
|
208
|
+
"sn": 48100,
|
|
209
|
+
"so": 48200,
|
|
210
|
+
"sr": 48500,
|
|
211
|
+
"ss": 48600,
|
|
212
|
+
"st": 48700,
|
|
213
|
+
"sv": 48900,
|
|
214
|
+
"sx": 49100,
|
|
215
|
+
"sy": 49200,
|
|
216
|
+
"sz": 49300,
|
|
217
|
+
"tc": 49600,
|
|
218
|
+
"td": 49700,
|
|
219
|
+
"tf": 49900,
|
|
220
|
+
"tg": 50000,
|
|
221
|
+
"th": 50100,
|
|
222
|
+
"tj": 50300,
|
|
223
|
+
"tk": 50400,
|
|
224
|
+
"tl": 50500,
|
|
225
|
+
"tm": 50600,
|
|
226
|
+
"tn": 50700,
|
|
227
|
+
"to": 50800,
|
|
228
|
+
"tr": 51100,
|
|
229
|
+
"tt": 51300,
|
|
230
|
+
"tv": 51500,
|
|
231
|
+
"tw": 51600,
|
|
232
|
+
"tz": 51900,
|
|
233
|
+
"ua": 52000,
|
|
234
|
+
"ug": 52600,
|
|
235
|
+
"um": 53200,
|
|
236
|
+
"us": 53800,
|
|
237
|
+
"uy": 54400,
|
|
238
|
+
"uz": 54500,
|
|
239
|
+
"va": 54600,
|
|
240
|
+
"vc": 54800,
|
|
241
|
+
"ve": 55000,
|
|
242
|
+
"vg": 55200,
|
|
243
|
+
"vi": 55400,
|
|
244
|
+
"vn": 55900,
|
|
245
|
+
"vu": 56600,
|
|
246
|
+
"wf": 57700,
|
|
247
|
+
"ws": 59000,
|
|
248
|
+
"xk": 60800,
|
|
249
|
+
"ye": 62800,
|
|
250
|
+
"yt": 64300,
|
|
251
|
+
"za": 65000,
|
|
252
|
+
"zm": 66200,
|
|
253
|
+
"zw": 67200
|
|
254
|
+
}
|
package/schema_ids.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const ENTITY_TYPE_IDS: Readonly<Record<string, number>>;
|
|
2
|
+
export declare const ID_TO_ENTITY_TYPE: Readonly<Record<number, string>>;
|
|
3
|
+
export declare const GEOMETRY_KIND_IDS: Readonly<Record<string, number>>;
|
|
4
|
+
export declare const ID_TO_GEOMETRY_KIND: Readonly<Record<number, string>>;
|
|
5
|
+
export declare const FEATURE_KIND_IDS: Readonly<Record<string, number>>;
|
|
6
|
+
export declare const ID_TO_FEATURE_KIND: Readonly<Record<number, string>>;
|
|
7
|
+
export declare const REGION_NUMERIC_CODES: Readonly<Record<string, number>>;
|
|
8
|
+
export declare const SEGMENT_ROLE_IDS: Readonly<Record<string, number>>;
|
|
9
|
+
export declare const SEGMENT_ROLE_ID_UNSET: number;
|
|
10
|
+
export declare const SEGMENT_ROLE_ID_UNSUPPORTED: number;
|
|
11
|
+
export declare const ID_TO_SEGMENT_ROLE: Readonly<Record<number, string>>;
|
package/schema_ids.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const REGION_CODES_RAW = require("./region_numeric_codes.json");
|
|
5
|
+
|
|
6
|
+
export const ENTITY_TYPE_IDS = Object.freeze({
|
|
7
|
+
c: 0,
|
|
8
|
+
n: 1,
|
|
9
|
+
w: 2,
|
|
10
|
+
r: 3,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const ID_TO_ENTITY_TYPE = Object.freeze(
|
|
14
|
+
Object.fromEntries(Object.entries(ENTITY_TYPE_IDS).map(([k, v]) => [String(v), k]))
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export const GEOMETRY_KIND_IDS = Object.freeze({
|
|
18
|
+
point: 0,
|
|
19
|
+
polyline: 1,
|
|
20
|
+
polygon: 2,
|
|
21
|
+
grid_fill: 3,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const ID_TO_GEOMETRY_KIND = Object.freeze(
|
|
25
|
+
Object.fromEntries(Object.entries(GEOMETRY_KIND_IDS).map(([k, v]) => [String(v), k]))
|
|
26
|
+
);
|
|
27
|
+
export const FEATURE_KIND_IDS = Object.freeze({
|
|
28
|
+
country_land: 0,
|
|
29
|
+
admin_boundary: 100,
|
|
30
|
+
coastline: 200,
|
|
31
|
+
natural_area: 210,
|
|
32
|
+
waterbody: 220,
|
|
33
|
+
landuse: 230,
|
|
34
|
+
park: 240,
|
|
35
|
+
road_major: 300,
|
|
36
|
+
road_minor: 301,
|
|
37
|
+
waterway: 400,
|
|
38
|
+
place_label: 500,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const REGION_NUMERIC_CODES = Object.freeze(REGION_CODES_RAW);
|
|
42
|
+
|
|
43
|
+
export const ID_TO_FEATURE_KIND = Object.freeze(
|
|
44
|
+
Object.fromEntries(Object.entries(FEATURE_KIND_IDS).map(([k, v]) => [String(v), k]))
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export const SEGMENT_ROLE_ID_UNSET = 0x00;
|
|
48
|
+
export const SEGMENT_ROLE_ID_UNSUPPORTED = 0x0f;
|
|
49
|
+
|
|
50
|
+
export const SEGMENT_ROLE_IDS = Object.freeze({
|
|
51
|
+
"": SEGMENT_ROLE_ID_UNSET,
|
|
52
|
+
outer: 0x10,
|
|
53
|
+
inner: 0x11,
|
|
54
|
+
forward: 0x12,
|
|
55
|
+
backward: 0x13,
|
|
56
|
+
from: 0x14,
|
|
57
|
+
via: 0x15,
|
|
58
|
+
to: 0x16,
|
|
59
|
+
label: 0x17,
|
|
60
|
+
perimeter: 0x18,
|
|
61
|
+
main_stream: 0x19,
|
|
62
|
+
side_stream: 0x1a,
|
|
63
|
+
anabranch: 0x1b,
|
|
64
|
+
spring: 0x1c,
|
|
65
|
+
mouth: 0x1d,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export const ID_TO_SEGMENT_ROLE = Object.freeze({
|
|
69
|
+
...Object.fromEntries(
|
|
70
|
+
Object.entries(SEGMENT_ROLE_IDS).map(([role, id]) => [String(id), role])
|
|
71
|
+
),
|
|
72
|
+
[String(SEGMENT_ROLE_ID_UNSUPPORTED)]: "<unsupported>",
|
|
73
|
+
});
|