@osmix/gtfs 0.0.3 → 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/dist/gtfs-archive.d.ts +2 -2
- package/dist/gtfs-archive.d.ts.map +1 -1
- package/dist/gtfs-archive.js +17 -11
- package/dist/gtfs-archive.js.map +1 -1
- package/package.json +23 -25
- package/src/gtfs-archive.ts +17 -11
- package/CHANGELOG.md +0 -28
- package/dist/src/from-gtfs.d.ts +0 -76
- package/dist/src/from-gtfs.d.ts.map +0 -1
- package/dist/src/from-gtfs.js +0 -211
- package/dist/src/from-gtfs.js.map +0 -1
- package/dist/src/gtfs-archive.d.ts +0 -71
- package/dist/src/gtfs-archive.d.ts.map +0 -1
- package/dist/src/gtfs-archive.js +0 -102
- package/dist/src/gtfs-archive.js.map +0 -1
- package/dist/src/index.d.ts +0 -39
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -39
- package/dist/src/index.js.map +0 -1
- package/dist/src/types.d.ts +0 -139
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -48
- package/dist/src/types.js.map +0 -1
- package/dist/src/utils.d.ts +0 -25
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/src/utils.js +0 -210
- package/dist/src/utils.js.map +0 -1
- package/dist/test/from-gtfs.test.d.ts +0 -2
- package/dist/test/from-gtfs.test.d.ts.map +0 -1
- package/dist/test/from-gtfs.test.js +0 -389
- package/dist/test/from-gtfs.test.js.map +0 -1
- package/dist/test/helpers.d.ts +0 -14
- package/dist/test/helpers.d.ts.map +0 -1
- package/dist/test/helpers.js +0 -84
- package/dist/test/helpers.js.map +0 -1
- package/test/from-gtfs.test.ts +0 -516
- package/test/helpers.ts +0 -118
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -9
package/dist/gtfs-archive.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Lazy GTFS archive parser.
|
|
2
|
+
* Lazy GTFS archive parser with streaming CSV support.
|
|
3
3
|
*
|
|
4
4
|
* Only parses CSV files when they are accessed, not upfront.
|
|
5
|
-
* Uses
|
|
5
|
+
* Uses shared CsvParseStream for true line-by-line streaming.
|
|
6
6
|
*
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gtfs-archive.d.ts","sourceRoot":"","sources":["../src/gtfs-archive.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EACX,UAAU,EACV,SAAS,EACT,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"gtfs-archive.d.ts","sourceRoot":"","sources":["../src/gtfs-archive.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EACX,UAAU,EACV,SAAS,EACT,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,MAAM,SAAS,CAAA;AAGhB;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,YAAY,EAAE,UAAU,CAAA;IACxB,WAAW,EAAE,QAAQ,CAAA;IACrB,YAAY,EAAE,SAAS,CAAA;IACvB,WAAW,EAAE,QAAQ,CAAA;IACrB,gBAAgB,EAAE,YAAY,CAAA;IAC9B,YAAY,EAAE,cAAc,CAAA;CAC5B;AAED,+CAA+C;AAC/C,MAAM,MAAM,YAAY,GAAG,MAAM,eAAe,CAAA;AAEhD;;;;;;GAMG;AACH,qBAAa,WAAW;IACvB,OAAO,CAAC,OAAO,CAAsB;IAErC,OAAO;IAIP;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,UAAU,GAAG,WAAW;IAiB9D;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIlC;;OAEG;IACH,SAAS,IAAI,MAAM,EAAE;IAIrB;;OAEG;YACW,YAAY;IAQ1B;;;;;;;;;;;;;;;;;;OAkBG;IACI,IAAI,CAAC,CAAC,SAAS,YAAY,EACjC,QAAQ,EAAE,CAAC,GACT,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC;CAoBpD"}
|
package/dist/gtfs-archive.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Lazy GTFS archive parser.
|
|
2
|
+
* Lazy GTFS archive parser with streaming CSV support.
|
|
3
3
|
*
|
|
4
4
|
* Only parses CSV files when they are accessed, not upfront.
|
|
5
|
-
* Uses
|
|
5
|
+
* Uses shared CsvParseStream for true line-by-line streaming.
|
|
6
6
|
*
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { CsvParseStream } from "@osmix/shared/csv-parse-stream";
|
|
10
10
|
import { unzip } from "but-unzip";
|
|
11
|
+
import { bytesToTextStream } from "./utils";
|
|
11
12
|
/**
|
|
12
13
|
* Lazy GTFS archive that only parses files on demand.
|
|
13
14
|
*
|
|
@@ -81,14 +82,19 @@ export class GtfsArchive {
|
|
|
81
82
|
const bytes = await this.getFileBytes(filename);
|
|
82
83
|
if (!bytes)
|
|
83
84
|
return;
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
const textStream = bytesToTextStream(bytes);
|
|
86
|
+
const csvStream = textStream.pipeThrough(new CsvParseStream({ skipFirstRow: true }));
|
|
87
|
+
const reader = csvStream.getReader();
|
|
88
|
+
try {
|
|
89
|
+
while (true) {
|
|
90
|
+
const { value, done } = await reader.read();
|
|
91
|
+
if (done)
|
|
92
|
+
break;
|
|
93
|
+
yield value;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
reader.releaseLock();
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
100
|
}
|
package/dist/gtfs-archive.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gtfs-archive.js","sourceRoot":"","sources":["../src/gtfs-archive.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"gtfs-archive.js","sourceRoot":"","sources":["../src/gtfs-archive.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EAAE,KAAK,EAAgB,MAAM,WAAW,CAAA;AAS/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAiB3C;;;;;;GAMG;AACH,MAAM,OAAO,WAAW;IACf,OAAO,CAAsB;IAErC,YAAoB,OAA6B;QAChD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACvB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,OAAiC;QAC/C,MAAM,KAAK,GACV,OAAO,YAAY,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;QAClE,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;QAE1B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAmB,CAAA;QAC1C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAC1B,gDAAgD;YAChD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;YAC/C,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC3B,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;YACxB,CAAC;QACF,CAAC;QAED,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;IAChC,CAAC;IAED;;OAEG;IACH,OA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;IACF,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -2,26 +2,11 @@
|
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@osmix/gtfs",
|
|
4
4
|
"description": "Convert GTFS transit feeds to OSM format.",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.6",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"types": "./src/index.ts",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
9
8
|
"publishConfig": {
|
|
10
|
-
"access": "public"
|
|
11
|
-
"registry": "https://registry.npmjs.org/",
|
|
12
|
-
"main": "./dist/index.js",
|
|
13
|
-
"types": "./dist/index.d.ts",
|
|
14
|
-
"exports": {
|
|
15
|
-
".": {
|
|
16
|
-
"import": "./dist/index.js",
|
|
17
|
-
"types": "./dist/index.d.ts"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"files": [
|
|
21
|
-
"dist",
|
|
22
|
-
"README.md",
|
|
23
|
-
"LICENSE"
|
|
24
|
-
]
|
|
9
|
+
"access": "public"
|
|
25
10
|
},
|
|
26
11
|
"license": "MIT",
|
|
27
12
|
"repository": {
|
|
@@ -42,14 +27,27 @@
|
|
|
42
27
|
"typecheck": "tsgo --noEmit"
|
|
43
28
|
},
|
|
44
29
|
"devDependencies": {
|
|
45
|
-
"@types/bun": "
|
|
30
|
+
"@types/bun": "catalog:",
|
|
46
31
|
"fflate": "^0.8.2",
|
|
47
|
-
"typescript": "
|
|
32
|
+
"typescript": "catalog:"
|
|
48
33
|
},
|
|
49
34
|
"dependencies": {
|
|
50
|
-
"@osmix/core": "
|
|
51
|
-
"@osmix/shared": "
|
|
52
|
-
"but-unzip": "^0.1.7"
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
"@osmix/core": "workspace:*",
|
|
36
|
+
"@osmix/shared": "workspace:*",
|
|
37
|
+
"but-unzip": "^0.1.7"
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./src/index.ts",
|
|
42
|
+
"bun": "./src/index.ts",
|
|
43
|
+
"development|production": "./src/index.ts",
|
|
44
|
+
"default": "./dist/index.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist",
|
|
49
|
+
"src",
|
|
50
|
+
"README.md",
|
|
51
|
+
"LICENSE"
|
|
52
|
+
]
|
|
55
53
|
}
|
package/src/gtfs-archive.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Lazy GTFS archive parser.
|
|
2
|
+
* Lazy GTFS archive parser with streaming CSV support.
|
|
3
3
|
*
|
|
4
4
|
* Only parses CSV files when they are accessed, not upfront.
|
|
5
|
-
* Uses
|
|
5
|
+
* Uses shared CsvParseStream for true line-by-line streaming.
|
|
6
6
|
*
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { CsvParseStream } from "@osmix/shared/csv-parse-stream"
|
|
11
11
|
import { unzip, type ZipItem } from "but-unzip"
|
|
12
12
|
import type {
|
|
13
13
|
GtfsAgency,
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
GtfsStopTime,
|
|
18
18
|
GtfsTrip,
|
|
19
19
|
} from "./types"
|
|
20
|
+
import { bytesToTextStream } from "./utils"
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Map of GTFS filenames to their record types.
|
|
@@ -117,15 +118,20 @@ export class GtfsArchive {
|
|
|
117
118
|
const bytes = await this.getFileBytes(filename)
|
|
118
119
|
if (!bytes) return
|
|
119
120
|
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
skip_empty_lines: true,
|
|
125
|
-
})
|
|
121
|
+
const textStream = bytesToTextStream(bytes)
|
|
122
|
+
const csvStream = textStream.pipeThrough(
|
|
123
|
+
new CsvParseStream({ skipFirstRow: true }),
|
|
124
|
+
)
|
|
126
125
|
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
const reader = csvStream.getReader()
|
|
127
|
+
try {
|
|
128
|
+
while (true) {
|
|
129
|
+
const { value, done } = await reader.read()
|
|
130
|
+
if (done) break
|
|
131
|
+
yield value as unknown as GtfsFileTypeMap[F]
|
|
132
|
+
}
|
|
133
|
+
} finally {
|
|
134
|
+
reader.releaseLock()
|
|
129
135
|
}
|
|
130
136
|
}
|
|
131
137
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# @osmix/gtfs
|
|
2
|
-
|
|
3
|
-
## 0.0.3
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- f468db5: Fix publishing (2)
|
|
8
|
-
- 536a3cd: Remove JSR dependency for CSV parsing
|
|
9
|
-
- Updated dependencies [f468db5]
|
|
10
|
-
- @osmix/core@0.1.3
|
|
11
|
-
- @osmix/shared@0.0.8
|
|
12
|
-
|
|
13
|
-
## 0.0.2
|
|
14
|
-
|
|
15
|
-
### Patch Changes
|
|
16
|
-
|
|
17
|
-
- 68d6bd8: Fix publishing for packages.
|
|
18
|
-
- Updated dependencies [68d6bd8]
|
|
19
|
-
- @osmix/core@0.1.2
|
|
20
|
-
- @osmix/shared@0.0.7
|
|
21
|
-
|
|
22
|
-
## 0.0.1
|
|
23
|
-
|
|
24
|
-
### Added
|
|
25
|
-
|
|
26
|
-
- Initial release with GTFS to OSM conversion.
|
|
27
|
-
- Stops parsed as nodes with tags.
|
|
28
|
-
- Routes parsed as ways with shape geometry.
|
package/dist/src/from-gtfs.d.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GTFS to OSM conversion utilities.
|
|
3
|
-
*
|
|
4
|
-
* Imports GTFS transit feeds into Osm indexes, mapping:
|
|
5
|
-
* - Stops → Nodes with transit tags
|
|
6
|
-
* - Routes → Ways with shape geometry
|
|
7
|
-
*
|
|
8
|
-
* Uses lazy, on-demand parsing - files are only parsed when needed.
|
|
9
|
-
*
|
|
10
|
-
* @module
|
|
11
|
-
*/
|
|
12
|
-
import { Osm, type OsmOptions } from "@osmix/core";
|
|
13
|
-
import { type ProgressEvent } from "@osmix/shared/progress";
|
|
14
|
-
import { GtfsArchive } from "./gtfs-archive";
|
|
15
|
-
import type { GtfsConversionOptions } from "./types";
|
|
16
|
-
/**
|
|
17
|
-
* Create an Osm index from a zipped GTFS file.
|
|
18
|
-
*
|
|
19
|
-
* Parses the GTFS zip lazily - only reading files when needed.
|
|
20
|
-
* Converts stops and routes to OSM entities:
|
|
21
|
-
* - Stops become nodes with transit-related tags
|
|
22
|
-
* - Routes become ways with shape geometry (if available) or stop sequence
|
|
23
|
-
*
|
|
24
|
-
* @param zipData - The GTFS zip file as ArrayBuffer or Uint8Array
|
|
25
|
-
* @param options - Osm index options (id, header)
|
|
26
|
-
* @param gtfsOptions - GTFS conversion options
|
|
27
|
-
* @param onProgress - Progress callback for UI feedback
|
|
28
|
-
* @returns Populated Osm index with built indexes
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* import { fromGtfs } from "@osmix/gtfs"
|
|
33
|
-
*
|
|
34
|
-
* const response = await fetch("https://example.com/gtfs.zip")
|
|
35
|
-
* const zipData = await response.arrayBuffer()
|
|
36
|
-
* const osm = await fromGtfs(zipData, { id: "transit" })
|
|
37
|
-
*
|
|
38
|
-
* console.log(`Imported ${osm.nodes.size} stops`)
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare function fromGtfs(zipData: ArrayBuffer | Uint8Array, options?: Partial<OsmOptions>, gtfsOptions?: GtfsConversionOptions, onProgress?: (progress: ProgressEvent) => void): Promise<Osm>;
|
|
42
|
-
/**
|
|
43
|
-
* Builder class for converting GTFS data to OSM entities.
|
|
44
|
-
*
|
|
45
|
-
* Uses lazy parsing - only reads GTFS files when needed.
|
|
46
|
-
*/
|
|
47
|
-
export declare class GtfsOsmBuilder {
|
|
48
|
-
private osm;
|
|
49
|
-
private onProgress;
|
|
50
|
-
private nextNodeId;
|
|
51
|
-
private nextWayId;
|
|
52
|
-
private stopIdToNodeId;
|
|
53
|
-
constructor(osmOptions?: Partial<OsmOptions>, onProgress?: (progress: ProgressEvent) => void);
|
|
54
|
-
/**
|
|
55
|
-
* Process GTFS stops into OSM nodes.
|
|
56
|
-
* Uses streaming iteration to avoid loading all stops at once.
|
|
57
|
-
*/
|
|
58
|
-
processStops(archive: GtfsArchive): Promise<void>;
|
|
59
|
-
/**
|
|
60
|
-
* Process GTFS routes into OSM ways.
|
|
61
|
-
* Creates one way per unique (shape_id, route_id) pair, so each route gets
|
|
62
|
-
* its own way with correct metadata even when routes share the same shape.
|
|
63
|
-
*
|
|
64
|
-
* @param archive - The GTFS archive
|
|
65
|
-
*/
|
|
66
|
-
processRoutes(archive: GtfsArchive): Promise<void>;
|
|
67
|
-
/**
|
|
68
|
-
* Create a way from shape points.
|
|
69
|
-
*/
|
|
70
|
-
private createWayFromShape;
|
|
71
|
-
/**
|
|
72
|
-
* Build the OSM index with all entities.
|
|
73
|
-
*/
|
|
74
|
-
buildOsm(): Osm;
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=from-gtfs.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"from-gtfs.d.ts","sourceRoot":"","sources":["../../src/from-gtfs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,GAAG,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAEN,KAAK,aAAa,EAElB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,qBAAqB,EAAkB,MAAM,SAAS,CAAA;AAGpE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,QAAQ,CAC7B,OAAO,EAAE,WAAW,GAAG,UAAU,EACjC,OAAO,GAAE,OAAO,CAAC,UAAU,CAAM,EACjC,WAAW,GAAE,qBAA0B,EACvC,UAAU,GAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAkB,GACzD,OAAO,CAAC,GAAG,CAAC,CAad;AAED;;;;GAIG;AACH,qBAAa,cAAc;IAC1B,OAAO,CAAC,GAAG,CAAK;IAChB,OAAO,CAAC,UAAU,CAAmC;IAErD,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,SAAS,CAAK;IAGtB,OAAO,CAAC,cAAc,CAA4B;gBAGjD,UAAU,GAAE,OAAO,CAAC,UAAU,CAAM,EACpC,UAAU,GAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAkB;IAM5D;;;OAGG;IACG,YAAY,CAAC,OAAO,EAAE,WAAW;IAgCvC;;;;;;OAMG;IACG,aAAa,CAAC,OAAO,EAAE,WAAW;IAmFxC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA6B1B;;OAEG;IACH,QAAQ,IAAI,GAAG;CAMf"}
|
package/dist/src/from-gtfs.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GTFS to OSM conversion utilities.
|
|
3
|
-
*
|
|
4
|
-
* Imports GTFS transit feeds into Osm indexes, mapping:
|
|
5
|
-
* - Stops → Nodes with transit tags
|
|
6
|
-
* - Routes → Ways with shape geometry
|
|
7
|
-
*
|
|
8
|
-
* Uses lazy, on-demand parsing - files are only parsed when needed.
|
|
9
|
-
*
|
|
10
|
-
* @module
|
|
11
|
-
*/
|
|
12
|
-
import { Osm } from "@osmix/core";
|
|
13
|
-
import { logProgress, progressEvent, } from "@osmix/shared/progress";
|
|
14
|
-
import { GtfsArchive } from "./gtfs-archive";
|
|
15
|
-
import { routeToTags, stopToTags } from "./utils";
|
|
16
|
-
/**
|
|
17
|
-
* Create an Osm index from a zipped GTFS file.
|
|
18
|
-
*
|
|
19
|
-
* Parses the GTFS zip lazily - only reading files when needed.
|
|
20
|
-
* Converts stops and routes to OSM entities:
|
|
21
|
-
* - Stops become nodes with transit-related tags
|
|
22
|
-
* - Routes become ways with shape geometry (if available) or stop sequence
|
|
23
|
-
*
|
|
24
|
-
* @param zipData - The GTFS zip file as ArrayBuffer or Uint8Array
|
|
25
|
-
* @param options - Osm index options (id, header)
|
|
26
|
-
* @param gtfsOptions - GTFS conversion options
|
|
27
|
-
* @param onProgress - Progress callback for UI feedback
|
|
28
|
-
* @returns Populated Osm index with built indexes
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* import { fromGtfs } from "@osmix/gtfs"
|
|
33
|
-
*
|
|
34
|
-
* const response = await fetch("https://example.com/gtfs.zip")
|
|
35
|
-
* const zipData = await response.arrayBuffer()
|
|
36
|
-
* const osm = await fromGtfs(zipData, { id: "transit" })
|
|
37
|
-
*
|
|
38
|
-
* console.log(`Imported ${osm.nodes.size} stops`)
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export async function fromGtfs(zipData, options = {}, gtfsOptions = {}, onProgress = logProgress) {
|
|
42
|
-
onProgress(progressEvent("Opening GTFS archive..."));
|
|
43
|
-
const archive = GtfsArchive.fromZip(zipData);
|
|
44
|
-
const builder = new GtfsOsmBuilder(options, onProgress);
|
|
45
|
-
if (gtfsOptions.includeStops ?? true) {
|
|
46
|
-
await builder.processStops(archive);
|
|
47
|
-
}
|
|
48
|
-
if (gtfsOptions.includeRoutes ?? true) {
|
|
49
|
-
await builder.processRoutes(archive);
|
|
50
|
-
}
|
|
51
|
-
return builder.buildOsm();
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Builder class for converting GTFS data to OSM entities.
|
|
55
|
-
*
|
|
56
|
-
* Uses lazy parsing - only reads GTFS files when needed.
|
|
57
|
-
*/
|
|
58
|
-
export class GtfsOsmBuilder {
|
|
59
|
-
osm;
|
|
60
|
-
onProgress;
|
|
61
|
-
nextNodeId = -1;
|
|
62
|
-
nextWayId = -1;
|
|
63
|
-
// Map GTFS stop_id to OSM node ID
|
|
64
|
-
stopIdToNodeId = new Map();
|
|
65
|
-
constructor(osmOptions = {}, onProgress = logProgress) {
|
|
66
|
-
this.osm = new Osm(osmOptions);
|
|
67
|
-
this.onProgress = onProgress;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Process GTFS stops into OSM nodes.
|
|
71
|
-
* Uses streaming iteration to avoid loading all stops at once.
|
|
72
|
-
*/
|
|
73
|
-
async processStops(archive) {
|
|
74
|
-
let count = 0;
|
|
75
|
-
this.onProgress(progressEvent("Processing stops..."));
|
|
76
|
-
for await (const stop of archive.iter("stops.txt")) {
|
|
77
|
-
const lat = Number.parseFloat(stop.stop_lat);
|
|
78
|
-
const lon = Number.parseFloat(stop.stop_lon);
|
|
79
|
-
if (Number.isNaN(lat) || Number.isNaN(lon))
|
|
80
|
-
continue;
|
|
81
|
-
const tags = stopToTags(stop);
|
|
82
|
-
const nodeId = this.nextNodeId--;
|
|
83
|
-
this.osm.nodes.addNode({
|
|
84
|
-
id: nodeId,
|
|
85
|
-
lat,
|
|
86
|
-
lon,
|
|
87
|
-
tags,
|
|
88
|
-
});
|
|
89
|
-
this.stopIdToNodeId.set(stop.stop_id, nodeId);
|
|
90
|
-
count++;
|
|
91
|
-
if (count % 1000 === 0) {
|
|
92
|
-
this.onProgress(progressEvent(`Processed ${count} stops...`));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
this.onProgress(progressEvent(`Added ${count} stops as nodes`));
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Process GTFS routes into OSM ways.
|
|
99
|
-
* Creates one way per unique (shape_id, route_id) pair, so each route gets
|
|
100
|
-
* its own way with correct metadata even when routes share the same shape.
|
|
101
|
-
*
|
|
102
|
-
* @param archive - The GTFS archive
|
|
103
|
-
*/
|
|
104
|
-
async processRoutes(archive) {
|
|
105
|
-
this.onProgress(progressEvent("Processing routes..."));
|
|
106
|
-
// Build shape lookup if shapes exist
|
|
107
|
-
const shapeMap = new Map();
|
|
108
|
-
if (archive.hasFile("shapes.txt")) {
|
|
109
|
-
this.onProgress(progressEvent("Loading shape data..."));
|
|
110
|
-
for await (const point of archive.iter("shapes.txt")) {
|
|
111
|
-
const points = shapeMap.get(point.shape_id) ?? [];
|
|
112
|
-
points.push(point);
|
|
113
|
-
shapeMap.set(point.shape_id, points);
|
|
114
|
-
}
|
|
115
|
-
// Sort each shape by sequence
|
|
116
|
-
for (const points of shapeMap.values()) {
|
|
117
|
-
points.sort((a, b) => Number.parseInt(a.shape_pt_sequence, 10) -
|
|
118
|
-
Number.parseInt(b.shape_pt_sequence, 10));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
throw Error("No shape data found. Cannot process routes.");
|
|
123
|
-
}
|
|
124
|
-
// Group trips by (shape_id, route_id) to ensure each route gets its own way
|
|
125
|
-
// even when multiple routes share the same shape geometry
|
|
126
|
-
const shapeRouteToTrips = new Map();
|
|
127
|
-
this.onProgress(progressEvent("Loading trip data..."));
|
|
128
|
-
for await (const trip of archive.iter("trips.txt")) {
|
|
129
|
-
if (!trip.shape_id)
|
|
130
|
-
continue;
|
|
131
|
-
const key = `${trip.shape_id}:${trip.route_id}`;
|
|
132
|
-
const existing = shapeRouteToTrips.get(key);
|
|
133
|
-
if (existing) {
|
|
134
|
-
existing.tripIds.push(trip.trip_id);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
shapeRouteToTrips.set(key, { tripIds: [trip.trip_id] });
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
// Load routes into a map for lookup
|
|
141
|
-
const routeMap = new Map();
|
|
142
|
-
for await (const route of archive.iter("routes.txt")) {
|
|
143
|
-
routeMap.set(route.route_id, routeToTags(route));
|
|
144
|
-
}
|
|
145
|
-
// Process unique (shape, route) pairs - one way per combination
|
|
146
|
-
let count = 0;
|
|
147
|
-
for (const [key, { tripIds }] of shapeRouteToTrips) {
|
|
148
|
-
const [shapeId, routeId] = key.split(":");
|
|
149
|
-
const routeTags = routeMap.get(routeId);
|
|
150
|
-
if (!routeTags)
|
|
151
|
-
continue;
|
|
152
|
-
const shapePoints = shapeMap.get(shapeId);
|
|
153
|
-
if (!shapePoints || shapePoints.length < 2) {
|
|
154
|
-
this.onProgress(progressEvent(`No shape data found for shape ${shapeId}`, "error"));
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
// Build tags with route info and all trip IDs for this route
|
|
158
|
-
const tags = {
|
|
159
|
-
...routeTags,
|
|
160
|
-
"gtfs:shape_id": shapeId,
|
|
161
|
-
"gtfs:trip_ids": tripIds.join(";"),
|
|
162
|
-
"gtfs:trip_count": tripIds.length,
|
|
163
|
-
};
|
|
164
|
-
// Create way from shape points
|
|
165
|
-
this.createWayFromShape(tags, shapePoints);
|
|
166
|
-
count++;
|
|
167
|
-
if (count % 100 === 0) {
|
|
168
|
-
this.onProgress(progressEvent(`Processed ${count} shape-route pairs...`));
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
this.onProgress(progressEvent(`Added ${count} shape-route pairs as ways`));
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Create a way from shape points.
|
|
175
|
-
*/
|
|
176
|
-
createWayFromShape(tags, shapePoints) {
|
|
177
|
-
const nodeRefs = [];
|
|
178
|
-
for (const point of shapePoints) {
|
|
179
|
-
const lat = Number.parseFloat(point.shape_pt_lat);
|
|
180
|
-
const lon = Number.parseFloat(point.shape_pt_lon);
|
|
181
|
-
if (Number.isNaN(lat) || Number.isNaN(lon))
|
|
182
|
-
continue;
|
|
183
|
-
// Create a node for this shape point
|
|
184
|
-
const nodeId = this.nextNodeId--;
|
|
185
|
-
this.osm.nodes.addNode({
|
|
186
|
-
id: nodeId,
|
|
187
|
-
lat,
|
|
188
|
-
lon,
|
|
189
|
-
});
|
|
190
|
-
nodeRefs.push(nodeId);
|
|
191
|
-
}
|
|
192
|
-
if (nodeRefs.length >= 2) {
|
|
193
|
-
const wayId = this.nextWayId--;
|
|
194
|
-
this.osm.ways.addWay({
|
|
195
|
-
id: wayId,
|
|
196
|
-
refs: nodeRefs,
|
|
197
|
-
tags,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Build the OSM index with all entities.
|
|
203
|
-
*/
|
|
204
|
-
buildOsm() {
|
|
205
|
-
this.onProgress(progressEvent("Building indexes..."));
|
|
206
|
-
this.osm.buildIndexes();
|
|
207
|
-
this.osm.buildSpatialIndexes();
|
|
208
|
-
return this.osm;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
//# sourceMappingURL=from-gtfs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"from-gtfs.js","sourceRoot":"","sources":["../../src/from-gtfs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,GAAG,EAAmB,MAAM,aAAa,CAAA;AAClD,OAAO,EACN,WAAW,EAEX,aAAa,GACb,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC7B,OAAiC,EACjC,UAA+B,EAAE,EACjC,cAAqC,EAAE,EACvC,aAAgD,WAAW;IAE3D,UAAU,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC,CAAA;IACpD,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5C,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;IACvD,IAAI,WAAW,CAAC,YAAY,IAAI,IAAI,EAA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accessed, not upfront.
|
|
5
|
-
* Uses @std/csv CsvParseStream for true line-by-line streaming.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import type { GtfsAgency, GtfsRoute, GtfsShapePoint, GtfsStop, GtfsStopTime, GtfsTrip } from "./types";
|
|
10
|
-
/**
|
|
11
|
-
* Map of GTFS filenames to their record types.
|
|
12
|
-
*/
|
|
13
|
-
export interface GtfsFileTypeMap {
|
|
14
|
-
"agency.txt": GtfsAgency;
|
|
15
|
-
"stops.txt": GtfsStop;
|
|
16
|
-
"routes.txt": GtfsRoute;
|
|
17
|
-
"trips.txt": GtfsTrip;
|
|
18
|
-
"stop_times.txt": GtfsStopTime;
|
|
19
|
-
"shapes.txt": GtfsShapePoint;
|
|
20
|
-
}
|
|
21
|
-
/** Valid GTFS filenames that can be parsed. */
|
|
22
|
-
export type GtfsFileName = keyof GtfsFileTypeMap;
|
|
23
|
-
/**
|
|
24
|
-
* Lazy GTFS archive that only parses files on demand.
|
|
25
|
-
*
|
|
26
|
-
* Files are read from the zip and parsed only when their
|
|
27
|
-
* corresponding getter is called for the first time.
|
|
28
|
-
* Streaming iterators parse CSV line-by-line without loading
|
|
29
|
-
* the entire file into memory.
|
|
30
|
-
*/
|
|
31
|
-
export declare class GtfsArchive {
|
|
32
|
-
private entries;
|
|
33
|
-
private constructor();
|
|
34
|
-
/**
|
|
35
|
-
* Create a GtfsArchive from zip data.
|
|
36
|
-
*/
|
|
37
|
-
static fromZip(zipData: ArrayBuffer | Uint8Array): GtfsArchive;
|
|
38
|
-
/**
|
|
39
|
-
* Check if a file exists in the archive.
|
|
40
|
-
*/
|
|
41
|
-
hasFile(filename: string): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* List all files in the archive.
|
|
44
|
-
*/
|
|
45
|
-
listFiles(): string[];
|
|
46
|
-
/**
|
|
47
|
-
* Get a readable stream of bytes for a file.
|
|
48
|
-
*/
|
|
49
|
-
private getFileBytes;
|
|
50
|
-
/**
|
|
51
|
-
* Stream parse a CSV file, yielding typed records one at a time.
|
|
52
|
-
*
|
|
53
|
-
* The return type is automatically inferred based on the filename:
|
|
54
|
-
* - `"stops.txt"` → `AsyncGenerator<GtfsStop>`
|
|
55
|
-
* - `"routes.txt"` → `AsyncGenerator<GtfsRoute>`
|
|
56
|
-
* - `"shapes.txt"` → `AsyncGenerator<GtfsShapePoint>`
|
|
57
|
-
* - etc.
|
|
58
|
-
*
|
|
59
|
-
* @param filename - The GTFS filename to parse (e.g., "stops.txt")
|
|
60
|
-
* @returns An async generator yielding typed records
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* for await (const stop of archive.iter("stops.txt")) {
|
|
65
|
-
* console.log(stop.stop_name) // TypeScript knows this is GtfsStop
|
|
66
|
-
* }
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
iter<F extends GtfsFileName>(filename: F): AsyncGenerator<GtfsFileTypeMap[F], void, unknown>;
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=gtfs-archive.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gtfs-archive.d.ts","sourceRoot":"","sources":["../../src/gtfs-archive.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EACX,UAAU,EACV,SAAS,EACT,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,MAAM,SAAS,CAAA;AAGhB;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,YAAY,EAAE,UAAU,CAAA;IACxB,WAAW,EAAE,QAAQ,CAAA;IACrB,YAAY,EAAE,SAAS,CAAA;IACvB,WAAW,EAAE,QAAQ,CAAA;IACrB,gBAAgB,EAAE,YAAY,CAAA;IAC9B,YAAY,EAAE,cAAc,CAAA;CAC5B;AAED,+CAA+C;AAC/C,MAAM,MAAM,YAAY,GAAG,MAAM,eAAe,CAAA;AAEhD;;;;;;;GAOG;AACH,qBAAa,WAAW;IACvB,OAAO,CAAC,OAAO,CAAsB;IAErC,OAAO;IAIP;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,UAAU,GAAG,WAAW;IAiB9D;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIlC;;OAEG;IACH,SAAS,IAAI,MAAM,EAAE;IAIrB;;OAEG;YACW,YAAY;IAQ1B;;;;;;;;;;;;;;;;;;OAkBG;IACI,IAAI,CAAC,CAAC,SAAS,YAAY,EACjC,QAAQ,EAAE,CAAC,GACT,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC;CAoBpD"}
|