-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): Create-overview determine max zoom overview from the gsd #2612
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { sha256base58 } from '@basemaps/config'; | ||
import { GoogleTms, NamedBounds, Nztm2000QuadTms, QuadKey, TileMatrixSet } from '@basemaps/geo'; | ||
import { LogConfig, LogType } from '@basemaps/shared'; | ||
import { ChunkSource, SourceMemory } from '@chunkd/core'; | ||
import { LogConfig, LogType, Projection } from '@basemaps/shared'; | ||
import { SourceMemory } from '@chunkd/core'; | ||
import { fsa } from '@chunkd/fs'; | ||
import { CogTiff } from '@cogeotiff/core'; | ||
import { CotarIndexBinary, CotarIndexBuilder, TarReader } from '@cotar/core'; | ||
|
@@ -18,6 +18,7 @@ import { JobTiles, tile } from './tile.generator.js'; | |
import { SimpleTimer } from './timer.js'; | ||
|
||
const DefaultMaxZoom = 15; | ||
const MaxNumberTiles = 250000; | ||
|
||
export class CommandCreateOverview extends CommandLineAction { | ||
private source: CommandLineStringParameter; | ||
|
@@ -39,11 +40,6 @@ export class CommandCreateOverview extends CommandLineAction { | |
description: 'Path of source imagery files', | ||
required: true, | ||
}); | ||
this.maxZoom = this.defineIntegerParameter({ | ||
argumentName: 'MAX_ZOOM', | ||
parameterLongName: '--max-zoom', | ||
description: 'Maximum zoom level for the overview', | ||
}); | ||
this.output = this.defineStringParameter({ | ||
argumentName: 'OUTPUT', | ||
parameterLongName: '--output', | ||
|
@@ -55,20 +51,23 @@ export class CommandCreateOverview extends CommandLineAction { | |
const logger = LogConfig.get(); | ||
const source = this.source.value; | ||
if (source == null) throw new Error('Please provide a path for the source imagery.'); | ||
const maxZoom = this.maxZoom.value ?? DefaultMaxZoom; | ||
|
||
const hash = sha256base58(source); | ||
|
||
logger.info({ source, hash, maxZoom }, 'CreateOverview'); | ||
logger.info({ source, hash }, 'CreateOverview'); | ||
const path = fsa.join('overview', hash); | ||
|
||
const st = new SimpleTimer(); | ||
logger.debug({ source }, 'CreateOverview:ListTiffs'); | ||
const tiffList = (await fsa.toArray(fsa.list(source))).filter(filterTiff); | ||
const tiffSource = tiffList.map((path: string) => fsa.source(path)); | ||
|
||
logger.info({ source, duration: st.tick() }, 'CreateOverview:ListTiffs:Done'); | ||
|
||
logger.debug({ source }, 'CreateOverview:PrepareSourceFiles'); | ||
const tileMatrix = await this.getTileMatrix(tiffSource); | ||
const tiff = await CogTiff.create(tiffSource[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will throw if there are not tiffs, maybe check and exit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should let it die here, but with a nice error message, stack traces are not super helpful to users |
||
const tileMatrix = await this.getTileMatrix(tiff); | ||
const maxZoom = await this.getMaxZoomFromGSD(tiff, tileMatrix); | ||
logger.info({ source, duration: st.tick() }, 'CreateOverview:PrepareSourceFiles:Done'); | ||
|
||
logger.debug({ source }, 'CreateOverview:PrepareCovering'); | ||
|
@@ -115,6 +114,7 @@ export class CommandCreateOverview extends CommandLineAction { | |
qk = QuadKey.parent(qk); | ||
} | ||
} | ||
if (tiles.size > MaxNumberTiles) this.prepareTiles(files, maxZoom - 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also why is this async? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good pick |
||
return tiles; | ||
} | ||
|
||
|
@@ -126,8 +126,7 @@ export class CommandCreateOverview extends CommandLineAction { | |
} | ||
} | ||
|
||
async getTileMatrix(sources: ChunkSource[]): Promise<TileMatrixSet> { | ||
const tiff = await CogTiff.create(sources[0]); | ||
async getTileMatrix(tiff: CogTiff): Promise<TileMatrixSet> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesnt need to be async the tiff is (you are initing the tiff twice) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tiff.init(true) is called in the other function you should pull that out to the same place as the new CogTiff |
||
await tiff.getImage(0).loadGeoTiffTags(); | ||
const projection = tiff.getImage(0).epsg; | ||
if (projection == null) throw new Error('Failed to find the projection from the imagery.'); | ||
|
@@ -136,6 +135,13 @@ export class CommandCreateOverview extends CommandLineAction { | |
else throw new Error(`Projection code: ${projection} not supported`); | ||
} | ||
|
||
async getMaxZoomFromGSD(tiff: CogTiff, tileMatrix: TileMatrixSet): Promise<number> { | ||
await tiff.init(true); | ||
const gsd = tiff.getImage(tiff.images.length - 1).resolution[0]; | ||
const resZoom = Projection.getTiffResZoom(tileMatrix, gsd); | ||
return Math.min(resZoom + 2, DefaultMaxZoom); | ||
} | ||
|
||
async createTar(path: string, logger: LogType): Promise<void> { | ||
const tarFile = 'overviews.tar.co'; | ||
const tarFilePath = fsa.join(path, tarFile); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we add a sentence explaining what these numbers do?