@basemaps/cli 6.35.0 → 6.37.0

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 (94) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +6 -0
  3. package/build/cli/cogify/__tests__/batch.job.test.js +5 -3
  4. package/build/cli/cogify/__tests__/batch.job.test.js.map +1 -1
  5. package/build/cli/cogify/action.cog.d.ts +1 -0
  6. package/build/cli/cogify/action.cog.d.ts.map +1 -1
  7. package/build/cli/cogify/action.cog.js +20 -41
  8. package/build/cli/cogify/action.cog.js.map +1 -1
  9. package/build/cli/cogify/action.job.d.ts +0 -1
  10. package/build/cli/cogify/action.job.d.ts.map +1 -1
  11. package/build/cli/cogify/action.job.js +3 -10
  12. package/build/cli/cogify/action.job.js.map +1 -1
  13. package/build/cli/cogify/action.make.cog.d.ts +5 -0
  14. package/build/cli/cogify/action.make.cog.d.ts.map +1 -1
  15. package/build/cli/cogify/action.make.cog.js +84 -16
  16. package/build/cli/cogify/action.make.cog.js.map +1 -1
  17. package/build/cli/cogify/action.make.cog.pr.d.ts +10 -0
  18. package/build/cli/cogify/action.make.cog.pr.d.ts.map +1 -0
  19. package/build/cli/cogify/action.make.cog.pr.js +54 -0
  20. package/build/cli/cogify/action.make.cog.pr.js.map +1 -0
  21. package/build/cli/cogify/batch.job.js +4 -4
  22. package/build/cli/cogify/batch.job.js.map +1 -1
  23. package/build/cli/config/action.bundle.assets.d.ts +1 -0
  24. package/build/cli/config/action.bundle.assets.d.ts.map +1 -1
  25. package/build/cli/config/action.cog.mapsheet.d.ts +2 -0
  26. package/build/cli/config/action.cog.mapsheet.d.ts.map +1 -1
  27. package/build/cli/config/action.cog.mapsheet.js +18 -0
  28. package/build/cli/config/action.cog.mapsheet.js.map +1 -1
  29. package/build/cli/config/action.imagery.config.d.ts +1 -0
  30. package/build/cli/config/action.imagery.config.d.ts.map +1 -1
  31. package/build/cli/config/action.imagery.config.js +19 -12
  32. package/build/cli/config/action.imagery.config.js.map +1 -1
  33. package/build/cli/config/action.import.d.ts +14 -1
  34. package/build/cli/config/action.import.d.ts.map +1 -1
  35. package/build/cli/config/action.import.js +98 -3
  36. package/build/cli/config/action.import.js.map +1 -1
  37. package/build/cli/github/github.d.ts +48 -0
  38. package/build/cli/github/github.d.ts.map +1 -0
  39. package/build/cli/github/github.js +108 -0
  40. package/build/cli/github/github.js.map +1 -0
  41. package/build/cli/github/make.cog.pr.d.ts +20 -0
  42. package/build/cli/github/make.cog.pr.d.ts.map +1 -0
  43. package/build/cli/github/make.cog.pr.js +98 -0
  44. package/build/cli/github/make.cog.pr.js.map +1 -0
  45. package/build/cli/index.d.ts.map +1 -1
  46. package/build/cli/index.js +4 -0
  47. package/build/cli/index.js.map +1 -1
  48. package/build/cli/overview/action.create.overview.d.ts +17 -0
  49. package/build/cli/overview/action.create.overview.d.ts.map +1 -0
  50. package/build/cli/overview/action.create.overview.js +168 -0
  51. package/build/cli/overview/action.create.overview.js.map +1 -0
  52. package/build/cli/overview/overview.wmts.d.ts +3 -0
  53. package/build/cli/overview/overview.wmts.d.ts.map +1 -0
  54. package/build/cli/overview/overview.wmts.js +31 -0
  55. package/build/cli/overview/overview.wmts.js.map +1 -0
  56. package/build/cli/overview/tile.generator.d.ts +13 -0
  57. package/build/cli/overview/tile.generator.d.ts.map +1 -0
  58. package/build/cli/overview/tile.generator.js +86 -0
  59. package/build/cli/overview/tile.generator.js.map +1 -0
  60. package/build/cli/overview/timer.d.ts +14 -0
  61. package/build/cli/overview/timer.d.ts.map +1 -0
  62. package/build/cli/overview/timer.js +21 -0
  63. package/build/cli/overview/timer.js.map +1 -0
  64. package/build/cog/__tests__/cog.test.js +1 -1
  65. package/build/cog/__tests__/cog.test.js.map +1 -1
  66. package/build/cog/__tests__/cutline.test.js +8 -23
  67. package/build/cog/__tests__/cutline.test.js.map +1 -1
  68. package/build/cog/builder.d.ts +1 -1
  69. package/build/cog/builder.js +2 -2
  70. package/build/cog/cog.stac.job.d.ts +2 -7
  71. package/build/cog/cog.stac.job.d.ts.map +1 -1
  72. package/build/cog/cog.stac.job.js +7 -8
  73. package/build/cog/cog.stac.job.js.map +1 -1
  74. package/build/cog/constants.d.ts +2 -2
  75. package/build/cog/constants.d.ts.map +1 -1
  76. package/build/cog/constants.js +2 -2
  77. package/build/cog/constants.js.map +1 -1
  78. package/build/cog/cutline.d.ts +4 -6
  79. package/build/cog/cutline.d.ts.map +1 -1
  80. package/build/cog/cutline.js +7 -19
  81. package/build/cog/cutline.js.map +1 -1
  82. package/build/cog/job.factory.d.ts +1 -0
  83. package/build/cog/job.factory.d.ts.map +1 -1
  84. package/build/cog/job.factory.js +3 -3
  85. package/build/cog/job.factory.js.map +1 -1
  86. package/build/cog/stac.d.ts +2 -2
  87. package/build/cog/stac.d.ts.map +1 -1
  88. package/build/cog/types.d.ts +0 -1
  89. package/build/cog/types.d.ts.map +1 -1
  90. package/build/gdal/gdal.config.d.ts +1 -1
  91. package/build/gdal/gdal.config.d.ts.map +1 -1
  92. package/build/gdal/gdal.progress.d.ts +1 -0
  93. package/build/gdal/gdal.progress.d.ts.map +1 -1
  94. package/package.json +15 -9
