@osmix/core 0.0.1 → 0.0.6

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.
Files changed (107) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +118 -107
  3. package/dist/core/src/entities.d.ts +114 -0
  4. package/dist/core/src/entities.d.ts.map +1 -0
  5. package/dist/core/src/entities.js +152 -0
  6. package/dist/core/src/entities.js.map +1 -0
  7. package/dist/core/src/ids.d.ts +113 -0
  8. package/dist/core/src/ids.d.ts.map +1 -0
  9. package/dist/core/src/ids.js +236 -0
  10. package/dist/core/src/ids.js.map +1 -0
  11. package/dist/core/src/index.d.ts +32 -0
  12. package/dist/core/src/index.d.ts.map +1 -0
  13. package/dist/core/src/index.js +35 -0
  14. package/dist/core/src/index.js.map +1 -0
  15. package/dist/core/src/nodes.d.ts +101 -0
  16. package/dist/core/src/nodes.d.ts.map +1 -0
  17. package/dist/core/src/nodes.js +309 -0
  18. package/dist/core/src/nodes.js.map +1 -0
  19. package/dist/core/src/osm.d.ts +74 -0
  20. package/dist/core/src/osm.d.ts.map +1 -0
  21. package/dist/core/src/osm.js +120 -0
  22. package/dist/core/src/osm.js.map +1 -0
  23. package/dist/core/src/relations.d.ts +118 -0
  24. package/dist/core/src/relations.d.ts.map +1 -0
  25. package/dist/core/src/relations.js +412 -0
  26. package/dist/core/src/relations.js.map +1 -0
  27. package/dist/core/src/stringtable.d.ts +95 -0
  28. package/dist/core/src/stringtable.d.ts.map +1 -0
  29. package/dist/core/src/stringtable.js +170 -0
  30. package/dist/core/src/stringtable.js.map +1 -0
  31. package/dist/core/src/tags.d.ts +126 -0
  32. package/dist/core/src/tags.d.ts.map +1 -0
  33. package/dist/core/src/tags.js +228 -0
  34. package/dist/core/src/tags.js.map +1 -0
  35. package/dist/core/src/typed-arrays.d.ts +124 -0
  36. package/dist/core/src/typed-arrays.d.ts.map +1 -0
  37. package/dist/core/src/typed-arrays.js +198 -0
  38. package/dist/core/src/typed-arrays.js.map +1 -0
  39. package/dist/core/src/utils.d.ts +11 -0
  40. package/dist/core/src/utils.d.ts.map +1 -0
  41. package/dist/core/src/utils.js +26 -0
  42. package/dist/core/src/utils.js.map +1 -0
  43. package/dist/core/src/ways.d.ts +101 -0
  44. package/dist/core/src/ways.d.ts.map +1 -0
  45. package/dist/core/src/ways.js +336 -0
  46. package/dist/core/src/ways.js.map +1 -0
  47. package/dist/core/test/memory.test.d.ts +7 -0
  48. package/dist/core/test/memory.test.d.ts.map +1 -0
  49. package/dist/core/test/memory.test.js +29 -0
  50. package/dist/core/test/memory.test.js.map +1 -0
  51. package/dist/core/test/mock-osm.d.ts +13 -0
  52. package/dist/core/test/mock-osm.d.ts.map +1 -0
  53. package/dist/core/test/mock-osm.js +122 -0
  54. package/dist/core/test/mock-osm.js.map +1 -0
  55. package/dist/core/test/tags-search.test.d.ts +2 -0
  56. package/dist/core/test/tags-search.test.d.ts.map +1 -0
  57. package/dist/core/test/tags-search.test.js +56 -0
  58. package/dist/core/test/tags-search.test.js.map +1 -0
  59. package/dist/core/test/typed-arrays.test.d.ts +2 -0
  60. package/dist/core/test/typed-arrays.test.d.ts.map +1 -0
  61. package/dist/core/test/typed-arrays.test.js +102 -0
  62. package/dist/core/test/typed-arrays.test.js.map +1 -0
  63. package/dist/osmix/src/extract.d.ts +43 -0
  64. package/dist/osmix/src/extract.d.ts.map +1 -0
  65. package/dist/osmix/src/extract.js +156 -0
  66. package/dist/osmix/src/extract.js.map +1 -0
  67. package/dist/osmix/src/pbf.d.ts +55 -0
  68. package/dist/osmix/src/pbf.d.ts.map +1 -0
  69. package/dist/osmix/src/pbf.js +187 -0
  70. package/dist/osmix/src/pbf.js.map +1 -0
  71. package/dist/osmix/src/utils.d.ts +36 -0
  72. package/dist/osmix/src/utils.d.ts.map +1 -0
  73. package/dist/osmix/src/utils.js +108 -0
  74. package/dist/osmix/src/utils.js.map +1 -0
  75. package/dist/osmix/test/extract.bench.d.ts +2 -0
  76. package/dist/osmix/test/extract.bench.d.ts.map +1 -0
  77. package/dist/osmix/test/extract.bench.js +26 -0
  78. package/dist/osmix/test/extract.bench.js.map +1 -0
  79. package/dist/osmix/test/extract.test.d.ts +2 -0
  80. package/dist/osmix/test/extract.test.d.ts.map +1 -0
  81. package/dist/osmix/test/extract.test.js +392 -0
  82. package/dist/osmix/test/extract.test.js.map +1 -0
  83. package/package.json +11 -11
  84. package/src/entities.ts +138 -22
  85. package/src/ids.ts +117 -45
  86. package/src/index.ts +34 -5
  87. package/src/nodes.ts +237 -58
  88. package/src/osm.ts +174 -0
  89. package/src/relations.ts +383 -54
  90. package/src/stringtable.ts +111 -36
  91. package/src/tags.ts +207 -46
  92. package/src/typed-arrays.ts +97 -10
  93. package/src/types/geoflatbush.d.ts +37 -0
  94. package/src/types/geokdbush.d.ts +37 -0
  95. package/src/types/kdbush.d.ts +24 -6
  96. package/src/utils.ts +9 -14
  97. package/src/ways.ts +248 -84
  98. package/test/memory.test.ts +38 -0
  99. package/test/mock-osm.ts +8 -8
  100. package/test/tags-search.test.ts +60 -0
  101. package/test/typed-arrays.test.ts +5 -6
  102. package/tsconfig.json +7 -1
  103. package/src/osmix.ts +0 -556
  104. package/test/extract.bench.ts +0 -29
  105. package/test/extract.test.ts +0 -156
  106. package/test/read.test.ts +0 -22
  107. package/test/write.test.ts +0 -66
