calcAsciiGridBoundingBox

Calculate the bounding box of the ASCII Grid using fast but imprecise floating-point arithmetic. For a slower, but more precise bounding box calculation, use calcAsciiGridPreciseBoundingBox.

calcAsciiGridBoundingBox
Parameters
data ((ArrayBuffer | Buffer | String)) your ASCII grid data
debug_level (Number = 0) 0 prevents all logging, 1+ logging to help debugging
max_read_length (Number = Infinity) how much to read of the ASCII grid file
meta (Object?) metadata object from parseAsciiGridMeta
Returns
Array<Number>: bounding box in numerical format [xmin, ymin, xmax, ymax]
Example
import { calcAsciiGridBoundingBox } from "ascii-grid";

calcAsciiGridBoundingBox({
 data: <ArrayBuffer>
});
[491501, 2556440, 594634.0933000001, 2645315.3392]

calcAsciiGridPreciseBoundingBox

Calculate the bounding box of the ASCII Grid using preciso a library for precise mathetmical calculations that avoid float-point arithemtic imprecision. This is the more precise (but slower) version of calcAsciiGridBoundingBox.

calcAsciiGridPreciseBoundingBox
Parameters
data ((ArrayBuffer | Buffer | String)) your ASCII grid data
debug_level (Number = 0) 0 prevents all logging, 1+ logging to help debugging
max_read_length (Number = Infinity) how much to read of the ASCII grid file
meta (Object?) metadata object from parseAsciiGridMeta
Returns
Array<String>: bounding box in numerical string format [xmin, ymin, xmax, ymax]
Example
import { calcAsciiGridPreciseBoundingBox } from "ascii-grid";

calcAsciiGridPreciseBoundingBox({
 data: <ArrayBuffer>
});
["491501", "2556440", "594634.0933", "2645315.3392"]

calcAsciiGridStats

Calculate Statistics for a Given ASCII Grid. Basically runs calc-stats on the data.

calcAsciiGridStats
Parameters
assume_clean (Boolean = true) assume that cell values are valid numbers and don't include null bytes
debug_level (Number = 0) 0 prevents all logging, 1+ logging to help debugging
data ((ArrayBuffer | Buffer | String)) your ASCII grid data
max_read_length (Number = Infinity) how much to read of the ASCII grid file
start_of_data_byte (Number?) where the metadata ends and to start reading the cell values
start_column (Number = 0) which column to start reading from. zero is the furthest left column.
end_column (Number?) at which column to stop reading. defaults to reading to the end of the grid
start_row (Number?) which row to start reading from. zero is the top/first row.
end_row (Number?) which row to stop reading from. defaults to reading through the last row.
meta (Object?) metadata object from parseAsciiGridMeta
calcHistogram (Boolean = true) calculate a histogram of cell values
calcMax (Boolean = true) calculate the maximum of all the valid cell values
calcMean (Boolean = true) calculate the mean of all the valid cell values
calcMedian (Boolean = true) calculate the median of all the valid cell values
calcMin (Boolean = true) calculate the min of all the valid cell values
calcMode (Boolean = true) calculate the most common cell value (ignoring no-data values)
calcMode (Boolean = true) calculate array of the most common cell values (ignoring no-data values)
calcSum (Boolean = true) calculate the sum of all cell values (ignoring no-data values)
Returns
CalcStatsResults: Results object from running calc-stats over the data

countDigits

count the number of digits right of the decimal point for a given numerical string

countDigits
Parameters
n (String) a number as a string
Returns
Number: the number of digits right of the decimal point

forEachAsciiGridPoint

run a callback function on each cell in your ASCII Grid

forEachAsciiGridPoint
Parameters
data ((ArrayBuffer | Buffer | String))
callback (Function) calls this function for each cell with the first param being GridPointInfo
assume_clean (Boolean = true)
cache (Boolean = false)
debug_level (Number = 0)
max_read_length (Number = Infinity)
start_of_data_byte (Number?)
start_column (Number = 0)
end_column (Number?)
start_row (Number = 0)
end_row (Number?)
meta (Object?)
Example
import { forEachAsciiGridPoint } from "ascii-grid";

forEachAsciiGridPoint({
 data: <ArrayBuffer>,
 callback: ({n, c, r }) => {
  console.log(`value "${n}" at row "${r}" and column "${c}"`);
 }
});

getDataLength

gets the length of your ASCII Grid data. If it's a string, return the string length. If it's a typed array, return the length. If it's binary (e.g. ArrayBuffer and Buffer), return the number of bytes,

getDataLength
Parameters
input (Object)
Name Description
input.data (ArrayBuffer | Buffer | String) your data

GridPointInfo

GridPointInfo

Type: Object

Parameters
c (number) the column by zero-index
r (number) the row by zero-index
num (number) the cell value as a number
str (String) the raw string cell value
meta (Object) metadata parsed from the header of the ASCII Grid data

parseAsciiGridData

parseAsciiGridData

writeAsciiGrid

write ASCII-Grid text file (.asc)

writeAsciiGrid
Parameters
data (Array<Number>) a numerical array of cell values. can be provided as one flat array of an array of rows.
ncols ((Number | String)) number of columns of cells
nrows ((Number | String)) number of rows of cells
xllcenter ((Number | String)) x value of center of lower left cell
xllcorner ((Number | String)) x value of lower left corner of lower left cell
yllcenter ((Number | String)) y value of center of lower left cell
yllcorner ((Number | String)) y value of lower left corner of lower left cell
cellsize ((Number | String)) the height and width of the cell in units of the spatial reference system
nodata_value ((Number | String)) the no data value. cells without data should be skipped when visualizing or calculating statistics.
strict (Boolean) if strict, throw an error when necessary metadata is missing
debug_level-null (Boolean) set to 1+ for increased logging
trailing_newline (Boolean) whether to include a newline at the end of the file
fixed_digits (Number) the number of digits after the decimal. default is no rounding. ignores nodata_values. for more explanation of the rounding please see the documentation for JavaScript's toFixed function here