@@ -0,0 +1,108 @@
1
+ import { Env } from '@basemaps/shared';
2
+ import { Octokit } from '@octokit/core';
3
+ import { restEndpointMethods } from '@octokit/plugin-rest-endpoint-methods';
4
+ export const owner = 'linz'; // The Owner of the Github repository
5
+ export const repo = 'basemaps-config'; // Github repository name
6
+ export const base = 'master'; // Base head name of repository
7
+ export class Github {
8
+ constructor(logger) {
9
+ this.isOk = (s) => s >= 200 && s <= 299;
10
+ this.logger = logger;
11
+ const token = Env.get(Env.GitHubToken);
12
+ if (token == null)
13
+ throw new Error('Please set up github token environment variable.');
14
+ this.octokit = restEndpointMethods(new Octokit({ auth: token }));
15
+ }
16
+ /**
17
+ * Get branch by name if exists
18
+ *
19
+ * @returns {ref} github references or the new created branch
20
+ */
21
+ async getBranch(ref) {
22
+ this.logger.info({ ref }, 'GitHub: Get branch');
23
+ try {
24
+ const response = await this.octokit.rest.git.getRef({ owner, repo, ref });
25
+ if (this.isOk(response.status))
26
+ return response.data.object.sha;
27
+ }
28
+ catch (_a) {
29
+ this.logger.info({ ref }, 'GitHub: Brach Not Found');
30
+ return;
31
+ }
32
+ return;
33
+ }
34
+ /**
35
+ * Create a new branch from the latest master branch
36
+ *
37
+ * @returns {ref} github references or the new created branch
38
+ */
39
+ async createBranch(branch, ref) {
40
+ // Get the latest sha from master branch
41
+ const master = await this.octokit.rest.git.getRef({ owner, repo, ref: `heads/${base}` });
42
+ if (!this.isOk(master.status))
43
+ throw new Error('Failed to get master head.');
44
+ const sha = master.data.object.sha;
45
+ // Create new branch from the latest master
46
+ this.logger.info({ branch }, 'GitHub: Create branch');
47
+ const response = await this.octokit.rest.git.createRef({ owner, repo, ref: `refs/${ref}`, sha });
48
+ if (!this.isOk(response.status))
49
+ throw new Error(`Failed to create branch ${branch}.`);
50
+ return sha;
51
+ }
52
+ async createBlobs(content, path) {
53
+ // Create the blobs with the files content
54
+ this.logger.info({ path }, 'GitHub: Create blob');
55
+ const blobRes = await this.octokit.rest.git.createBlob({ owner, repo, content, encoding: 'utf-8' });
56
+ if (!this.isOk(blobRes.status))
57
+ throw new Error(`Failed to create data blob.`);
58
+ const blobSha = blobRes.data.sha;
59
+ return { path, mode: '100644', type: 'blob', sha: blobSha };
60
+ }
61
+ /**
62
+ * Create a file imagery config file into basemaps-config/config/imagery and commit
63
+ */
64
+ async commit(branch, ref, blobs, message, sha) {
65
+ // Create a tree which defines the folder structure
66
+ const treeRes = await this.octokit.rest.git.createTree({ owner, repo, base_tree: sha, tree: blobs });
67
+ if (!this.isOk(treeRes.status))
68
+ throw new Error(`Failed to create tree.`);
69
+ const treeSha = treeRes.data.sha;
70
+ // Create the commit
71
+ const commitRes = await this.octokit.rest.git.createCommit({
72
+ owner,
73
+ repo,
74
+ message,
75
+ parents: [sha],
76
+ tree: treeSha,
77
+ });
78
+ if (!this.isOk(commitRes.status))
79
+ throw new Error(`Failed to create commit.`);
80
+ const commitSha = commitRes.data.sha;
81
+ // Update the reference of your branch to point to the new commit SHA
82
+ const response = await this.octokit.rest.git.updateRef({ owner, repo, ref, sha: commitSha });
83
+ if (!this.isOk(response.status))
84
+ throw new Error(`Failed to update branch ${branch} sha.`);
85
+ }
86
+ /**
87
+ * Create a new pull request from the given branch and return pull request number
88
+ */
89
+ async createPullRequest(branch, title, draft) {
90
+ // Create pull request from the give head
91
+ const response = await this.octokit.rest.pulls.create({ owner, repo, title, head: branch, base, draft });
92
+ if (!this.isOk(response.status))
93
+ throw new Error('Failed to create pull request.');
94
+ this.logger.info({ branch, url: response.data.html_url }, 'GitHub: Create Pull Request');
95
+ return response.data.number;
96
+ }
97
+ /**
98
+ * Update a new pull request from pull request number
99
+ */
100
+ async updatePullRequest(branch, title, pull_number) {
101
+ // Update pull request by given pull_number
102
+ const response = await this.octokit.rest.pulls.update({ owner, repo, pull_number, title, base });
103
+ if (!this.isOk(response.status))
104
+ throw new Error('Failed to update pull request.');
105
+ this.logger.info({ branch, pull_number }, 'GitHub: Update Pull Request');
106
+ }
107
+ }
108
+ //# sourceMappingURL=github.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.js","sourceRoot":"","sources":["../../../src/cli/github/github.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAE5E,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,qCAAqC;AAClE,MAAM,CAAC,MAAM,IAAI,GAAG,iBAAiB,CAAC,CAAC,yBAAyB;AAChE,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,+BAA+B;AAe7D,MAAM,OAAO,MAAM;IAIjB,YAAY,MAAe;QAO3B,SAAI,GAAG,CAAC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MAAc,EAAE,KAAa,EAAE,KAAc;QACnE,yCAAyC;QACzC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACzG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACnF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,6BAA6B,CAAC,CAAC;QACzF,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,iBAAiB,CAAC,MAAc,EAAE,KAAa,EAAE,WAAmB;QACxE,2CAA2C;QAC3C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACjG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACnF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,6BAA6B,CAAC,CAAC;IAC3E,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ import { ConfigLayer, ConfigTileSetRaster } from '@basemaps/config';
2
+ import { LogType } from '@basemaps/shared';
3
+ import { Github } from './github.js';
4
+ export declare class MakeCogGithub extends Github {
5
+ imagery: string;
6
+ constructor(imagery: string, logger: LogType);
7
+ /**
8
+ * Get the master aerial tileset config from the basemaps config repo
9
+ */
10
+ getTileSetConfig(): Promise<ConfigTileSetRaster>;
11
+ /**
12
+ * Prepare and create pull request for the aerial tileset config
13
+ */
14
+ createTileSetPullRequest(layer: ConfigLayer, jira: string | undefined): Promise<number | undefined>;
15
+ /**
16
+ * Prepare aerial tileSet config json
17
+ */
18
+ prepareTileSetConfig(layer: ConfigLayer, tileSet: ConfigTileSetRaster): Promise<ConfigTileSetRaster | undefined>;
19
+ }
20
+ //# sourceMappingURL=make.cog.pr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make.cog.pr.d.ts","sourceRoot":"","sources":["../../../src/cli/github/make.cog.pr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAe,MAAM,aAAa,CAAC;AAElD,qBAAa,aAAc,SAAQ,MAAM;IACvC,OAAO,EAAE,MAAM,CAAC;gBACJ,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;IAK5C;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAYtD;;OAEG;IACG,wBAAwB,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IA4BzG;;OAEG;IACG,oBAAoB,CACxB,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;CAyC5C"}
@@ -0,0 +1,98 @@
1
+ import { Github, owner, repo } from './github.js';
2
+ export class MakeCogGithub extends Github {
3
+ constructor(imagery, logger) {
4
+ super(logger);
5
+ this.imagery = imagery;
6
+ }
7
+ /**
8
+ * Get the master aerial tileset config from the basemaps config repo
9
+ */
10
+ async getTileSetConfig() {
11
+ this.logger.info({ imagery: this.imagery }, 'GitHub: Get the master TileSet config file');
12
+ const path = 'config/tileset/aerial.json';
13
+ const response = await this.octokit.rest.repos.getContent({ owner, repo, path });
14
+ if (!this.isOk(response.status))
15
+ throw new Error('Failed to get aerial TileSet config.');
16
+ if ('content' in response.data) {
17
+ return JSON.parse(Buffer.from(response.data.content, 'base64').toString());
18
+ }
19
+ else {
20
+ throw new Error('Unable to find the content.');
21
+ }
22
+ }
23
+ /**
24
+ * Prepare and create pull request for the aerial tileset config
25
+ */
26
+ async createTileSetPullRequest(layer, jira) {
27
+ // Prepare new aerial tileset config
28
+ const tileSet = await this.getTileSetConfig();
29
+ const newTileSet = await this.prepareTileSetConfig(layer, tileSet);
30
+ // skip pull request if not an urban or rural imagery
31
+ if (newTileSet == null)
32
+ return;
33
+ const branch = `feat/config-${this.imagery}`;
34
+ const ref = `heads/${branch}`;
35
+ // Create branch first
36
+ let sha = await this.getBranch(ref);
37
+ if (sha == null)
38
+ sha = await this.createBranch(branch, ref);
39
+ // Create blob for the tileset config
40
+ const content = JSON.stringify(newTileSet, null, 2) + '\n'; // Add a new line at end to match the prettier.
41
+ const path = `config/tileset/aerial.json`;
42
+ const blob = await this.createBlobs(content, path);
43
+ // commit blobs to tree
44
+ const message = `feat(imagery): Add imagery ${this.imagery} config file.`;
45
+ await this.commit(branch, ref, [blob], message, sha);
46
+ // Create imagery import pull request
47
+ const title = `feat(aerial): Config imagery ${this.imagery} into Aerial Map. ${jira ? jira : ''}`;
48
+ const prNumber = await this.createPullRequest(branch, title, true);
49
+ return prNumber;
50
+ }
51
+ /**
52
+ * Prepare aerial tileSet config json
53
+ */
54
+ async prepareTileSetConfig(layer, tileSet) {
55
+ // Set layer zoom level and add to latest order
56
+ if (layer.name.includes('rural')) {
57
+ layer.minZoom = 13;
58
+ layer.category = 'Rural Aerial Photos';
59
+ for (let i = 0; i < tileSet.layers.length; i++) {
60
+ // Add new layer at the end of rural
61
+ if (tileSet.layers[i].minZoom === 14) {
62
+ tileSet.layers.splice(i, 0, layer);
63
+ break;
64
+ }
65
+ }
66
+ }
67
+ else if (layer.name.includes('urban')) {
68
+ layer.minZoom = 14;
69
+ layer.category = 'Urban Aerial Photos';
70
+ // Add new layer at the end of urban
71
+ for (let i = tileSet.layers.length - 1; i >= 0; i--) {
72
+ if (tileSet.layers[i].name.includes('urban')) {
73
+ tileSet.layers.splice(i + 1, 0, layer);
74
+ break;
75
+ }
76
+ }
77
+ }
78
+ else if (layer.name.includes('satellite')) {
79
+ layer.minZoom = 5;
80
+ layer.category = 'Satellite Imagery';
81
+ // Add new layer at the end of satellite
82
+ for (let i = tileSet.layers.length - 1; i >= 0; i--) {
83
+ if (tileSet.layers[i].name.includes('satellite')) {
84
+ tileSet.layers.splice(i + 1, 0, layer);
85
+ break;
86
+ }
87
+ }
88
+ }
89
+ else {
90
+ // Add new layer at the bottom
91
+ layer.minZoom = 32;
92
+ layer.category = 'New Aerial Photos';
93
+ tileSet.layers.push(layer);
94
+ }
95
+ return tileSet;
96
+ }
97
+ }
98
+ //# sourceMappingURL=make.cog.pr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make.cog.pr.js","sourceRoot":"","sources":["../../../src/cli/github/make.cog.pr.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,OAAO,aAAc,SAAQ,MAAM;IAEvC,YAAY,OAAe,EAAE,MAAe;QAC1C,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB;QACpB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,4CAA4C,CAAC,CAAC;QAC1F,MAAM,IAAI,GAAG,4BAA4B,CAAC;QAC1C,MAAM,QAAQ,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../../src/cli/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,gCAAgC,CAAC;AAYxC,qBAAa,yBAA0B,SAAQ,eAAe;;CAqB7D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,gCAAgC,CAAC;AAcxC,qBAAa,yBAA0B,SAAQ,eAAe;;CAuB7D"}
@@ -2,6 +2,8 @@
2
2
  import { BaseCommandLine } from '@basemaps/shared/build/cli/base.js';
