@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.
- package/CHANGELOG.md +52 -0
- package/README.md +118 -107
- package/dist/core/src/entities.d.ts +114 -0
- package/dist/core/src/entities.d.ts.map +1 -0
- package/dist/core/src/entities.js +152 -0
- package/dist/core/src/entities.js.map +1 -0
- package/dist/core/src/ids.d.ts +113 -0
- package/dist/core/src/ids.d.ts.map +1 -0
- package/dist/core/src/ids.js +236 -0
- package/dist/core/src/ids.js.map +1 -0
- package/dist/core/src/index.d.ts +32 -0
- package/dist/core/src/index.d.ts.map +1 -0
- package/dist/core/src/index.js +35 -0
- package/dist/core/src/index.js.map +1 -0
- package/dist/core/src/nodes.d.ts +101 -0
- package/dist/core/src/nodes.d.ts.map +1 -0
- package/dist/core/src/nodes.js +309 -0
- package/dist/core/src/nodes.js.map +1 -0
- package/dist/core/src/osm.d.ts +74 -0
- package/dist/core/src/osm.d.ts.map +1 -0
- package/dist/core/src/osm.js +120 -0
- package/dist/core/src/osm.js.map +1 -0
- package/dist/core/src/relations.d.ts +118 -0
- package/dist/core/src/relations.d.ts.map +1 -0
- package/dist/core/src/relations.js +412 -0
- package/dist/core/src/relations.js.map +1 -0
- package/dist/core/src/stringtable.d.ts +95 -0
- package/dist/core/src/stringtable.d.ts.map +1 -0
- package/dist/core/src/stringtable.js +170 -0
- package/dist/core/src/stringtable.js.map +1 -0
- package/dist/core/src/tags.d.ts +126 -0
- package/dist/core/src/tags.d.ts.map +1 -0
- package/dist/core/src/tags.js +228 -0
- package/dist/core/src/tags.js.map +1 -0
- package/dist/core/src/typed-arrays.d.ts +124 -0
- package/dist/core/src/typed-arrays.d.ts.map +1 -0
- package/dist/core/src/typed-arrays.js +198 -0
- package/dist/core/src/typed-arrays.js.map +1 -0
- package/dist/core/src/utils.d.ts +11 -0
- package/dist/core/src/utils.d.ts.map +1 -0
- package/dist/core/src/utils.js +26 -0
- package/dist/core/src/utils.js.map +1 -0
- package/dist/core/src/ways.d.ts +101 -0
- package/dist/core/src/ways.d.ts.map +1 -0
- package/dist/core/src/ways.js +336 -0
- package/dist/core/src/ways.js.map +1 -0
- package/dist/core/test/memory.test.d.ts +7 -0
- package/dist/core/test/memory.test.d.ts.map +1 -0
- package/dist/core/test/memory.test.js +29 -0
- package/dist/core/test/memory.test.js.map +1 -0
- package/dist/core/test/mock-osm.d.ts +13 -0
- package/dist/core/test/mock-osm.d.ts.map +1 -0
- package/dist/core/test/mock-osm.js +122 -0
- package/dist/core/test/mock-osm.js.map +1 -0
- package/dist/core/test/tags-search.test.d.ts +2 -0
- package/dist/core/test/tags-search.test.d.ts.map +1 -0
- package/dist/core/test/tags-search.test.js +56 -0
- package/dist/core/test/tags-search.test.js.map +1 -0
- package/dist/core/test/typed-arrays.test.d.ts +2 -0
- package/dist/core/test/typed-arrays.test.d.ts.map +1 -0
- package/dist/core/test/typed-arrays.test.js +102 -0
- package/dist/core/test/typed-arrays.test.js.map +1 -0
- package/dist/osmix/src/extract.d.ts +43 -0
- package/dist/osmix/src/extract.d.ts.map +1 -0
- package/dist/osmix/src/extract.js +156 -0
- package/dist/osmix/src/extract.js.map +1 -0
- package/dist/osmix/src/pbf.d.ts +55 -0
- package/dist/osmix/src/pbf.d.ts.map +1 -0
- package/dist/osmix/src/pbf.js +187 -0
- package/dist/osmix/src/pbf.js.map +1 -0
- package/dist/osmix/src/utils.d.ts +36 -0
- package/dist/osmix/src/utils.d.ts.map +1 -0
- package/dist/osmix/src/utils.js +108 -0
- package/dist/osmix/src/utils.js.map +1 -0
- package/dist/osmix/test/extract.bench.d.ts +2 -0
- package/dist/osmix/test/extract.bench.d.ts.map +1 -0
- package/dist/osmix/test/extract.bench.js +26 -0
- package/dist/osmix/test/extract.bench.js.map +1 -0
- package/dist/osmix/test/extract.test.d.ts +2 -0
- package/dist/osmix/test/extract.test.d.ts.map +1 -0
- package/dist/osmix/test/extract.test.js +392 -0
- package/dist/osmix/test/extract.test.js.map +1 -0
- package/package.json +11 -11
- package/src/entities.ts +138 -22
- package/src/ids.ts +117 -45
- package/src/index.ts +34 -5
- package/src/nodes.ts +237 -58
- package/src/osm.ts +174 -0
- package/src/relations.ts +383 -54
- package/src/stringtable.ts +111 -36
- package/src/tags.ts +207 -46
- package/src/typed-arrays.ts +97 -10
- package/src/types/geoflatbush.d.ts +37 -0
- package/src/types/geokdbush.d.ts +37 -0
- package/src/types/kdbush.d.ts +24 -6
- package/src/utils.ts +9 -14
- package/src/ways.ts +248 -84
- package/test/memory.test.ts +38 -0
- package/test/mock-osm.ts +8 -8
- package/test/tags-search.test.ts +60 -0
- package/test/typed-arrays.test.ts +5 -6
- package/tsconfig.json +7 -1
- package/src/osmix.ts +0 -556
- package/test/extract.bench.ts +0 -29
- package/test/extract.test.ts +0 -156
- package/test/read.test.ts +0 -22
- package/test/write.test.ts +0 -66
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ID storage and lookup for OSM entities.
|
|
3
|
+
*
|
|
4
|
+
* Uses a two-level binary search (anchor array + block search) to map 64-bit OSM IDs
|
|
5
|
+
* to internal array indices. Balances memory usage with O(log n) lookup speed.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { type BufferType } from "./typed-arrays";
|
|
10
|
+
/**
|
|
11
|
+
* Union type for looking up entities by either OSM ID or internal array index.
|
|
12
|
+
*/
|
|
13
|
+
export type IdOrIndex = {
|
|
14
|
+
id: number;
|
|
15
|
+
} | {
|
|
16
|
+
index: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Serializable state for worker transfer.
|
|
20
|
+
*/
|
|
21
|
+
export interface IdsTransferables<T extends BufferType = BufferType> {
|
|
22
|
+
/** Entity IDs in insertion order. */
|
|
23
|
+
ids: T;
|
|
24
|
+
/** Sorted IDs for binary search (aliases `ids` if already sorted). */
|
|
25
|
+
sortedIds: T;
|
|
26
|
+
/** Maps sorted position → original insertion index. */
|
|
27
|
+
sortedIdPositionToIndex: T;
|
|
28
|
+
/** Anchor array: every BLOCK_SIZE-th sorted ID. */
|
|
29
|
+
anchors: T;
|
|
30
|
+
/** True if IDs were inserted in ascending order. */
|
|
31
|
+
idsAreSorted: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Efficiently store and lookup OSM entity IDs.
|
|
35
|
+
*
|
|
36
|
+
* Stores 64-bit IDs in a Float64Array and maintains a sorted index for O(log n) lookups.
|
|
37
|
+
* Max capacity: ~2^32 entities.
|
|
38
|
+
*/
|
|
39
|
+
export declare class Ids {
|
|
40
|
+
/** All IDs in insertion order */
|
|
41
|
+
private ids;
|
|
42
|
+
/** Whether buildIndex() has been called */
|
|
43
|
+
private indexBuilt;
|
|
44
|
+
/** True if IDs were added in ascending order (allows index optimization) */
|
|
45
|
+
private idsAreSorted;
|
|
46
|
+
/** Sorted view of IDs for binary search */
|
|
47
|
+
private idsSorted;
|
|
48
|
+
/** Maps position in sorted array → original insertion index */
|
|
49
|
+
private sortedIdPositionToIndex;
|
|
50
|
+
/** Anchor array for two-level binary search: every BLOCK_SIZE-th sorted ID */
|
|
51
|
+
private anchors;
|
|
52
|
+
/**
|
|
53
|
+
* Create a new Ids index.
|
|
54
|
+
* @param transferables - Optional serialized state to reconstruct from.
|
|
55
|
+
*/
|
|
56
|
+
constructor(transferables?: IdsTransferables);
|
|
57
|
+
/** Number of IDs stored in this index. */
|
|
58
|
+
get size(): number;
|
|
59
|
+
/** Returns true if buildIndex() has been called and lookups are enabled. */
|
|
60
|
+
isReady(): boolean;
|
|
61
|
+
/** Returns true if IDs were inserted in ascending order. */
|
|
62
|
+
isSorted(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Add an ID to the index.
|
|
65
|
+
* @param id - The OSM entity ID to add.
|
|
66
|
+
* @returns The internal array index where this ID was stored.
|
|
67
|
+
* @throws If the index has already been built.
|
|
68
|
+
*/
|
|
69
|
+
add(id: number): number;
|
|
70
|
+
/**
|
|
71
|
+
* Get the ID at a specific internal index.
|
|
72
|
+
* @param index - The internal array index.
|
|
73
|
+
* @returns The OSM entity ID at that index.
|
|
74
|
+
*/
|
|
75
|
+
at(index: number): number;
|
|
76
|
+
/**
|
|
77
|
+
* Check if an ID exists in this index.
|
|
78
|
+
* @param id - The OSM entity ID to check.
|
|
79
|
+
* @returns True if the ID exists in this index.
|
|
80
|
+
*/
|
|
81
|
+
has(id: number): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Build the index of IDs to positions.
|
|
84
|
+
*
|
|
85
|
+
* If the IDs are not sorted, we need to sort them and build a new index.
|
|
86
|
+
* If the IDs are sorted, we can use the existing index.
|
|
87
|
+
*/
|
|
88
|
+
buildIndex(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Look up the internal array index for an OSM entity ID.
|
|
91
|
+
*
|
|
92
|
+
* @param id - The OSM entity ID to look up.
|
|
93
|
+
* @returns The internal array index, or -1 if not found.
|
|
94
|
+
* @throws If the index has not been built.
|
|
95
|
+
*/
|
|
96
|
+
getIndexFromId(id: number): number;
|
|
97
|
+
/**
|
|
98
|
+
* Pass an ID or an index, get both.
|
|
99
|
+
*/
|
|
100
|
+
idOrIndex(i: IdOrIndex): [index: number, id: number];
|
|
101
|
+
/** Returns the sorted array of IDs for iteration. */
|
|
102
|
+
get sorted(): Float64Array<ArrayBufferLike>;
|
|
103
|
+
/**
|
|
104
|
+
* Get transferable buffers for passing to another thread.
|
|
105
|
+
* @returns Serializable representation of this index.
|
|
106
|
+
*/
|
|
107
|
+
transferables(): IdsTransferables;
|
|
108
|
+
/**
|
|
109
|
+
* Get the approximate memory requirements for a given number of IDs in bytes.
|
|
110
|
+
*/
|
|
111
|
+
static getBytesRequired(count: number): number;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../../src/ids.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cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAqClC;;OAEG;IACH,SAAS,CAAC,CAAC,EAAE,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC;IAKpD,qDAAqD;IACrD,IAAI,MAAM,kCAET;IAED;;;OAGG;IACH,aAAa,IAAI,gBAAgB;IAUjC;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,MAAM;CASrC"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ID storage and lookup for OSM entities.
|
|
3
|
+
*
|
|
4
|
+
* Uses a two-level binary search (anchor array + block search) to map 64-bit OSM IDs
|
|
5
|
+
* to internal array indices. Balances memory usage with O(log n) lookup speed.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { assertValue } from "@osmix/shared/assert";
|
|
10
|
+
import { BufferConstructor, ResizeableTypedArray as RTA, } from "./typed-arrays";
|
|
11
|
+
/**
|
|
12
|
+
* Number of IDs per anchor block for the two-level binary search.
|
|
13
|
+
* Smaller values increase anchor array size but speed up block-level search;
|
|
14
|
+
* larger values reduce anchor overhead but slow the final search.
|
|
15
|
+
*/
|
|
16
|
+
const BLOCK_SIZE = 256;
|
|
17
|
+
/**
|
|
18
|
+
* Efficiently store and lookup OSM entity IDs.
|
|
19
|
+
*
|
|
20
|
+
* Stores 64-bit IDs in a Float64Array and maintains a sorted index for O(log n) lookups.
|
|
21
|
+
* Max capacity: ~2^32 entities.
|
|
22
|
+
*/
|
|
23
|
+
export class Ids {
|
|
24
|
+
/** All IDs in insertion order */
|
|
25
|
+
ids;
|
|
26
|
+
/** Whether buildIndex() has been called */
|
|
27
|
+
indexBuilt = false;
|
|
28
|
+
/** True if IDs were added in ascending order (allows index optimization) */
|
|
29
|
+
idsAreSorted = true;
|
|
30
|
+
/** Sorted view of IDs for binary search */
|
|
31
|
+
idsSorted;
|
|
32
|
+
/** Maps position in sorted array → original insertion index */
|
|
33
|
+
sortedIdPositionToIndex;
|
|
34
|
+
/** Anchor array for two-level binary search: every BLOCK_SIZE-th sorted ID */
|
|
35
|
+
anchors;
|
|
36
|
+
/**
|
|
37
|
+
* Create a new Ids index.
|
|
38
|
+
* @param transferables - Optional serialized state to reconstruct from.
|
|
39
|
+
*/
|
|
40
|
+
constructor(transferables) {
|
|
41
|
+
if (transferables) {
|
|
42
|
+
this.ids = RTA.from(Float64Array, transferables.ids);
|
|
43
|
+
this.idsSorted = new Float64Array(transferables.sortedIds);
|
|
44
|
+
this.sortedIdPositionToIndex = new Uint32Array(transferables.sortedIdPositionToIndex);
|
|
45
|
+
this.anchors = new Float64Array(transferables.anchors);
|
|
46
|
+
this.idsAreSorted = transferables.idsAreSorted;
|
|
47
|
+
this.indexBuilt = true;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.ids = new RTA(Float64Array);
|
|
51
|
+
this.idsSorted = new Float64Array(new BufferConstructor(0));
|
|
52
|
+
this.sortedIdPositionToIndex = new Uint32Array(new BufferConstructor(0));
|
|
53
|
+
this.anchors = new Float64Array(new BufferConstructor(0));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Number of IDs stored in this index. */
|
|
57
|
+
get size() {
|
|
58
|
+
return this.ids.length;
|
|
59
|
+
}
|
|
60
|
+
/** Returns true if buildIndex() has been called and lookups are enabled. */
|
|
61
|
+
isReady() {
|
|
62
|
+
return this.indexBuilt;
|
|
63
|
+
}
|
|
64
|
+
/** Returns true if IDs were inserted in ascending order. */
|
|
65
|
+
isSorted() {
|
|
66
|
+
return this.idsAreSorted;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Add an ID to the index.
|
|
70
|
+
* @param id - The OSM entity ID to add.
|
|
71
|
+
* @returns The internal array index where this ID was stored.
|
|
72
|
+
* @throws If the index has already been built.
|
|
73
|
+
*/
|
|
74
|
+
add(id) {
|
|
75
|
+
if (this.indexBuilt)
|
|
76
|
+
throw Error("ID index already built.");
|
|
77
|
+
if (this.ids.length > 0 && id < this.ids.at(-1))
|
|
78
|
+
this.idsAreSorted = false;
|
|
79
|
+
return this.ids.push(id);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the ID at a specific internal index.
|
|
83
|
+
* @param index - The internal array index.
|
|
84
|
+
* @returns The OSM entity ID at that index.
|
|
85
|
+
*/
|
|
86
|
+
at(index) {
|
|
87
|
+
return this.ids.at(index);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check if an ID exists in this index.
|
|
91
|
+
* @param id - The OSM entity ID to check.
|
|
92
|
+
* @returns True if the ID exists in this index.
|
|
93
|
+
*/
|
|
94
|
+
has(id) {
|
|
95
|
+
return this.getIndexFromId(id) !== -1;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Build the index of IDs to positions.
|
|
99
|
+
*
|
|
100
|
+
* If the IDs are not sorted, we need to sort them and build a new index.
|
|
101
|
+
* If the IDs are sorted, we can use the existing index.
|
|
102
|
+
*/
|
|
103
|
+
buildIndex() {
|
|
104
|
+
if (this.indexBuilt)
|
|
105
|
+
throw Error("ID index already build.");
|
|
106
|
+
this.ids.compact();
|
|
107
|
+
if (!this.idsAreSorted) {
|
|
108
|
+
console.warn("IDs were not sorted. Sorting now...");
|
|
109
|
+
// Build the sorted index
|
|
110
|
+
const idsBuffer = new BufferConstructor(this.size * Float64Array.BYTES_PER_ELEMENT);
|
|
111
|
+
const posBuffer = new BufferConstructor(this.size * Uint32Array.BYTES_PER_ELEMENT);
|
|
112
|
+
this.idsSorted = new Float64Array(idsBuffer);
|
|
113
|
+
this.sortedIdPositionToIndex = new Uint32Array(posBuffer);
|
|
114
|
+
// Fill and sort with positions.
|
|
115
|
+
for (let i = 0; i < this.size; i++) {
|
|
116
|
+
this.idsSorted[i] = this.ids.at(i);
|
|
117
|
+
this.sortedIdPositionToIndex[i] = i;
|
|
118
|
+
}
|
|
119
|
+
// Sort by id, carrying position; use native sort on chunks or a custom radix/merge for stability.
|
|
120
|
+
// For simplicity:
|
|
121
|
+
const tmp = Array.from({ length: this.size }, (_, i) => ({
|
|
122
|
+
id: this.idsSorted[i],
|
|
123
|
+
pos: this.sortedIdPositionToIndex[i],
|
|
124
|
+
}));
|
|
125
|
+
tmp.sort((a, b) => a.id - b.id);
|
|
126
|
+
tmp.forEach(({ id, pos }, i) => {
|
|
127
|
+
this.idsSorted[i] = id;
|
|
128
|
+
this.sortedIdPositionToIndex[i] = pos;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
// Point to the same array
|
|
133
|
+
this.idsSorted = this.ids.array;
|
|
134
|
+
// Create the sortedIdPositionToIndex array
|
|
135
|
+
const posBuffer = new BufferConstructor(this.size * Uint32Array.BYTES_PER_ELEMENT);
|
|
136
|
+
this.sortedIdPositionToIndex = new Uint32Array(posBuffer);
|
|
137
|
+
for (let i = 0; i < this.size; i++) {
|
|
138
|
+
this.sortedIdPositionToIndex[i] = i;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Build anchors (every blockSize-th key)
|
|
142
|
+
const aLen = Math.ceil(this.size / BLOCK_SIZE);
|
|
143
|
+
const sab = new BufferConstructor(aLen * Float64Array.BYTES_PER_ELEMENT);
|
|
144
|
+
this.anchors = new Float64Array(sab, 0, aLen);
|
|
145
|
+
for (let j = 0; j < aLen; j++) {
|
|
146
|
+
const id = this.idsSorted[Math.min(j * BLOCK_SIZE, this.size - 1)];
|
|
147
|
+
assertValue(id, "ID is undefined");
|
|
148
|
+
this.anchors[j] = id;
|
|
149
|
+
}
|
|
150
|
+
this.indexBuilt = true;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Look up the internal array index for an OSM entity ID.
|
|
154
|
+
*
|
|
155
|
+
* @param id - The OSM entity ID to look up.
|
|
156
|
+
* @returns The internal array index, or -1 if not found.
|
|
157
|
+
* @throws If the index has not been built.
|
|
158
|
+
*/
|
|
159
|
+
getIndexFromId(id) {
|
|
160
|
+
if (!this.indexBuilt)
|
|
161
|
+
throw Error("IdIndex not built.");
|
|
162
|
+
// binary search anchors
|
|
163
|
+
let lo = 0;
|
|
164
|
+
let hi = this.anchors.length - 1;
|
|
165
|
+
while (lo < hi) {
|
|
166
|
+
const mid = (lo + hi + 1) >>> 1;
|
|
167
|
+
const anchor = this.anchors[mid];
|
|
168
|
+
assertValue(anchor, "Anchor is undefined");
|
|
169
|
+
if (anchor <= id)
|
|
170
|
+
lo = mid;
|
|
171
|
+
else
|
|
172
|
+
hi = mid - 1;
|
|
173
|
+
}
|
|
174
|
+
const start = lo * BLOCK_SIZE;
|
|
175
|
+
const end = Math.min(start + BLOCK_SIZE, this.idsSorted.length);
|
|
176
|
+
// binary search within block
|
|
177
|
+
let l = start;
|
|
178
|
+
let r = end - 1;
|
|
179
|
+
while (l <= r) {
|
|
180
|
+
const m = (l + r) >>> 1;
|
|
181
|
+
const v = this.idsSorted[m];
|
|
182
|
+
assertValue(v, "Value is undefined");
|
|
183
|
+
if (v === id) {
|
|
184
|
+
if (this.idsAreSorted)
|
|
185
|
+
return m;
|
|
186
|
+
const index = this.sortedIdPositionToIndex[m];
|
|
187
|
+
assertValue(index, "Position is undefined");
|
|
188
|
+
return index;
|
|
189
|
+
}
|
|
190
|
+
if (v < id)
|
|
191
|
+
l = m + 1;
|
|
192
|
+
else
|
|
193
|
+
r = m - 1;
|
|
194
|
+
}
|
|
195
|
+
// ID not found
|
|
196
|
+
return -1;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Pass an ID or an index, get both.
|
|
200
|
+
*/
|
|
201
|
+
idOrIndex(i) {
|
|
202
|
+
if ("id" in i)
|
|
203
|
+
return [this.getIndexFromId(i.id), i.id];
|
|
204
|
+
return [i.index, this.at(i.index)];
|
|
205
|
+
}
|
|
206
|
+
/** Returns the sorted array of IDs for iteration. */
|
|
207
|
+
get sorted() {
|
|
208
|
+
return this.idsSorted;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Get transferable buffers for passing to another thread.
|
|
212
|
+
* @returns Serializable representation of this index.
|
|
213
|
+
*/
|
|
214
|
+
transferables() {
|
|
215
|
+
return {
|
|
216
|
+
ids: this.ids.array.buffer,
|
|
217
|
+
sortedIds: this.idsSorted.buffer,
|
|
218
|
+
sortedIdPositionToIndex: this.sortedIdPositionToIndex.buffer,
|
|
219
|
+
anchors: this.anchors.buffer,
|
|
220
|
+
idsAreSorted: this.idsAreSorted,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get the approximate memory requirements for a given number of IDs in bytes.
|
|
225
|
+
*/
|
|
226
|
+
static getBytesRequired(count) {
|
|
227
|
+
if (count === 0)
|
|
228
|
+
return 0;
|
|
229
|
+
return (count * Float64Array.BYTES_PER_ELEMENT + // ids
|
|
230
|
+
count * Float64Array.BYTES_PER_ELEMENT + // sortedIds
|
|
231
|
+
count * Uint32Array.BYTES_PER_ELEMENT + // sortedIdPositionToIndex
|
|
232
|
+
Math.ceil(count / BLOCK_SIZE) * Float64Array.BYTES_PER_ELEMENT // anchors
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../../../src/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EACN,iBAAiB,EAEjB,oBAAoB,IAAI,GAAG,GAC3B,MAAM,gBAAgB,CAAA;AAOvB;;;;GAIG;AACH,MAAM,UAAU,GAAG,GAAG,CAAA;AAkBtB;;;;;GAKG;AACH,MAAM,OAAO,GAAG;IACf,iCAAiC;IACzB,GAAG,CAAmB;IAC9B,2CAA2C;IACnC,UAAU,GAAG,KAAK,CAAA;IAC1B,4EAA4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;IACH,SAAS,CAAC,CAAY;QACrB,IAAI,IAAI,IAAI,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;QACvD,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;IACnC,CAAC;IAED,qDAAqD;IACrD,IAAI,MAAM;QACT,OAAO,IAAI,CAAC,SAAS,CAAA;IACtB,CAAC;IAED;;;OAGG;IACH,aAAa;QACZ,OAAO;YACN,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM;YAC1B,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM;YAChC,uBAAuB,EAAE,IAAI,CAAC,uBAAuB,CAAC,MAAM;YAC5D,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;YAC5B,YAAY,EAAE,IAAI,CAAC,YAAY;SAC/B,CAAA;IACF,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,KAAa;QACpC,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,CAAC,CAAA;QACzB,OAAO,CACN,KAAK,GAAG,YAAY,CAAC,iBAAiB,GAAG,MAAM;YAC/C,KAAK,GAAG,YAAY,CAAC,iBAAiB,GAAG,YAAY;YACrD,KAAK,GAAG,WAAW,CAAC,iBAAiB,GAAG,0BAA0B;YAClE,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,YAAY,CAAC,iBAAiB,CAAC,UAAU;SACzE,CAAA;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @osmix/core - In-memory OSM entity storage with spatial indexing.
|
|
3
|
+
*
|
|
4
|
+
* Efficiently stores and queries OpenStreetMap entities (nodes, ways, relations).
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - **Memory-efficient**: Uses typed arrays and Int32Array microdegrees.
|
|
8
|
+
* - **Spatial indexing**: KDBush (points) and Flatbush (bboxes) for fast geographic queries.
|
|
9
|
+
* - **Worker-ready**: Zero-copy transfer via `transferables()`.
|
|
10
|
+
* - **Tag indexing**: Fast reverse lookup by tag key.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { Osm } from "@osmix/core"
|
|
15
|
+
* const osm = new Osm({ id: "example" })
|
|
16
|
+
* osm.nodes.addNode({ id: 1, lon: -122.4, lat: 47.6, tags: { name: "Seattle" } })
|
|
17
|
+
* osm.buildIndexes()
|
|
18
|
+
* osm.buildSpatialIndexes()
|
|
19
|
+
* const nearby = osm.nodes.findIndexesWithinRadius(-122.4, 47.6, 10)
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @module @osmix/core
|
|
23
|
+
*/
|
|
24
|
+
export * from "./nodes";
|
|
25
|
+
export * from "./osm";
|
|
26
|
+
export * from "./relations";
|
|
27
|
+
export * from "./stringtable";
|
|
28
|
+
export * from "./tags";
|
|
29
|
+
export { BufferConstructor, type BufferType } from "./typed-arrays";
|
|
30
|
+
export * from "./utils";
|
|
31
|
+
export * from "./ways";
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA;AACrB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,QAAQ,CAAA;AACtB,OAAO,EAAE,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACnE,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @osmix/core - In-memory OSM entity storage with spatial indexing.
|
|
3
|
+
*
|
|
4
|
+
* Efficiently stores and queries OpenStreetMap entities (nodes, ways, relations).
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - **Memory-efficient**: Uses typed arrays and Int32Array microdegrees.
|
|
8
|
+
* - **Spatial indexing**: KDBush (points) and Flatbush (bboxes) for fast geographic queries.
|
|
9
|
+
* - **Worker-ready**: Zero-copy transfer via `transferables()`.
|
|
10
|
+
* - **Tag indexing**: Fast reverse lookup by tag key.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { Osm } from "@osmix/core"
|
|
15
|
+
* const osm = new Osm({ id: "example" })
|
|
16
|
+
* osm.nodes.addNode({ id: 1, lon: -122.4, lat: 47.6, tags: { name: "Seattle" } })
|
|
17
|
+
* osm.buildIndexes()
|
|
18
|
+
* osm.buildSpatialIndexes()
|
|
19
|
+
* const nearby = osm.nodes.findIndexesWithinRadius(-122.4, 47.6, 10)
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @module @osmix/core
|
|
23
|
+
*/
|
|
24
|
+
/// <reference path="./types/kdbush.d.ts" />
|
|
25
|
+
/// <reference path="./types/geokdbush.d.ts" />
|
|
26
|
+
/// <reference path="./types/geoflatbush.d.ts" />
|
|
27
|
+
export * from "./nodes";
|
|
28
|
+
export * from "./osm";
|
|
29
|
+
export * from "./relations";
|
|
30
|
+
export * from "./stringtable";
|
|
31
|
+
export * from "./tags";
|
|
32
|
+
export { BufferConstructor } from "./typed-arrays";
|
|
33
|
+
export * from "./utils"; // TODO Move into shared?
|
|
34
|
+
export * from "./ways";
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,4CAA4C;AAC5C,+CAA+C;AAC/C,iDAAiD;AAEjD,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA;AACrB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,QAAQ,CAAA;AACtB,OAAO,EAAE,iBAAiB,EAAmB,MAAM,gBAAgB,CAAA;AACnE,cAAc,SAAS,CAAA,CAAC,yBAAyB;AACjD,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { OsmPbfBlock, OsmPbfDenseNodes } from "@osmix/pbf";
|
|
2
|
+
import type { GeoBbox2D, OsmNode, OsmTags } from "@osmix/shared/types";
|
|
3
|
+
import { Entities, type EntitiesTransferables } from "./entities";
|
|
4
|
+
import { type IdOrIndex } from "./ids";
|
|
5
|
+
import type StringTable from "./stringtable";
|
|
6
|
+
import { type BufferType } from "./typed-arrays";
|
|
7
|
+
export interface NodesTransferables<T extends BufferType = BufferType> extends EntitiesTransferables<T> {
|
|
8
|
+
lons: T;
|
|
9
|
+
lats: T;
|
|
10
|
+
bbox: GeoBbox2D;
|
|
11
|
+
/** Optional - can be rebuilt via buildSpatialIndex() */
|
|
12
|
+
spatialIndex?: T;
|
|
13
|
+
}
|
|
14
|
+
export interface AddNodeOptions {
|
|
15
|
+
filter?: (node: OsmNode) => boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare class Nodes extends Entities<OsmNode> {
|
|
18
|
+
/**
|
|
19
|
+
* Coordinates are stored as integer microdegrees (Int32Array).
|
|
20
|
+
* Use OSM_COORD_SCALE (1e7) to convert between degrees and microdegrees.
|
|
21
|
+
*/
|
|
22
|
+
private lons;
|
|
23
|
+
private lats;
|
|
24
|
+
private bbox;
|
|
25
|
+
private spatialIndex;
|
|
26
|
+
private spatialIndexBuilt;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new Nodes index.
|
|
29
|
+
*/
|
|
30
|
+
constructor(stringTable: StringTable, transferables?: NodesTransferables);
|
|
31
|
+
/**
|
|
32
|
+
* Add a single node to the index.
|
|
33
|
+
*/
|
|
34
|
+
addNode(node: OsmNode): number;
|
|
35
|
+
/**
|
|
36
|
+
* Add dense nodes from a PBF block.
|
|
37
|
+
*/
|
|
38
|
+
addDenseNodes(dense: OsmPbfDenseNodes, block: OsmPbfBlock, blockStringIndexMap: Uint32Array, filter?: (node: OsmNode) => boolean): number;
|
|
39
|
+
/**
|
|
40
|
+
* Compact the internal arrays to free up memory.
|
|
41
|
+
*/
|
|
42
|
+
buildEntityIndex(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Build the spatial index for nodes.
|
|
45
|
+
* Spatial index stores degrees (Float64Array) for geokdbush compatibility.
|
|
46
|
+
*/
|
|
47
|
+
buildSpatialIndex(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Check if the spatial index has been built.
|
|
50
|
+
*/
|
|
51
|
+
hasSpatialIndex(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Get the bounding box of all nodes.
|
|
54
|
+
*/
|
|
55
|
+
getBbox(): GeoBbox2D;
|
|
56
|
+
/**
|
|
57
|
+
* Get the bounding box of a specific node.
|
|
58
|
+
*/
|
|
59
|
+
getEntityBbox(i: IdOrIndex): GeoBbox2D;
|
|
60
|
+
/**
|
|
61
|
+
* Get the longitude and latitude of a specific node.
|
|
62
|
+
*/
|
|
63
|
+
getNodeLonLat(i: IdOrIndex): [number, number];
|
|
64
|
+
/**
|
|
65
|
+
* Get the full node entity.
|
|
66
|
+
*/
|
|
67
|
+
getFullEntity(index: number, id: number, tags?: OsmTags): OsmNode;
|
|
68
|
+
/**
|
|
69
|
+
* Find node indexes within a bounding box.
|
|
70
|
+
*/
|
|
71
|
+
findIndexesWithinBbox(bbox: GeoBbox2D): number[];
|
|
72
|
+
/**
|
|
73
|
+
* Find node indexes within a radius of a point.
|
|
74
|
+
* Uses geokdbush for proper great-circle distance calculations.
|
|
75
|
+
* @param lon - Longitude in degrees.
|
|
76
|
+
* @param lat - Latitude in degrees.
|
|
77
|
+
* @param radiusKm - Radius in kilometers.
|
|
78
|
+
* @returns Array of node indexes within the radius.
|
|
79
|
+
*/
|
|
80
|
+
findIndexesWithinRadius(lon: number, lat: number, radiusKm: number): number[];
|
|
81
|
+
/**
|
|
82
|
+
* Get nodes within a bounding box.
|
|
83
|
+
* @param bbox - The bounding box to search within.
|
|
84
|
+
* @param include - A function to filter nodes. If provided, only nodes for which the function returns true will be included.
|
|
85
|
+
* @returns An object containing the IDs and positions of the nodes within the bounding box.
|
|
86
|
+
*/
|
|
87
|
+
withinBbox(bbox: GeoBbox2D, include?: (i: number) => boolean): {
|
|
88
|
+
ids: Float64Array;
|
|
89
|
+
positions: Float64Array;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Get transferable objects for passing to another thread.
|
|
93
|
+
* Only includes spatialIndex if it has been built.
|
|
94
|
+
*/
|
|
95
|
+
transferables(): NodesTransferables;
|
|
96
|
+
/**
|
|
97
|
+
* Get the approximate memory requirements for a given number of nodes in bytes.
|
|
98
|
+
*/
|
|
99
|
+
static getBytesRequired(count: number): number;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=nodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../../src/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAG/D,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGtE,OAAO,EAAE,QAAQ,EAAE,KAAK,qBAAqB,EAAE,MAAM,YAAY,CAAA;AACjE,OAAO,EAAE,KAAK,SAAS,EAAO,MAAM,OAAO,CAAA;AAC3C,OAAO,KAAK,WAAW,MAAM,eAAe,CAAA;AAE5C,OAAO,EAEN,KAAK,UAAU,EAEf,MAAM,gBAAgB,CAAA;AA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