get_version

src/index.mjs

Fetches the current version of terrain50.

get_version(): string
Returns
string: The current version of the terrain50 library.

Represents a single Terrain50 tile.. Note that this does NOT fill it with data - meta or otherwise. It simply creates the necessary data structures to hold such data. See Terrain50.Parse() (a static method) for parsing an serialised Terrain50 string.

new Terrain50(was_blank: any)
Parameters
was_blank (any = false)
Static Members
ValidMetaHeaderKeys
RequiredMetaHeaderKeys
Instance Members
meta
data
was_blank
newline
max_value
min_value
shift(new_min)
replace(old_value, new_value)
round()
trim(meta)
analyse_frequencies(ignore_nodata)
scale(scale_factor)
serialise(stream, do_close)
validate()
to_geojson_feature()

Creates a prefilled blank Terrain50 instance.

terrain50_blank(meta: object): Terrain50
Parameters
meta (object) The metadata of the instance to create. See Terrain50.meta for more information.
Returns
Terrain50: A new blank instance.
Example
import Terrain50 from 'terrain50';
// ....
let new_instance = Terrain50.Blank(some_metadata_here);

Parses a Terrain50 instance from a string. See https://en.wikipedia.org/wiki/Esri_grid for more information on the supported format.

See also Terrain50.Merge() for merging multiple instances (format restrictions apply).

terrain50_parse(str: string): Terrain50
Parameters
str (string) The string to parse
Returns
Terrain50: The parsed string as a Terrain50 object.
Example
import fs from 'fs';
import Terrain50 from 'terrain50';
let new_instance = Terrain50.Parse(fs.readFileSync("path/to/file.asc", "utf-8"));

Parses a Terrain50 instance from a string. See https://en.wikipedia.org/wiki/Esri_grid for more information on the supported format.

See also Terrain50.Merge() for merging multiple instances (format restrictions apply).

terrain50_parse_stream(stream: stream.Readable, values_delimiter: (RegExp | string)): Generator<Terrain50>
Parameters
stream (stream.Readable) The Stream to read and parse from.
values_delimiter ((RegExp | string) = " ") The delimiter to use when parsing data. Default: a string. Set to the regex /\s+/ to improve performance.
Returns
Generator<Terrain50>: A generator that may emit (at least) 1 or more Terrain50 objects. If no data is found, an empty Terrain50 object is returned.
Example
import fs from 'fs';
import Terrain50 from 'terrain50';
let input_stream = fs.createReadStream("path/to/multiple.asc", "utf-8")
for await (let next of Terrain50.ParseStream(input_stream)) {
	console.log(next);
}
Using a regex delimiter
// Warning: Using a regex decreases performance.
for await (let next  of Terrain50.ParseStream(some_stream, /\s+/)) {
	console.log(next);
}

Merges multiple Terrain50 instances. Note that they MUST be a rectangle overall. Gaps in tiles are filled in though.

Note also that all tiles MUST be the same height and width. Expect odd results if they aren't!

In addition, all cells MUST have an identical pixel size (cellsize).

NODATA_value MUST NOT be present in any input files. If it is, then it will be ignored and a different value used instead!

terrain50_merge(tiles: Terrain50): Terrain50
Parameters
tiles (Terrain50) The tiles to merge
Returns
Terrain50: 1 big Terrain50 instance representing all of the input instances.
Example

Basic usage

import Terrain50 from 'terrain50';
// ....
let new_instance = Terrain50.Merge(
	instance1,
	instance2
	//, instanceN
);

Using the spread operator

// ....
let big = Terrain50.Merge(...array_of_terrain50_instances);

Checks a Terrain50 string for errors. Possible error messages:

Code Meaning
TE001 Invalid number of elements on metadata header line
TE002 Found unexpected metadata header line after X rows of data
TE003 Data rows have differing numbers of columns
TE004 Required metadata header not found
TE005 Actual row count does not match metadata
TE006 Actual column count does not match metadata
TE007 No data rows detected
TE008 Seen more than 1 column count
TW001 Unknown metadata header key
TW002 Invalid metadata header value
terrain50_validate(str: string): Array<Terrain50ValidationMessage>
Parameters
str (string) The source string to check.
Returns
Array<Terrain50ValidationMessage>: A list of validation errors (if any) found.
Example
import fs from 'fs';
import Terrain50 from 'terrain50';
let errors = Terrain50.Validate(fs.readFileSync("path/to/file.asc", "utf-8"));

terrain50_analyse_frequencies

src/static/Terrain50AnalyseFrequencies.mjs

Return a map of the frequencies of the data values in 1 or more Terrain50 instances.

terrain50_analyse_frequencies(input: (Terrain50 | Generator<Promise<Terrain50>>), ignore_nodata: boolean, quiet: any): Promise<Map>
Parameters
input ((Terrain50 | Generator<Promise<Terrain50>>)) The input Terrain50 instance to analyse, or an async generator to read from (e.g. the one returned buy Terrain50.ParseStream())
ignore_nodata (boolean) Whether to ignore NODATA values (default: false)
quiet (any = false)
Returns
Promise<Map>: A key → value map of frequencies in the form Math.floor(data_value) → number of occurrencies
Related
my_terrain50_instance.analyse_frequencies() The instance method which underpins this static one Terrain50.ParseStream() Works great with this function
Example
Single instance
let map = await Terrain50.AnalyseFrequencies(my_terrain50_instance);
// The above is equivalent to this:
let map = await my_terrain50_instance.analyse_frequencies();
"Combining with Terrain50.ParseStream"
let map = await Terrain50.AnalyseFrequencies(Terrain50.ParseStream(some_stream)));