3
3
  import 'source-map-support/register.js';
4
4
  import { CommandCogCreate } from './cogify/action.cog.js';
5
+ import { CommandCreateOverview } from './overview/action.create.overview.js';
6
+ import { CommandCogPullRequest } from './cogify/action.make.cog.pr.js';
5
7
  import { CommandJobCreate } from './cogify/action.job.js';
6
8
  import { CommandMakeCog } from './cogify/action.make.cog.js';
7
9
  import { CommandBundleAssets } from './config/action.bundle.assets.js';
@@ -20,6 +22,8 @@ export class BasemapsConfigCommandLine extends BaseCommandLine {
20
22
  this.addAction(new CommandCogCreate());
21
23
  this.addAction(new CommandJobCreate());
22
24
  this.addAction(new CommandMakeCog());
25
+ this.addAction(new CommandCreateOverview());
26
+ this.addAction(new CommandCogPullRequest());
23
27
  this.addAction(new CommandBundle());
24
28
  this.addAction(new CommandBundleAssets());
25
29
  this.addAction(new CommandImport());
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,C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EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;QAE3C,IAAI,CAAC,SAAS,CAAC,IAAI,cAAc,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,SAAS,CAAC,IAAI,YAAY,EAAE,CAAC,CAAC;QAEnC,IAAI,CAAC,SAAS,CAAC,IAAI,kBAAkB,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ import { NamedBounds, TileMatrixSet } from '@basemaps/geo';
2
+ import { LogType } from '@basemaps/shared';
3
+ import { CogTiff } from '@cogeotiff/core';
4
+ import { CommandLineAction } from '@rushstack/ts-command-line';
5
+ export declare class CommandCreateOverview extends CommandLineAction {
6
+ private source;
7
+ private output;
8
+ constructor();
9
+ protected onDefineParameters(): void;
10
+ onExecute(): Promise<void>;
11
+ prepareTiles(files: NamedBounds[], maxZoom: number): Set<string>;
12
+ addChildren(qk: string, maxZoom: number, tiles: Set<string>): void;
13
+ getTileMatrix(tiff: CogTiff): Promise<TileMatrixSet>;
14
+ getMaxZoomFromGSD(tiff: CogTiff, tileMatrix: TileMatrixSet): number;
15
+ createTar(path: string, logger: LogType): Promise<void>;
16
+ }
17
+ //# sourceMappingURL=action.create.overview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.create.overview.d.ts","sourceRoot":"","sources":["../../../src/cli/overview/action.create.overview.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,WAAW,EAA4B,aAAa,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,EAAa,OAAO,EAAc,MAAM,kBAAkB,CAAC;AAGlE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAA8B,MAAM,4BAA4B,CAAC;AAc3F,qBAAa,qBAAsB,SAAQ,iBAAiB;IAC1D,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,MAAM,CAA6B;;IAU3C,SAAS,CAAC,kBAAkB,IAAI,IAAI;IAc9B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IA6DhC,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAiBhE,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI;IAQ5D,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;IAS1D,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,GAAG,MAAM;IAM7D,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAgC9D"}
@@ -0,0 +1,168 @@
1
+ import { sha256base58 } from '@basemaps/config';
2
+ import { GoogleTms, Nztm2000QuadTms, QuadKey } from '@basemaps/geo';
3
+ import { LogConfig, Projection } from '@basemaps/shared';
4
+ import { SourceMemory } from '@chunkd/core';
5
+ import { fsa } from '@chunkd/fs';
6
+ import { CogTiff } from '@cogeotiff/core';
7
+ import { CotarIndexBinary, CotarIndexBuilder, TarReader } from '@cotar/core';
8
+ import { TarBuilder } from '@cotar/tar';
9
+ import { CommandLineAction } from '@rushstack/ts-command-line';
10
+ import { promises as fs } from 'fs';
11
+ import * as path from 'path';
12
+ import { resolve } from 'path';
13
+ import { CogBuilder } from '../../cog/builder.js';
14
+ import { Cutline } from '../../cog/cutline.js';
15
+ import { filterTiff, MaxConcurrencyDefault } from '../../cog/job.factory.js';
16
+ import { createOverviewWmtsCapabilities } from './overview.wmts.js';
17
+ import { tile } from './tile.generator.js';
18
+ import { SimpleTimer } from './timer.js';
19
+ const DefaultMaxZoom = 15; // Limitation of maximum overview zoom level to create
20
+ const MaxNumberTiles = 250000; // Limitation of maximum number of tiles we can create for overview.
21
+ export class CommandCreateOverview extends CommandLineAction {
22
+ constructor() {
23
+ super({
24
+ actionName: 'create-overview',
25
+ summary: 'Create a overview of imagery',
26
+ documentation: 'Given a s3 path of Basemaps imagery and create a overview of them within a maximum zoom level.',
27
+ });
28
+ }
29
+ onDefineParameters() {
30
+ this.source = this.defineStringParameter({
31
+ argumentName: 'SOURCE',
32
+ parameterLongName: '--source',
33
+ description: 'Path of source imagery files',
34
+ required: true,
35
+ });
36
+ this.output = this.defineStringParameter({
37
+ argumentName: 'OUTPUT',
38
+ parameterLongName: '--output',
39
+ description: 'Path of output tar file',
40
+ });
41
+ }
42
+ async onExecute() {
43
+ const logger = LogConfig.get();
44
+ const source = this.source.value;
45
+ if (source == null)
46
+ throw new Error('Please provide a path for the source imagery.');
47
+ const hash = sha256base58(source);
48
+ logger.info({ source, hash }, 'CreateOverview');
49
+ const path = fsa.join('overview', hash);
50
+ const st = new SimpleTimer();
51
+ logger.debug({ source }, 'CreateOverview:ListTiffs');
52
+ const tiffList = (await fsa.toArray(fsa.list(source))).filter(filterTiff);
53
+ const tiffSource = tiffList.map((path) => fsa.source(path));
54
+ logger.info({ source, duration: st.tick() }, 'CreateOverview:ListTiffs:Done');
55
+ logger.debug({ source }, 'CreateOverview:PrepareSourceFiles');
56
+ let tiff;
57
+ try {
58
+ tiff = await CogTiff.create(tiffSource[0]);
59
+ await tiff.init(true);
60
+ }
61
+ catch (_a) {
62
+ throw new Error(`Source: ${tiffSource[0]} is not a valid tiff file.`);
63
+ }
64
+ const tileMatrix = await this.getTileMatrix(tiff);
65
+ const maxZoom = this.getMaxZoomFromGSD(tiff, tileMatrix);
66
+ await tiff.close();
67
+ logger.info({ source, duration: st.tick() }, 'CreateOverview:PrepareSourceFiles:Done');
68
+ logger.debug({ source }, 'CreateOverview:PrepareCovering');
69
+ const cutline = new Cutline(tileMatrix);
70
+ const builder = new CogBuilder(tileMatrix, MaxConcurrencyDefault, logger);
71
+ const metadata = await builder.build(tiffSource, cutline, 10);
72
+ logger.info({ source, duration: st.tick() }, 'CreateOverview:PrepareCovering:Done');
73
+ logger.debug({ source }, 'CreateOverview:PrepareTiles');
74
+ const tiles = this.prepareTiles(metadata.files, maxZoom);
75
+ if (tiles.size < 1)
76
+ throw new Error('Failed to prepare overviews.');
77
+ logger.info({ source, duration: st.tick() }, 'CreateOverview:PrepareTiles:Done');
78
+ logger.debug({ source }, 'CreateOverview:GenerateTiles');
79
+ const jobTiles = {
80
+ path,
81
+ files: metadata.bounds,
82
+ tileMatrix: tileMatrix.identifier,
83
+ tiles: Array.from(tiles.values()),
84
+ };
85
+ await tile(jobTiles, logger);
86
+ logger.info({ source, duration: st.tick() }, 'CreateOverview:GenerateTiles:Done');
87
+ const wmts = createOverviewWmtsCapabilities(tileMatrix, maxZoom);
88
+ await fsa.write(fsa.join(path, 'WMTSCapabilities.xml'), wmts);
89
+ logger.debug({ source }, 'CreateOverview:CreatingTar');
90
+ await this.createTar(path, logger);
91
+ logger.info({ source, duration: st.tick() }, 'CreateOverview:CreatingTar:Done');
92
+ logger.info({ source, duration: st.total() }, 'CreateOverview:Done');
93
+ }
94
+ prepareTiles(files, maxZoom) {
95
+ const tiles = new Set(['']);
96
+ for (const file of files) {
97
+ const name = file.name;
98
+ const [z, x, y] = path.basename(name).replace('.tiff', '').split('-').map(Number);
99
+ let qk = QuadKey.fromTile({ x, y, z });
100
+ this.addChildren(qk, maxZoom, tiles);
101
+ while (qk.length > 0) {
102
+ if (tiles.has(qk))
103
+ break;
104
+ if (qk.length < maxZoom)
105
+ tiles.add(qk);
106
+ qk = QuadKey.parent(qk);
107
+ }
108
+ }
109
+ if (tiles.size > MaxNumberTiles)
110
+ return this.prepareTiles(files, maxZoom - 1);
111
+ return tiles;
112
+ }
113
+ addChildren(qk, maxZoom, tiles) {
114
+ if (qk.length >= maxZoom)
115
+ return;
116
+ for (const child of QuadKey.children(qk)) {
117
+ tiles.add(child);
118
+ if (child.length < maxZoom)
119
+ this.addChildren(child, maxZoom, tiles);
120
+ }
121
+ }
122
+ async getTileMatrix(tiff) {
123
+ await tiff.getImage(0).loadGeoTiffTags();
124
+ const projection = tiff.getImage(0).epsg;
125
+ if (projection == null)
126
+ throw new Error('Failed to find the projection from the imagery.');
127
+ else if (projection === 2193)
128
+ return Nztm2000QuadTms;
129
+ else if (projection === 3857)
130
+ return GoogleTms;
131
+ else
132
+ throw new Error(`Projection code: ${projection} not supported`);
133
+ }
134
+ getMaxZoomFromGSD(tiff, tileMatrix) {
135
+ const gsd = tiff.getImage(tiff.images.length - 1).resolution[0];
136
+ const resZoom = Projection.getTiffResZoom(tileMatrix, gsd);
137
+ return Math.min(resZoom + 2, DefaultMaxZoom);
138
+ }
139
+ async createTar(path, logger) {
140
+ const tarFile = 'overviews.tar.co';
141
+ const tarFilePath = fsa.join(path, tarFile);
142
+ const targetPath = resolve(path);
143
+ // Create tar file
144
+ const tiles = await fsa.toArray(fsa.list(fsa.join(targetPath, 'tiles/')));
145
+ tiles.push(fsa.join(targetPath, 'WMTSCapabilities.xml'));
146
+ const tarBuilder = new TarBuilder(tarFilePath);
147
+ tiles.sort((a, b) => a.localeCompare(b));
148
+ for (const file of tiles)
149
+ await tarBuilder.write(file.slice(targetPath.length + 1), await fsa.read(file));
150
+ await tarBuilder.close();
151
+ logger.info(tarBuilder.stats, 'CreateOver:TarCreated');
152
+ // Creating tar index
153
+ const fd = await fs.open(tarFilePath, 'r');
154
+ const index = await CotarIndexBuilder.create(fd);
155
+ const indexBinary = await CotarIndexBinary.create(new SourceMemory('index', index.buffer));
156
+ await TarReader.validate(fd, indexBinary);
157
+ await fd.close();
158
+ await fs.appendFile(tarFilePath, index.buffer);
159
+ // Copy the output into s3 location
160
+ const output = this.output.value;
161
+ if (output) {
162
+ const outputFile = fsa.join(output, tarFile);
163
+ logger.info({ target: outputFile }, 'CreateOverview:UploadOutput');
164
+ await fsa.write(outputFile, fsa.stream(tarFilePath));
165
+ }
166
+ }
167
+ }
168
+ //# sourceMappingURL=action.create.overview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.create.overview.js","sourceRoot":"","sources":["../../../src/cli/overview/action.create.overview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAe,eAAe,EAAE,OAAO,EAAiB,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,SAAS,EAAW,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAA8B,MAAM,4BAA4B,CAAC;AAC3F,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAY,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,cAAc,GAAG,EAAE,CAAC,CAAC,sDAAsD;AACjF,MAAM,cAAc,GAAG,MAA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AC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAC3F,MAAM,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;QAC1C,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAE/C,mCAAmC;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QACjC,IAAI,MAAM,EAAE;YACV,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC7C,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,6BAA6B,CAAC,CAAC;YACnE,MAAM,GAAG,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;SACtD;IACH,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ import { TileMatrixSet } from '@basemaps/geo';
2
+ export declare function createOverviewWmtsCapabilities(tileMatrix: TileMatrixSet, maxZoom: number, title?: string): string;
3
+ //# sourceMappingURL=overview.wmts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overview.wmts.d.ts","sourceRoot":"","sources":["../../../src/cli/overview/overview.wmts.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,aAAa,EAAE,MAAM,eAAe,CAAC;AAG3D,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,aAAa,EACzB,OAAO,EAAE,MAAM,EACf,KAAK,SAAoB,GACxB,MAAM,CA4BR"}
@@ -0,0 +1,31 @@
1
+ import { TileSetType } from '@basemaps/config';
2
+ import { ImageFormat } from '@basemaps/geo';
3
+ import { WmtsCapabilities } from '@basemaps/lambda-tiler/build/wmts.capability.js';
4
+ export function createOverviewWmtsCapabilities(tileMatrix, maxZoom, title = 'cotar-overviews') {
5
+ const fakeLayer = { [tileMatrix.projection.code]: '', title, name: 'cotar-overviews' };
6
+ const tileSet = {
7
+ id: 'cotar-overviews',
8
+ name: 'cotar-overviews',
9
+ type: TileSetType.Raster,
10
+ format: ImageFormat.Webp,
11
+ layers: [fakeLayer],
12
+ title,
13
+ };
14
+ const wmts = new WmtsCapabilities({
15
+ tileSet,
16
+ tileMatrix: [tileMatrix],
17
+ formats: [ImageFormat.Webp],
18
+ httpBase: '',
19
+ imagery: new Map(),
20
+ isIndividualLayers: false,
21
+ });
22
+ wmts.maxZoom = maxZoom;
23
+ const nodes = wmts.toVNode();
24
+ const resourceUrl = nodes.find('ResourceURL');
25
+ if (resourceUrl == null)
26
+ throw new Error('Failed to create WMTSCapabilities missing resourceUrl');
27
+ // Overwrite the location of the tiles to the structure used in the overview tar
28
+ resourceUrl.attrs['template'] = '/tiles/{TileMatrix}/{TileCol}/{TileRow}.webp';
29
+ return nodes.toString();
30
+ }
31
+ //# sourceMappingURL=overview.wmts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overview.wmts.js","sourceRoot":"","sources":["../../../src/cli/overview/overview.wmts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,WAAW,EAAiB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iDAAiD,CAAC;AAEnF,MAAM,UAAU,8BAA8B,CAC5C,UAAyB,EACzB,OAAe,EACf,KAAK,GAAG,iBAAiB;IAEzB,MAAM,SAAS,GAAgB,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC;IACpG,MAAM,OAAO,GAAwB;QACnC,EAAE,EAAE,iBAAiB;QACrB,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,WAAW,CAAC,MAAM;QACxB,MAAM,EAAE,WAAW,CAAC,IAAI;QACxB,MAAM,EAAE,CAAC,SAAS,CAAC;QACnB,KAAK;KACN,CAAC;IACF,MAAM,IAAI,GAAG,IAAI,gBAAgB,CAAC;QAChC,OAAO;QACP,UAAU,EAAE,CAAC,UAAU,CAAC;QACxB,OAAO,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC;QAC3B,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,IAAI,GAAG,EAAE;QAClB,kBAAkB,EAAE,KAAK;KAC1B,CAAC,CAAC;IAEH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAEvB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAE7B,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC9C,IAAI,WAAW,IAAI,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAClG,gFAAgF;IAChF,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,8CAA8C,CAAC;IAC/E,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { NamedBounds } from '@basemaps/geo';
2
+ import { LogType } from '@basemaps/shared';
3
+ export interface JobTiles {
4
+ path: string;
5
+ tileMatrix: string;
6
+ tiles: string[];
7
+ files: NamedBounds[];
8
+ }
9
+ export type RpcContract = {
10
+ tile(jobTiles: JobTiles): Promise<void>;
11
+ };
12
+ export declare function tile(jobTiles: JobTiles, logger: LogType): Promise<void>;
13
+ //# sourceMappingURL=tile.generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tile.generator.d.ts","sourceRoot":"","sources":["../../../src/cli/overview/tile.generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EAMZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAuB3C,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,WAAW,EAAE,CAAC;CACtB;AAID,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC,CAAC;AAEF,wBAAsB,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CA2B7E"}
@@ -0,0 +1,86 @@
1
+ import { Bounds, GoogleTms, ImageFormat, Nztm2000QuadTms, Nztm2000Tms, QuadKey, } from '@basemaps/geo';
2
+ import { fsa } from '@chunkd/fs';
3
+ import pLimit from 'p-limit';
4
+ import { CoSources } from '@basemaps/lambda-tiler/build/util/source.cache.js';
5
+ import { Tiler } from '@basemaps/tiler';
6
+ import { TileMakerSharp } from '@basemaps/tiler-sharp';
7
+ import Sharp from 'sharp';
8
+ import { SimpleTimer } from './timer.js';
9
+ const DefaultResizeKernel = { in: 'lanczos3', out: 'lanczos3' };
10
+ const DefaultBackground = { r: 0, g: 0, b: 0, alpha: 0 };
11
+ const TileComposer = new TileMakerSharp(256);
12
+ const tilerNZTM2000Quad = new Tiler(Nztm2000QuadTms);
13
+ const tilerGoogle = new Tiler(GoogleTms);
14
+ function getTiler(tileMatrix) {
15
+ if (tileMatrix === GoogleTms.identifier)
16
+ return { tiler: tilerGoogle, tileMatrix: GoogleTms };
17
+ else if (tileMatrix === Nztm2000QuadTms.identifier || tileMatrix === Nztm2000Tms.identifier)
18
+ return { tiler: tilerNZTM2000Quad, tileMatrix: Nztm2000QuadTms };
19
+ else
20
+ throw new Error(`Invalid Tile Matrix provided ${tileMatrix}`);
21
+ }
22
+ const Q = pLimit(20);
23
+ export async function tile(jobTiles, logger) {
24
+ const timer = new SimpleTimer();
25
+ let count = 0;
26
+ let skipped = 0;
27
+ const todo = jobTiles.tiles.map((qk) => {
28
+ return Q(async () => {
29
+ const tile = QuadKey.toTile(qk);
30
+ count++;
31
+ if (count % 100 === 0) {
32
+ logger.info({ count, total: jobTiles.tiles.length, duration: timer.tick() }, 'Tiles:Progress');
33
+ }
34
+ const outputTile = `tiles/${tile.z}/${tile.x}/${tile.y}.webp`;
35
+ const outputFile = fsa.join(jobTiles.path, outputTile);
36
+ const exists = await fsa.exists(outputFile);
37
+ if (exists) {
38
+ skipped++;
39
+ return;
40
+ }
41
+ const buffer = await getComposedTile(jobTiles, tile);
42
+ if (buffer != null)
43
+ await fsa.write(outputFile, buffer);
44
+ });
45
+ });
46
+ await Promise.all(todo);
47
+ logger.info({ count, skipped, duration: timer.total() }, 'Tiles:Created');
48
+ }
49
+ async function getComposedTile(jobTiles, tile) {
50
+ const files = jobTiles.files;
51
+ const tiffPaths = [];
52
+ const { tiler, tileMatrix } = getTiler(jobTiles.tileMatrix);
53
+ const tileBounds = tileMatrix.tileToSourceBounds(tile);
54
+ for (const c of files) {
55
+ if (!tileBounds.intersects(Bounds.fromJson(c)))
56
+ continue;
57
+ const tiffPath = c.name;
58
+ tiffPaths.push(tiffPath);
59
+ }
60
+ const todoTiffs = [];
61
+ for (const tiffPath of tiffPaths) {
62
+ const tiff = CoSources.getCog(tiffPath);
63
+ todoTiffs.push(tiff);
64
+ }
65
+ const tiffs = await Promise.all(todoTiffs);
66
+ const layers = await tiler.tile(tiffs, tile.x, tile.y, tile.z);
67
+ if (layers.length === 0)
68
+ return;
69
+ const res = await TileComposer.compose({
70
+ layers,
71
+ format: ImageFormat.Webp,
72
+ background: DefaultBackground,
73
+ resizeKernel: DefaultResizeKernel,
74
+ });
75
+ if (res.layers === 0)
76
+ return;
77
+ // Check and skip if the buffer is empty webp
78
+ if (res.buffer.byteLength < 215) {
79
+ const image = Sharp(Buffer.from(res.buffer));
80
+ const stat = await image.stats();
81
+ if (stat.channels[stat.channels.length - 1].max === 0)
82
+ return;
83
+ }
84
+ return res.buffer;
85
+ }
86
+ //# sourceMappingURL=tile.generator.js.map