Skip to content

Commit 0fc9e6b

Browse files
committed
Revert the mbtile file path to string instead of url
1 parent 0ab464c commit 0fc9e6b

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

packages/cli-vector/src/cli/cli.join.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TileMatrixSets } from '@basemaps/geo';
2-
import { fsa, LogType, Url, UrlArrayJsonFile } from '@basemaps/shared';
2+
import { fsa, isArgo, LogType, Url, UrlArrayJsonFile } from '@basemaps/shared';
33
import { CliId, CliInfo } from '@basemaps/shared/build/cli/info.js';
44
import { getLogger, logArguments } from '@basemaps/shared/build/cli/log.js';
55
import { command, option, string } from 'cmd-ts';
@@ -109,7 +109,8 @@ export const JoinCommand = command({
109109
const bucketPath = new URL(`vector/${tileMatrix.projection.code}/`, args.target);
110110
const filePaths = await download(args.fromFile, outputPath, logger);
111111

112-
const outputMbtiles = fsa.toUrl(`${outputPath}/${args.filename}.mbtiles`);
112+
// Mbtiles output path to be string type path to avoid issues with tippecanoe and better-sqlite3
113+
const outputMbtiles = `${outputPath}/${args.filename}.mbtiles`;
113114
logger.info({ files: filePaths.length, outputMbtiles }, 'JoinMbtiles: Start');
114115
await tileJoin(filePaths, outputMbtiles, logger);
115116
logger.info({ files: filePaths.length, outputMbtiles }, 'JoinMbtiles: End');
@@ -130,13 +131,19 @@ export const JoinCommand = command({
130131

131132
// Upload output to s3
132133
logger.info({ target: bucketPath, tileMatrix: tileMatrix.identifier }, 'Upload: Start');
133-
await upload(outputMbtiles, bucketPath, logger);
134+
await upload(fsa.toUrl(outputMbtiles), bucketPath, logger);
134135
await upload(outputCotar, bucketPath, logger);
135136
await upload(outputIndex, bucketPath, logger);
136137
// Upload stac Files
137138
for (const file of stacFiles) {
138139
await upload(file, bucketPath, logger);
139140
}
140141
logger.info({ target: bucketPath, tileMatrix: tileMatrix.identifier }, 'Upload: End');
142+
143+
// Write output target for argo tasks to create pull request
144+
if (isArgo()) {
145+
const target = new URL(`topographic/${CliId}/${args.filename}.tar.co`, bucketPath);
146+
await fsa.write(fsa.toUrl('/tmp/target'), JSON.stringify([target]));
147+
}
141148
},
142149
});

packages/cli-vector/src/transform/mbtiles.to.ttiles.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LogType, urlToString } from '@basemaps/shared';
1+
import { LogType } from '@basemaps/shared';
22
import bs3 from 'better-sqlite3';
33
import { createWriteStream } from 'fs';
44
import * as tar from 'tar-stream';
@@ -17,7 +17,9 @@ export function xyzToPath(x: number | string, y: number | string, z: number | st
1717
export async function* readMbTiles(
1818
fileName: string,
1919
limit = -1,
20+
logger: LogType,
2021
): AsyncGenerator<{ tile: TileTable; index: number; total: number }, null> {
22+
logger.debug({ file: fileName }, 'ReadMbTiles:Start');
2123
const db = bs3(fileName);
2224
let limitQuery = '';
2325
if (limit > 0) limitQuery = 'LIMIT ' + limit;
@@ -27,19 +29,20 @@ export async function* readMbTiles(
2729

2830
let index = 0;
2931
for (const tile of query.iterate()) yield { tile: tile as TileTable, index: index++, total: total as number };
32+
logger.debug({ file: fileName }, 'ReadMbTiles:End');
3033
return null;
3134
}
3235

33-
export async function toTarTiles(input: URL, output: URL, logger: LogType, limit = -1): Promise<void> {
36+
export async function toTarTiles(input: string, output: URL, logger: LogType, limit = -1): Promise<void> {
3437
const packer = tar.pack();
3538
const startTime = Date.now();
3639
let writeCount = 0;
3740
const writeProm = new Promise((resolve) => packer.on('end', resolve));
3841

39-
packer.pipe(createWriteStream(urlToString(output)));
42+
packer.pipe(createWriteStream(output));
4043

4144
let startTileTime = Date.now();
42-
for await (const { tile, index, total } of readMbTiles(input.pathname, limit)) {
45+
for await (const { tile, index, total } of readMbTiles(input, limit, logger)) {
4346
if (index === 0) logger.info({ path: output.href, count: total }, 'Covt.Tar:Start');
4447

4548
const z = tile.zoom_level;

packages/cli-vector/src/transform/tippecanoe.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ export async function tippecanoe(input: URL, output: URL, layer: Layer, logger:
5757
*
5858
* @returns { cmd: string; args: string[] } cmd and arguments for tippecanoe tile-join docker command
5959
*/
60-
export async function tileJoin(inputs: URL[], output: URL, logger: LogType): Promise<void> {
60+
export async function tileJoin(inputs: URL[], output: string, logger: LogType): Promise<void> {
6161
const cmd = Command.create('tile-join');
6262

63-
cmd.mount(dirname(output.pathname));
63+
cmd.mount(dirname(output));
6464

6565
cmd.args.push('-pk');
66-
cmd.args.push('-o', output.pathname);
66+
cmd.args.push('-o', output);
6767
for (const input of inputs) {
6868
if (input.href.endsWith('mbtiles')) {
6969
cmd.mount(dirname(input.pathname));

0 commit comments

Comments
 (0)