fast-osmpbf-js 0.1.2 → 0.1.4
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 +1 -1
- package/bindings-aarch64-apple-darwin/index.darwin-arm64.node +0 -0
- package/bindings-aarch64-unknown-linux-gnu/index.linux-arm64-gnu.node +0 -0
- package/bindings-x86_64-apple-darwin/index.darwin-x64.node +0 -0
- package/bindings-x86_64-pc-windows-msvc/index.win32-x64-msvc.node +0 -0
- package/bindings-x86_64-unknown-linux-gnu/index.linux-x64-gnu.node +0 -0
- package/index.d.ts +28 -0
- package/index.js +45 -10
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ import { JsElementBlock, OsmReader, getTags } from "fast-osmpbf-js"
|
|
|
55
55
|
|
|
56
56
|
const reader = new OsmReader("./scripts/osm-data/germany-latest.osm.pbf")
|
|
57
57
|
const relevantTags = ["addr:city", "addr:postcode", "addr:street", "addr:housenumber"]
|
|
58
|
-
const stream = reader.streamBlocks(relevantTags)
|
|
58
|
+
const stream = reader.streamBlocks(null, relevantTags)
|
|
59
59
|
|
|
60
60
|
async function main() {
|
|
61
61
|
let totalItems = 0
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export declare class AsyncBlockIterator {
|
|
4
|
+
next(): Promise<JsElementBlock | null>
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export declare class OsmReader {
|
|
8
|
+
constructor(path: string)
|
|
9
|
+
streamBlocks(elementFilter?: JsElementFilter | undefined | null, tagFilter?: Array<string> | undefined | null): AsyncBlockIterator
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface JsElementBlock {
|
|
13
|
+
ids: BigInt64Array
|
|
14
|
+
elementType: string
|
|
15
|
+
nodeIds?: [BigInt64Array, Uint32Array]
|
|
16
|
+
latitudes?: Float64Array
|
|
17
|
+
longitudes?: Float64Array
|
|
18
|
+
relationMembers?: [BigInt64Array, Uint8Array, Int32Array, Uint32Array]
|
|
19
|
+
denseTags?: [Uint32Array, Uint32Array, Uint32Array]
|
|
20
|
+
tags?: [Uint32Array, Uint32Array, Uint32Array]
|
|
21
|
+
stringTable: Array<string>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface JsElementFilter {
|
|
25
|
+
nodes: boolean
|
|
26
|
+
ways: boolean
|
|
27
|
+
relations: boolean
|
|
28
|
+
}
|
package/index.js
CHANGED
|
@@ -1,18 +1,59 @@
|
|
|
1
1
|
import { createRequire } from "module"
|
|
2
|
+
import { platform, arch } from "process"
|
|
3
|
+
import { join, dirname } from "path"
|
|
4
|
+
import { fileURLToPath } from "url"
|
|
5
|
+
|
|
2
6
|
const require = createRequire(import.meta.url)
|
|
3
|
-
const
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
8
|
+
|
|
9
|
+
// Map Node.js platform/arch to your binding folder names
|
|
10
|
+
function getBindingPath() {
|
|
11
|
+
const platformMap = {
|
|
12
|
+
darwin: "apple-darwin",
|
|
13
|
+
win32: "pc-windows-msvc",
|
|
14
|
+
linux: "unknown-linux-gnu",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const archMap = {
|
|
18
|
+
x64: "x86_64",
|
|
19
|
+
arm64: "aarch64",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const nodeFileMap = {
|
|
23
|
+
"linux-x64": "index.linux-x64-gnu.node",
|
|
24
|
+
"linux-arm64": "index.linux-arm64-gnu.node",
|
|
25
|
+
"darwin-x64": "index.darwin-x64.node",
|
|
26
|
+
"darwin-arm64": "index.darwin-arm64.node",
|
|
27
|
+
"win32-x64": "index.win32-x64-msvc.node",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const mappedPlatform = platformMap[platform]
|
|
31
|
+
const mappedArch = archMap[arch]
|
|
32
|
+
|
|
33
|
+
if (!mappedPlatform || !mappedArch) {
|
|
34
|
+
throw new Error(`Unsupported platform: ${platform}-${arch}`)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const bindingFolder = `bindings-${mappedArch}-${mappedPlatform}`
|
|
38
|
+
const nodeFile = nodeFileMap[`${platform}-${arch}`]
|
|
39
|
+
|
|
40
|
+
if (!nodeFile) {
|
|
41
|
+
throw new Error(`No binding available for ${platform}-${arch}`)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return join(__dirname, bindingFolder, nodeFile)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const native = require(getBindingPath())
|
|
4
48
|
|
|
5
49
|
export function getTags(block, index) {
|
|
6
50
|
let tags = block.denseTags || block.tags
|
|
7
|
-
|
|
8
51
|
const start = tags[2][index]
|
|
9
52
|
const end = tags[2][index + 1]
|
|
10
53
|
const result = []
|
|
11
|
-
|
|
12
54
|
for (let i = start; i < end; i++) {
|
|
13
55
|
result.push([block.stringTable[tags[0][i]], block.stringTable[tags[1][i]]])
|
|
14
56
|
}
|
|
15
|
-
|
|
16
57
|
return result
|
|
17
58
|
}
|
|
18
59
|
|
|
@@ -20,15 +61,12 @@ export function getNodeIds(block, index) {
|
|
|
20
61
|
if (!block.nodeIds) {
|
|
21
62
|
return []
|
|
22
63
|
}
|
|
23
|
-
|
|
24
64
|
const result = []
|
|
25
65
|
const start = block.nodeIds[1][index]
|
|
26
66
|
const end = block.nodeIds[1][index + 1]
|
|
27
|
-
|
|
28
67
|
for (let i = start; i < end; i++) {
|
|
29
68
|
result.push(block.nodeIds[0][i])
|
|
30
69
|
}
|
|
31
|
-
|
|
32
70
|
return result
|
|
33
71
|
}
|
|
34
72
|
|
|
@@ -36,11 +74,9 @@ export function getRelationMembers(block, index) {
|
|
|
36
74
|
if (!block.relationMembers) {
|
|
37
75
|
return []
|
|
38
76
|
}
|
|
39
|
-
|
|
40
77
|
const result = []
|
|
41
78
|
const start = block.relationMembers[3][index]
|
|
42
79
|
const end = block.relationMembers[3][index + 1]
|
|
43
|
-
|
|
44
80
|
for (let i = start; i < end; i++) {
|
|
45
81
|
result.push({
|
|
46
82
|
id: block.relationMembers[0][i],
|
|
@@ -48,7 +84,6 @@ export function getRelationMembers(block, index) {
|
|
|
48
84
|
role: block.stringTable[block.relationMembers[2][i]],
|
|
49
85
|
})
|
|
50
86
|
}
|
|
51
|
-
|
|
52
87
|
return result
|
|
53
88
|
}
|
|
54
89
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fast-osmpbf-js",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"description": "Node.js bindings for the fast-osmpbf Rust library",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Daniel Steblin",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"index.js",
|
|
14
14
|
"wrapper.d.ts",
|
|
15
|
-
"index.
|
|
16
|
-
"
|
|
15
|
+
"index.d.ts",
|
|
16
|
+
"bindings-*/*.node"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
19
|
"artifacts": "napi artifacts",
|