mirror of
https://github.com/sbrl/terrain50-cli.git
synced 2024-11-29 08:02:59 +00:00
clamp: add new subcommand
This commit is contained in:
parent
c3a42e27cc
commit
4e01ce965d
3 changed files with 62 additions and 0 deletions
|
@ -16,6 +16,7 @@ npm install --save terrain50-cli
|
||||||
|
|
||||||
## v1.9 (unreleased)
|
## v1.9 (unreleased)
|
||||||
- `identify`: Add value range to output
|
- `identify`: Add value range to output
|
||||||
|
- `clamp`: add new subcommand
|
||||||
|
|
||||||
|
|
||||||
## v1.8
|
## v1.8
|
||||||
|
|
36
src/Subcommands/clamp/index.mjs
Normal file
36
src/Subcommands/clamp/index.mjs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
|
import l from '../../Helpers/Log.mjs';
|
||||||
|
import a from '../../Helpers/Ansi.mjs';
|
||||||
|
import Terrain50 from 'terrain50';
|
||||||
|
|
||||||
|
export default async function(settings) {
|
||||||
|
if(typeof settings.cli.input !== "string") {
|
||||||
|
l.error("Error: No input file specified (try --filename path/to/heightmap.asc)");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
if(typeof settings.cli.output !== "string") {
|
||||||
|
l.error("Error: No output file specified (try --filename path/to/output.asc)");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
l.log(`Reading input files`);
|
||||||
|
let heightmap = Terrain50.Parse(await fs.promises.readFile(settings.cli.input, "utf-8"));
|
||||||
|
|
||||||
|
if(typeof settings.cli.min == "number") {
|
||||||
|
l.log(`Clamping values to a minimum of ${a.hicol}${settings.cli.min}${a.reset}`);
|
||||||
|
heightmap.min_value = settings.cli.min;
|
||||||
|
l.log(`done`);
|
||||||
|
}
|
||||||
|
if(typeof settings.cli.max == "number") {
|
||||||
|
l.log(`Clamping values to a maximum of ${a.hicol}${settings.cli.max}${a.reset}`);
|
||||||
|
heightmap.max_value = settings.cli.max;
|
||||||
|
l.log(`done`);
|
||||||
|
}
|
||||||
|
|
||||||
|
l.log(`Writing result to disk`);
|
||||||
|
await heightmap.serialise(fs.createWriteStream(settings.cli.output));
|
||||||
|
l.log(`Trimming complete!`);
|
||||||
|
}
|
25
src/Subcommands/clamp/meta.toml
Normal file
25
src/Subcommands/clamp/meta.toml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
description = "Clamp data values (but not NODATA values) to a given minimum and maximum."
|
||||||
|
|
||||||
|
[[arguments]]
|
||||||
|
name = "input"
|
||||||
|
description = "The input Terrain50 file to operate on"
|
||||||
|
# default_value = ""
|
||||||
|
type = "string"
|
||||||
|
|
||||||
|
[[arguments]]
|
||||||
|
name = "output"
|
||||||
|
description = "The filepath to write the output to"
|
||||||
|
# default_value = ""
|
||||||
|
type = "string"
|
||||||
|
|
||||||
|
[[arguments]]
|
||||||
|
name = "min"
|
||||||
|
description = "The minimum value to clamp to. If not specified, values will not be clamped to a minimum."
|
||||||
|
# default_value = ""
|
||||||
|
type = "float"
|
||||||
|
|
||||||
|
[[arguments]]
|
||||||
|
name = "max"
|
||||||
|
description = "The maximum value to clamp to. If not specified, values will not be clamped to a maximum."
|
||||||
|
# default_value = ""
|
||||||
|
type = "float"
|
Loading…
Reference in a new issue