@@ -0,0 +1,309 @@
1
+ import { assertValue } from "@osmix/shared/assert";
2
+ import { microToDegrees, toMicroDegrees } from "@osmix/shared/coordinates";
3
+ import { around as geoAround } from "geokdbush";
4
+ import KDBush from "kdbush";
5
+ import { Entities } from "./entities";
6
+ import { Ids } from "./ids";
7
+ import { Tags } from "./tags";
8
+ import { BufferConstructor, ResizeableTypedArray as RTA, } from "./typed-arrays";
9
+ export class Nodes extends Entities {
10
+ /**
11
+ * Coordinates are stored as integer microdegrees (Int32Array).
12
+ * Use OSM_COORD_SCALE (1e7) to convert between degrees and microdegrees.
13
+ */
14
+ lons;
15
+ lats;
16
+ // Bbox stored in microdegrees internally
17
+ bbox = [
18
+ Number.MAX_SAFE_INTEGER,
19
+ Number.MAX_SAFE_INTEGER,
20
+ Number.MIN_SAFE_INTEGER,
21
+ Number.MIN_SAFE_INTEGER,
22
+ ];
23
+ // Spatial index stores coordinates in degrees (Float64Array) for geokdbush compatibility
24
+ spatialIndex = new KDBush(0, 128, Float64Array, BufferConstructor);
25
+ // Track if spatial index was properly built (vs default empty)
26
+ spatialIndexBuilt = false;
27
+ /**
28
+ * Create a new Nodes index.
29
+ */
30
+ constructor(stringTable, transferables) {
31
+ if (transferables) {
32
+ super("node", new Ids(transferables), new Tags(stringTable, transferables));
33
+ this.lons = RTA.from(Int32Array, transferables.lons);
34
+ this.lats = RTA.from(Int32Array, transferables.lats);
35
+ // Only load spatial index if provided (not stored in IndexedDB)
36
+ if (transferables.spatialIndex?.byteLength) {
37
+ this.spatialIndex = KDBush.from(transferables.spatialIndex);
38
+ this.spatialIndexBuilt = true;
39
+ }
40
+ this.bbox = transferables.bbox;
41
+ this.indexBuilt = true;
42
+ }
43
+ else {
44
+ super("node", new Ids(), new Tags(stringTable));
45
+ this.lons = new RTA(Int32Array);
46
+ this.lats = new RTA(Int32Array);
47
+ // Spatial index uses Float64Array with degrees for geokdbush compatibility
48
+ this.spatialIndex = new KDBush(0, 128, Float64Array, BufferConstructor);
49
+ }
50
+ }
51
+ /**
52
+ * Add a single node to the index.
53
+ */
54
+ addNode(node) {
55
+ const nodeIndex = this.addEntity(node.id, node.tags ?? {});
56
+ const lonMicro = toMicroDegrees(node.lon);
57
+ const latMicro = toMicroDegrees(node.lat);
58
+ this.lons.push(lonMicro);
59
+ this.lats.push(latMicro);
60
+ if (node.lon < this.bbox[0])
61
+ this.bbox[0] = node.lon;
62
+ if (node.lat < this.bbox[1])
63
+ this.bbox[1] = node.lat;
64
+ if (node.lon > this.bbox[2])
65
+ this.bbox[2] = node.lon;
66
+ if (node.lat > this.bbox[3])
67
+ this.bbox[3] = node.lat;
68
+ return nodeIndex;
69
+ }
70
+ /**
71
+ * Add dense nodes from a PBF block.
72
+ */
73
+ addDenseNodes(dense, block, blockStringIndexMap, filter) {
74
+ // PBF block already has offsets and granularity converted to degrees
75
+ const lon_offset = block.lon_offset ?? 0;
76
+ const lat_offset = block.lat_offset ?? 0;
77
+ const granularity = block.granularity ?? 1e7;
78
+ const delta = {
79
+ id: 0,
80
+ lat: 0,
81
+ lon: 0,
82
+ timestamp: 0,
83
+ changeset: 0,
84
+ uid: 0,
85
+ user_sid: 0,
86
+ };
87
+ const getStringTableIndex = (keyIndex) => {
88
+ const key = dense.keys_vals[keyIndex];
89
+ assertValue(key, "Block string key is undefined");
90
+ const index = blockStringIndexMap[key];
91
+ assertValue(index, "Block string not found");
92
+ return index;
93
+ };
94
+ let keysValsIndex = 0;
95
+ let added = 0;
96
+ for (let i = 0; i < dense.id.length; i++) {
97
+ const idSid = dense.id[i];
98
+ const latSid = dense.lat[i];
99
+ const lonSid = dense.lon[i];
100
+ assertValue(idSid, "ID SID is undefined");
101
+ assertValue(latSid, "Latitude SID is undefined");
102
+ assertValue(lonSid, "Longitude SID is undefined");
103
+ delta.id += idSid;
104
+ delta.lat += latSid;
105
+ delta.lon += lonSid;
106
+ // Calculate degrees from PBF delta encoding
107
+ const lon = lon_offset + delta.lon / granularity;
108
+ const lat = lat_offset + delta.lat / granularity;
109
+ // Convert to microdegrees for storage
110
+ const lonMicro = toMicroDegrees(lon);
111
+ const latMicro = toMicroDegrees(lat);
112
+ const tagKeys = [];
113
+ const tagValues = [];
114
+ if (dense.keys_vals.length > 0) {
115
+ while (dense.keys_vals[keysValsIndex] !== 0) {
116
+ const key = getStringTableIndex(keysValsIndex);
117
+ const val = getStringTableIndex(keysValsIndex + 1);
118
+ if (key && val) {
119
+ tagKeys.push(key);
120
+ tagValues.push(val);
121
+ }
122
+ keysValsIndex += 2;
123
+ }
124
+ keysValsIndex++;
125
+ }
126
+ const shouldInclude = filter
127
+ ? filter({
128
+ id: delta.id,
129
+ lon,
130
+ lat,
131
+ tags: this.tags.getTagsFromIndices(tagKeys, tagValues),
132
+ })
133
+ : true;
134
+ if (!shouldInclude)
135
+ continue;
136
+ this.addEntity(delta.id, tagKeys, tagValues);
137
+ this.lons.push(lonMicro);
138
+ this.lats.push(latMicro);
139
+ if (lon < this.bbox[0])
140
+ this.bbox[0] = lon;
141
+ if (lat < this.bbox[1])
142
+ this.bbox[1] = lat;
143
+ if (lon > this.bbox[2])
144
+ this.bbox[2] = lon;
145
+ if (lat > this.bbox[3])
146
+ this.bbox[3] = lat;
147
+ added++;
148
+ }
149
+ return added;
150
+ }
151
+ /**
152
+ * Compact the internal arrays to free up memory.
153
+ */
154
+ buildEntityIndex() {
155
+ this.lons.compact();
156
+ this.lats.compact();
157
+ }
158
+ /**
159
+ * Build the spatial index for nodes.
160
+ * Spatial index stores degrees (Float64Array) for geokdbush compatibility.
161
+ */
162
+ buildSpatialIndex() {
163
+ console.time("NodeIndex.buildSpatialIndex");
164
+ // Use Float64Array with degrees for geokdbush geographic queries
165
+ this.spatialIndex = new KDBush(this.size, 64, Float64Array, BufferConstructor);
166
+ for (let i = 0; i < this.size; i++) {
167
+ // Convert microdegrees to degrees for spatial index
168
+ const lon = microToDegrees(this.lons.at(i));
169
+ const lat = microToDegrees(this.lats.at(i));
170
+ this.spatialIndex.add(lon, lat);
171
+ }
172
+ this.spatialIndex.finish();
173
+ this.spatialIndexBuilt = true;
174
+ console.timeEnd("NodeIndex.buildSpatialIndex");
175
+ }
176
+ /**
177
+ * Check if the spatial index has been built.
178
+ */
179
+ hasSpatialIndex() {
180
+ return this.spatialIndexBuilt;
181
+ }
182
+ /**
183
+ * Get the bounding box of all nodes.
184
+ */
185
+ getBbox() {
186
+ return this.bbox;
187
+ }
188
+ /**
189
+ * Get the bounding box of a specific node.
190
+ */
191
+ getEntityBbox(i) {
192
+ const index = "index" in i ? i.index : this.ids.idOrIndex(i)[0];
193
+ const lon = microToDegrees(this.lons.at(index));
194
+ const lat = microToDegrees(this.lats.at(index));
195
+ return [lon, lat, lon, lat];
196
+ }
197
+ /**
198
+ * Get the longitude and latitude of a specific node.
199
+ */
200
+ getNodeLonLat(i) {
201
+ const index = "index" in i ? i.index : this.ids.idOrIndex(i)[0];
202
+ return [
203
+ microToDegrees(this.lons.at(index)),
204
+ microToDegrees(this.lats.at(index)),
205
+ ];
206
+ }
207
+ /**
208
+ * Get the full node entity.
209
+ */
210
+ getFullEntity(index, id, tags) {
211
+ const [lon, lat] = this.getNodeLonLat({ index });
212
+ if (tags) {
213
+ return {
214
+ id,
215
+ lat,
216
+ lon,
217
+ tags,
218
+ };
219
+ }
220
+ return {
221
+ id,
222
+ lat,
223
+ lon,
224
+ };
225
+ }
226
+ // Spatial operations
227
+ /**
228
+ * Find node indexes within a bounding box.
229
+ */
230
+ findIndexesWithinBbox(bbox) {
231
+ // Spatial index stores degrees, so query with degrees directly
232
+ return this.spatialIndex.range(bbox[0], bbox[1], bbox[2], bbox[3]);
233
+ }
234
+ /**
235
+ * Find node indexes within a radius of a point.
236
+ * Uses geokdbush for proper great-circle distance calculations.
237
+ * @param lon - Longitude in degrees.
238
+ * @param lat - Latitude in degrees.
239
+ * @param radiusKm - Radius in kilometers.
240
+ * @returns Array of node indexes within the radius.
241
+ */
242
+ findIndexesWithinRadius(lon, lat, radiusKm) {
243
+ // Use geokdbush for proper geographic distance calculations
244
+ return geoAround(this.spatialIndex, lon, lat, Number.POSITIVE_INFINITY, radiusKm);
245
+ }
246
+ /**
247
+ * Get nodes within a bounding box.
248
+ * @param bbox - The bounding box to search within.
249
+ * @param include - A function to filter nodes. If provided, only nodes for which the function returns true will be included.
250
+ * @returns An object containing the IDs and positions of the nodes within the bounding box.
251
+ */
252
+ withinBbox(bbox, include) {
253
+ console.time("Nodes.withinBbox");
254
+ const nodeCandidates = this.findIndexesWithinBbox(bbox);
255
+ const nodePositions = new Float64Array(nodeCandidates.length * 2);
256
+ const ids = new Float64Array(nodeCandidates.length);
257
+ let skipped = 0;
258
+ nodeCandidates.forEach((nodeIndex, i) => {
259
+ if (include && !include(nodeIndex)) {
260
+ skipped++;
261
+ return;
262
+ }
263
+ const [lon, lat] = this.getNodeLonLat({ index: nodeIndex });
264
+ ids[i - skipped] = this.ids.at(nodeIndex);
265
+ nodePositions[(i - skipped) * 2] = lon;
266
+ nodePositions[(i - skipped) * 2 + 1] = lat;
267
+ });
268
+ console.timeEnd("Nodes.withinBbox");
269
+ return {
270
+ ids: ids.subarray(0, nodeCandidates.length - skipped),
271
+ positions: nodePositions.slice(0, (nodeCandidates.length - skipped) * 2),
272
+ };
273
+ }
274
+ /**
275
+ * Get transferable objects for passing to another thread.
276
+ * Only includes spatialIndex if it has been built.
277
+ */
278
+ transferables() {
279
+ const base = {
280
+ ...super.transferables(),
281
+ lons: this.lons.array.buffer,
282
+ lats: this.lats.array.buffer,
283
+ bbox: this.bbox,
284
+ };
285
+ // Only include spatial index if it was built
286
+ if (this.spatialIndexBuilt) {
287
+ return { ...base, spatialIndex: this.spatialIndex.data };
288
+ }
289
+ return base;
290
+ }
291
+ /**
292
+ * Get the approximate memory requirements for a given number of nodes in bytes.
293
+ */
294
+ static getBytesRequired(count) {
295
+ if (count === 0)
296
+ return 0;
297
+ const indexBytes = (count < 65536 ? 2 : 4) * count;
298
+ // Spatial index stores coordinates in degrees (Float64Array)
299
+ const coordsBytes = count * 2 * Float64Array.BYTES_PER_ELEMENT;
300
+ const padding = (8 - (indexBytes % 8)) % 8;
301
+ const spatialIndexBytes = 8 + indexBytes + coordsBytes + padding;
302
+ return (Ids.getBytesRequired(count) +
303
+ Tags.getBytesRequired(count) +
304
+ count * Int32Array.BYTES_PER_ELEMENT + // lons (stored in microdegrees)
305
+ count * Int32Array.BYTES_PER_ELEMENT + // lats (stored in microdegrees)
306
+ spatialIndexBytes);
307
+ }
308
+ }
309
+ //# sourceMappingURL=nodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../../src/nodes.ts"],"names":[],"mappings":"A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GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;QAC1C,MAAM,iBAAiB,GAAG,CAAC,GAAG,UAAU,GAAG,WAAW,GAAG,OAAO,CAAA;QAEhE,OAAO,CACN,GAAG,CAAC,gBAAgB,CAAC,KAAK,CAAC;YAC3B,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;YAC5B,KAAK,GAAG,UAAU,CAAC,iBAAiB,GAAG,gCAAgC;YACvE,KAAK,GAAG,UAAU,CAAC,iBAAiB,GAAG,gCAAgC;YACvE,iBAAiB,CACjB,CAAA;IACF,CAAC;CACD"}
@@ -0,0 +1,74 @@
1
+ import type { OsmPbfHeaderBlock } from "@osmix/pbf";
2
+ import type { GeoBbox2D } from "@osmix/shared/types";
3
+ import { Nodes, type NodesTransferables } from "./nodes";
4
+ import { Relations, type RelationsTransferables } from "./relations";
5
+ import StringTable, { type StringTableTransferables } from "./stringtable";
6
+ import type { BufferType } from "./typed-arrays";
7
+ import { Ways, type WaysTransferables } from "./ways";
8
+ export interface OsmTransferables<T extends BufferType = BufferType> {
9
+ id: string;
10
+ header: OsmPbfHeaderBlock;
11
+ stringTable: StringTableTransferables<T>;
12
+ nodes: NodesTransferables<T>;
13
+ ways: WaysTransferables<T>;
14
+ relations: RelationsTransferables<T>;
15
+ }
16
+ export interface OsmInfo {
17
+ id: string;
18
+ bbox: GeoBbox2D;
19
+ header: OsmPbfHeaderBlock;
20
+ stats: {
21
+ nodes: number;
22
+ ways: number;
23
+ relations: number;
24
+ };
25
+ }
26
+ export interface OsmOptions {
27
+ id: string;
28
+ header: OsmPbfHeaderBlock;
29
+ }
30
+ /**
31
+ * OSM Entity Index.
32
+ */
33
+ export declare class Osm {
34
+ readonly id: string;
35
+ readonly header: OsmPbfHeaderBlock;
36
+ readonly stringTable: StringTable;
37
+ readonly nodes: Nodes;
38
+ readonly ways: Ways;
39
+ readonly relations: Relations;
40
+ private indexBuilt;
41
+ /**
42
+ * Create a new OSM Entity index.
43
+ */
44
+ constructor(opts?: Partial<OsmOptions> | OsmTransferables | Osm);
45
+ /**
46
+ * Build the internal indexes for all entities.
47
+ */
48
+ buildIndexes(): void;
49
+ /**
50
+ * Check if the index is built and ready for use.
51
+ */
52
+ isReady(): boolean;
53
+ /**
54
+ * Build spatial indexes for all entities.
55
+ */
56
+ buildSpatialIndexes(): void;
57
+ /**
58
+ * Check if spatial indexes have been built for all entity types.
59
+ */
60
+ hasSpatialIndexes(): boolean;
61
+ /**
62
+ * Get the bounding box of all entities in the OSM index.
63
+ */
64
+ bbox(): GeoBbox2D;
65
+ /**
66
+ * Get information about the OSM index.
67
+ */
68
+ info(): OsmInfo;
69
+ /**
70
+ * Get transferable objects for passing to another thread.
71
+ */
72
+ transferables(): OsmTransferables;
73
+ }
74
+ //# sourceMappingURL=osm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"osm.d.ts","sourceRoot":"","sources":["../../../src/osm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,KAAK,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACpE,OAAO,WAAW,EAAE,EAAE,KAAK,wBAAwB,EAAE,MAAM,eAAe,CAAA;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,KAAK,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAErD,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IAClE,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,iBAAiB,CAAA;IACzB,WAAW,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAA;IACx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import { Ways } from "./ways";
5
+ /**
6
+ * OSM Entity Index.
7
+ */
8
+ export class Osm {
9
+ // Filename or ID of this OSM Entity index.
10
+ id;
11
+ header;
12
+ // Shared string lookup table for all nodes, ways, and relations
13
+ stringTable;
14
+ nodes;
15
+ ways;
16
+ relations;
17
+ indexBuilt = false;
18
+ /**
19
+ * Create a new OSM Entity index.
20
+ */
21
+ constructor(opts) {
22
+ this.id = opts?.id ?? "unknown";
23
+ this.header = opts?.header ?? {
24
+ required_features: [],
25
+ optional_features: [],
26
+ };
27
+ if (opts && "stringTable" in opts) {
28
+ if (opts instanceof Osm) {
29
+ this.stringTable = new StringTable(opts.stringTable.transferables());
30
+ this.nodes = new Nodes(this.stringTable, opts.nodes.transferables());
31
+ this.ways = new Ways(this.stringTable, this.nodes, opts.ways.transferables());
32
+ this.relations = new Relations(this.stringTable, this.nodes, this.ways, opts.relations.transferables());
33
+ this.indexBuilt = true;
34
+ }
35
+ else {
36
+ this.stringTable = new StringTable(opts.stringTable);
37
+ this.nodes = new Nodes(this.stringTable, opts.nodes);
38
+ this.ways = new Ways(this.stringTable, this.nodes, opts.ways);
39
+ this.relations = new Relations(this.stringTable, this.nodes, this.ways, opts.relations);
40
+ this.indexBuilt = true;
41
+ }
42
+ }
43
+ else {
44
+ this.stringTable = new StringTable();
45
+ this.nodes = new Nodes(this.stringTable);
46
+ this.ways = new Ways(this.stringTable, this.nodes);
47
+ this.relations = new Relations(this.stringTable, this.nodes, this.ways);
48
+ }
49
+ }
50
+ /**
51
+ * Build the internal indexes for all entities.
52
+ */
53
+ buildIndexes() {
54
+ this.stringTable.buildIndex();
55
+ this.nodes.buildIndex();
56
+ this.ways.buildIndex();
57
+ this.relations.buildIndex();
58
+ this.indexBuilt = true;
59
+ }
60
+ /**
61
+ * Check if the index is built and ready for use.
62
+ */
63
+ isReady() {
64
+ return (this.nodes.isReady() &&
65
+ this.ways.isReady() &&
66
+ this.relations.isReady() &&
67
+ this.indexBuilt);
68
+ }
69
+ /**
70
+ * Build spatial indexes for all entities.
71
+ */
72
+ buildSpatialIndexes() {
73
+ this.nodes.buildSpatialIndex();
74
+ this.ways.buildSpatialIndex();
75
+ this.relations.buildSpatialIndex();
76
+ }
77
+ /**
78
+ * Check if spatial indexes have been built for all entity types.
79
+ */
80
+ hasSpatialIndexes() {
81
+ return (this.nodes.hasSpatialIndex() &&
82
+ this.ways.hasSpatialIndex() &&
83
+ this.relations.hasSpatialIndex());
84
+ }
85
+ /**
86
+ * Get the bounding box of all entities in the OSM index.
87
+ */
88
+ bbox() {
89
+ return this.nodes.getBbox();
90
+ }
91
+ /**
92
+ * Get information about the OSM index.
93
+ */
94
+ info() {
95
+ return {
96
+ id: this.id,
97
+ bbox: this.bbox(),
98
+ header: this.header,
99
+ stats: {
100
+ nodes: this.nodes.size,
101
+ ways: this.ways.size,
102
+ relations: this.relations.size,
103
+ },
104
+ };
105
+ }
106
+ /**
107
+ * Get transferable objects for passing to another thread.
108
+ */
109
+ transferables() {
110
+ return {
111
+ id: this.id,
112
+ header: this.header,
113
+ stringTable: this.stringTable.transferables(),
114
+ nodes: this.nodes.transferables(),
115
+ ways: this.ways.transferables(),
116
+ relations: this.relations.transferables(),
117
+ };
118
+ }
119
+ }
120
+ //# sourceMappingURL=osm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"osm.js","sourceRoot":"","sources":["../../../src/osm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAA2B,MAAM,SAAS,CAAA;AACxD,OAAO,EAAE,SAAS,EAA+B,MAAM,aAAa,CAAA;AACpE,OAAO,WAAW,EAAE,EAAiC,MAAM,eAAe,CAAA;AAE1E,OAAO,EAAE,IAAI,EAA0B,MAAM,QAAQ,CAAA;AA2BrD;;GAEG;AACH,MAAM,OAAO,GAAG;IACf,2CAA2C;IAClC,EAAE,CAAQ;IACV,MAAM,CAAmB;IAElC,gEAAgE;IACvD,WAAW,CAAa;IACxB,KAAK,CAAO;IACZ,IAAI,CAAM;IACV,S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B,EAAE,CAAA;QAC7B,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAA;IACnC,CAAC;IAED;;OAEG;IACH,iBAAiB;QAChB,OAAO,CACN,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE;YAC5B,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YAC3B,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,CAChC,CAAA;IACF,CAAC;IAED;;OAEG;IACH,IAAI;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAA;IAC5B,CAAC;IAED;;OAEG;IACH,IAAI;QACH,OAAO;YACN,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE;gBACN,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI;gBACtB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;gBACpB,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI;aAC9B;SACD,CAAA;IACF,CAAC;IAED;;OAEG;IACH,aAAa;QACZ,OAAO;YACN,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE;YAC7C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE;YACjC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YAC/B,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;SACzC,CAAA;IACF,CAAC;CACD"}
@@ -0,0 +1,118 @@
1
+ import type { OsmPbfRelation } from "@osmix/pbf";
2
+ import type { GeoBbox2D, LonLat, OsmEntityType, OsmRelation, OsmRelationMember, OsmTags } from "@osmix/shared/types";
3
+ import Flatbush from "flatbush";
4
+ import { Entities, type EntitiesTransferables } from "./entities";
5
+ import { type IdOrIndex } from "./ids";
6
+ import type { Nodes } from "./nodes";
7
+ import type StringTable from "./stringtable";
8
+ import { type BufferType } from "./typed-arrays";
9
+ import type { Ways } from "./ways";
10
+ export interface RelationsTransferables<T extends BufferType = BufferType> extends EntitiesTransferables<T> {
11
+ memberStart: T;
12
+ memberCount: T;
13
+ memberRefs: T;
14
+ memberTypes: T;
15
+ memberRoles: T;
16
+ bbox: T;
17
+ /** Optional - can be rebuilt via buildSpatialIndex() */
18
+ spatialIndex?: T;
19
+ }
20
+ export declare class Relations extends Entities<OsmRelation> {
21
+ private stringTable;
22
+ private memberStart;
23
+ private memberCount;
24
+ private memberRefs;
25
+ private memberTypes;
26
+ private memberRoles;
27
+ private spatialIndex;
28
+ private spatialIndexBuilt;
29
+ private bbox;
30
+ private nodes;
31
+ private ways;
32
+ /**
33
+ * Create a new Relations index.
34
+ */
35
+ constructor(stringTable: StringTable, nodes: Nodes, ways: Ways, transferables?: RelationsTransferables);
36
+ /**
37
+ * Add a single relation to the index.
38
+ */
39
+ addRelation(relation: OsmRelation): number;
40
+ /**
41
+ * Bulk add relations directly from a PBF PrimitiveBlock.
42
+ */
43
+ addRelations(relations: OsmPbfRelation[], blockStringIndexMap: Uint32Array, filter?: (relation: OsmRelation) => OsmRelation | null): number;
44
+ /**
45
+ * Compact the internal arrays to free up memory.
46
+ */
47
+ buildEntityIndex(): void;
48
+ /**
49
+ * Build the spatial index for relations.
50
+ * Handles nested relations by resolving all descendant nodes and ways.
51
+ * If bbox data already exists (e.g., loaded from storage), reuses it.
52
+ */
53
+ buildSpatialIndex(): Flatbush;
54
+ /**
55
+ * Check if the spatial index has been built.
56
+ */
57
+ hasSpatialIndex(): boolean;
58
+ /**
59
+ * Collect all coordinates from a relation, including nested relations.
60
+ * Used for building bounding boxes and spatial indexes.
61
+ */
62
+ private collectRelationCoordinates;
63
+ /**
64
+ * Get the bounding box of a relation.
65
+ */
66
+ getEntityBbox(i: IdOrIndex): GeoBbox2D;
67
+ /**
68
+ * Get the full relation entity.
69
+ */
70
+ getFullEntity(index: number, id: number, tags?: OsmTags): OsmRelation;
71
+ /**
72
+ * Get the members of a relation.
73
+ */
74
+ getMembersByIndex(index: number, relationMemberTypes?: OsmEntityType[]): OsmRelationMember[];
75
+ /**
76
+ * Check if a relation includes a specific member.
77
+ */
78
+ includesMember(index: number, memberRef: number, memberType: OsmEntityType, memberRole?: string): boolean;
79
+ /**
80
+ * Get all way IDs that are members of relations, including nested relations.
81
+ * Used to exclude these ways from individual rendering.
82
+ */
83
+ getWayMemberIds(): Set<number>;
84
+ /**
85
+ * Get relation geometry based on its kind.
86
+ * Returns coordinates suitable for rendering based on relation type.
87
+ * @param index - Relation index
88
+ * @returns Object with geometry data based on relation kind
89
+ */
90
+ getRelationGeometry(index: number): {
91
+ points?: LonLat[];
92
+ lineStrings?: LonLat[][];
93
+ rings?: LonLat[][][];
94
+ };
95
+ /**
96
+ * Find relations that intersect a bounding box.
97
+ */
98
+ intersects(bbox: GeoBbox2D, filterFn?: (index: number) => boolean): number[];
99
+ /**
100
+ * Find relation indexes near a point using great-circle distance.
101
+ * @param lon - Longitude in degrees.
102
+ * @param lat - Latitude in degrees.
103
+ * @param maxResults - Maximum number of results to return.
104
+ * @param maxDistanceKm - Maximum distance in kilometers.
105
+ * @returns Array of relation indexes sorted by distance.
106
+ */
107
+ neighbors(lon: number, lat: number, maxResults?: number, maxDistanceKm?: number): number[];
108
+ /**
109
+ * Get transferable objects for passing to another thread.
110
+ * Only includes spatialIndex if it has been built.
111
+ */
112
+ transferables(): RelationsTransferables;
113
+ /**
114
+ * Get the approximate memory requirements for a given number of relations in bytes.
115
+ */
116
+ static getBytesRequired(count: number): number;
117
+ }
118
+ //# sourceMappingURL=relations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relations.d.ts","sourceRoot":"","sources":["../../../src/relations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AA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