Home Reference Source Repository

Function

Static Public Summary
public

Adds a basic query() function to the coverage collection object.

public
public
public

asCovJSONDomainType(cov: Coverage): Promise<Coverage>

Tries to transform the given Coverage object into a new one that conforms to one of the CovJSON domain types.

public

asTime(inp: *): *

public

checkCoverage(obj: *)

public

checkDomain(obj: *)

public

ensureClockwisePolygon(rings: Array, isCartesian: boolean)

Modifies the point order of the given polygon rings such that the first ring is ordered clockwise and all others anti-clockwise.

public

fromDomain(domain: Domain): Coverage

Wraps a Domain into a Coverage object by adding dummy parameter and range data.

public

fromXndarray(xndarr: xndarray, options: object): Coverage

Creates a Coverage with a single parameter from an xndarray object.

public

getCategory(parameter: Parameter, val: number): Category

Returns the category of the given parameter corresponding to the encoded integer value.

public

Return the component names of the horizontal CRS of the domain.

public

Return the reference system connection object of the horizontal CRS of the domain, or undefined if none found.

public

getLanguageString(map: object, preferredLanguage: string): string

public

getLanguageTag(map: object, preferredLanguage: string): string

public

Preprocesses an array of polygons to answer the point-in-polygon question efficiently.

public

getProjection(domain: Domain): IProjection

Return a projection object based on the CRS found in the coverage domain.

public

getReferenceObject(domain: *, component: *): *

Return the reference system connection object for the given domain component, or undefined if none exists.

public

Return the index of the value closest to the given number in a sorted array.

public

indicesOfNearest(a: Array<number>, x: number): [lo,hi]

Return the indices of the two neighbors in the sorted array closest to the given number.

public

isCoverage(obj: *): *

public

isDomain(obj: *): *

public

isEllipsoidalCRS(rs: *): *

Return whether the reference system is a CRS in which horizontal position is specified by geodetic latitude and longitude.

public

isISODateAxis(domain: *, axisName: *): *

Returns true if the given axis has ISO8601 date strings as axis values.

public

iterateRange(range: *, fn: *)

Iterate over all range values and run a function for each value.

public

loadProjection(domain: Domain): Promise<IProjection>

Like getProjection but will also try to remotely load a projection definition via the uriproj library.

public

mapRange(cov: Coverage, key: String, fn: Function, dataType: String): Coverage

public

maskByPolygon(cov: Coverage, polygon: Object, axes: array): Promise<Coverage>

Returns a copy of the given Coverage object where the range values which belong to domain areas outside the given polygon are returned as null (no data).

public

minMax(arr: *): *

public

minMaxOfRange(range: Range<number>): [min,max]

Return the minimum/maximum across all range values, ignoring null's.

public

normalizeIndexSubsetConstraints(domain: *, constraints: *): *

After normalization, all constraints are start,stop,step objects.

public

reduceRange(range: Range, callback: function, start: *): *

Apply a reduce function over the range values.

public

renameAxes(cov: Coverage, mapping: Map<String, String>): Coverage

public

reproject(cov: Coverage, refDomain: Domain): Promise<Coverage>

Reproject a coverage.

public

reprojectCoords(pos: *, fromProjection: *, toProjection: *): *

Reprojects coordinates from one projection to another.

public

stringifyUnit(unit: *, language: *): *

Converts a unit object to a human-readable symbol or label, where symbols are preferred.

public

subsetByBbox(cov: Coverage, bbox: array, axes: array): Promise<Coverage>

Returns a copy of the grid coverage subsetted to the given bounding box.

public

subsetByIndex(cov: *, constraints: *): *

Generic subsetByIndex function that can be used when building new Coverage objects.

public

subsetByValue(cov: *, constraints: *): *

Generic subsetByValue function that can be used when building new Coverage objects.

public

subsetDomainByIndex(domain: *, constraints: *): *

public

withCategories(cov: Coverage, key: String, observedProperty: object, mapping: Map<String, String>): Coverage

Returns a copy of the given Coverage object with the categories of a given parameter replaced by the supplied ones and the encoding adapted to the given mapping from old to new.

public

withDerivedParameter(cov: *, options: *): *

public

withDomainType(cov: Coverage, domainType: String): Coverage

Returns a new coverage where the domainType field of the coverage and the domain is set to the given one.

public

withParameters(cov: *, params: *): *

Returns a copy of the given Coverage object with the parameters replaced by the supplied ones.

public

withSimpleDerivedParameter(cov: *, options: *): *

Static Public

public addCollectionQueryFunction(collection: *) source

import {addCollectionQueryFunction} from 'covutils/'

Adds a basic query() function to the coverage collection object. Note that this does not support paging.

Params:

NameTypeAttributeDescription
collection *

public addLoadRangesFunction(cov: *) source

import {addLoadRangesFunction} from 'covutils/'

Params:

NameTypeAttributeDescription
cov *

public addSubsetFunctions(cov: *) source

import {addSubsetFunctions} from 'covutils/'

Params:

NameTypeAttributeDescription
cov *

public asCovJSONDomainType(cov: Coverage): Promise<Coverage> source

import {asCovJSONDomainType} from 'covutils/'

Tries to transform the given Coverage object into a new one that conforms to one of the CovJSON domain types. If multiple domain types match, then the "smaller" one is preferred, for example, Point instead of Grid.

The transformation consists of:

  • Setting domainType in coverage and domain object
  • Renaming domain axes

Params:

NameTypeAttributeDescription
cov Coverage

The Coverage object.

Return:

Promise<Coverage>

A Promise succeeding with the transformed coverage, or failing if no CovJSON domain type matched the input coverage.

See:

public asTime(inp: *): * source

import {asTime} from 'covutils/'

Params:

NameTypeAttributeDescription
inp *

Return:

*

public checkCoverage(obj: *) source

import {checkCoverage} from 'covutils/'

Params:

NameTypeAttributeDescription
obj *

public checkDomain(obj: *) source

import {checkDomain} from 'covutils/'

Params:

NameTypeAttributeDescription
obj *

public ensureClockwisePolygon(rings: Array, isCartesian: boolean) source

import {ensureClockwisePolygon} from 'covutils/'

Modifies the point order of the given polygon rings such that the first ring is ordered clockwise and all others anti-clockwise. Modification happens in-place.

Params:

NameTypeAttributeDescription
rings Array

Polygon rings to reorder (in-place)

isCartesian boolean
  • optional
  • default: false

whether coordinates are cartesian or spherical degrees

public fromDomain(domain: Domain): Coverage source

import {fromDomain} from 'covutils/'

Wraps a Domain into a Coverage object by adding dummy parameter and range data.

Params:

NameTypeAttributeDescription
domain Domain

the Domain object

options.gridAxes array
  • optional

The horizontal grid axis names, used for checkerboard pattern.

Return:

Coverage

public fromXndarray(xndarr: xndarray, options: object): Coverage source

import {fromXndarray} from 'covutils/'

Creates a Coverage with a single parameter from an xndarray object.

Params:

NameTypeAttributeDescription
xndarr xndarray

Coordinates must be primitive, not tuples etc.

options object
  • optional

Options object.

options.parameter Parameter
  • optional

Specifies the parameter, default parameter has a key of 'p1'.

options.domainType string
  • optional

A domain type URI.

options.referencing Array<object>
  • optional

Optional referencing system info, defaults to longitude/latitude in WGS84 for x/y axes and ISO8601 time strings for t axis.

Return:

Coverage

Example:

var arr = xndarray(new Float64Array(
  [ 1,2,3,
    4,5,6 ]), {
  shape: [2,3],
  names: ['y','x'],
  coords: {
    y: [10,12,14],
    x: [100,101,102],
    t: [new Date('2001-01-01')]
  }
})
var cov = CovUtils.fromXndarray(arr, {
  parameter: {
    key: 'temperature',
    observedProperty: {
      label: {en: 'Air temperature'}
    },
    unit: { symbol: '°C' }
  }
})
let param = cov.parameters.get('temperature')
let unit = param.unit.symbol // °C
cov.loadRange('temperature').then(temps => {
  let val = temps.get({x:0, y:1}) // val == 4
})

public getCategory(parameter: Parameter, val: number): Category source

import {getCategory} from 'covutils/'

Returns the category of the given parameter corresponding to the encoded integer value.

Params:

NameTypeAttributeDescription
parameter Parameter
val number

Return:

Category

public getHorizontalCRSComponents(domain: *): * source

import {getHorizontalCRSComponents} from 'covutils/'

Return the component names of the horizontal CRS of the domain.

Params:

NameTypeAttributeDescription
domain *

Return:

*

Example:

var [xComp,yComp] = getHorizontalCRSComponents(domain)

public getHorizontalCRSReferenceObject(domain: *): * source

import {getHorizontalCRSReferenceObject} from 'covutils/'

Return the reference system connection object of the horizontal CRS of the domain, or undefined if none found. A horizontal CRS is either geodetic (typically ellipsoidal, meaning lat/lon) or projected, and may be 2D or 3D (including height).

Params:

NameTypeAttributeDescription
domain *

Return:

*

public getLanguageString(map: object, preferredLanguage: string): string source

import {getLanguageString} from 'covutils/'

Params:

NameTypeAttributeDescription
map object

An object that maps language tags to strings.

preferredLanguage string
  • optional
  • default: 'en'

The preferred language as a language tag, e.g. 'de'.

Return:

string

The string within the input map whose language tag best matched. If no match was found then this is an arbitrary string of the map.

Example:

var labels = {'en': 'Temperature', 'de': 'Temperatur'}
var label = CovUtils.getLanguageString(labels, 'en-GB')
// label == 'Temperature'

public getLanguageTag(map: object, preferredLanguage: string): string source

import {getLanguageTag} from 'covutils/'

Params:

NameTypeAttributeDescription
map object

An object that maps language tags to strings.

preferredLanguage string
  • optional
  • default: 'en'

The preferred language as a language tag, e.g. 'de'.

Return:

string

The best matched language tag of the input map. If no match was found then this is an arbitrary tag of the map.

Example:

var labels = {'en': 'Temperature', 'de': 'Temperatur'}
var tag = CovUtils.getLanguageTag(labels, 'en-GB')
// tag == 'en'

public getPointInPolygonsFn(polygons: Array): function source

import {getPointInPolygonsFn} from 'covutils/'

Preprocesses an array of polygons to answer the point-in-polygon question efficiently.

Params:

NameTypeAttributeDescription
polygons Array

A list of polygons where the exterior ring of each polygon is in clockwise and the interior rings in anti-clockwise order.

Return:

function

A function classify(point) which returns the index of the first found polygon containing point, or -1 if not in any polygon.

public getProjection(domain: Domain): IProjection source

import {getProjection} from 'covutils/'

Return a projection object based on the CRS found in the coverage domain. If no CRS is found or it is unsupported, then undefined is returned. For non-built-in projections, this function returns already-cached projections that were loaded via loadProjection.

A projection converts between geodetic lat/lon and projected x/y values.

For lat/lon CRSs the projection is defined such that an input lat/lon position gets projected/wrapped to the longitude range used in the domain, for example [0,360]. The purpose of this is to make intercomparison between different coverages easier.

The following limitations currently apply:

  • only primitive axes and Tuple/Polygon composite axes are supported for lat/lon CRSs

Params:

NameTypeAttributeDescription
domain Domain

A coverage domain object.

Return:

IProjection

A stripped-down Leaflet IProjection object.

public getReferenceObject(domain: *, component: *): * source

import {getReferenceObject} from 'covutils/'

Return the reference system connection object for the given domain component, or undefined if none exists.

Params:

NameTypeAttributeDescription
domain *
component *

Return:

*

public indexOfNearest(a: Array<number>, x: number): number source

import {indexOfNearest} from 'covutils/'

Return the index of the value closest to the given number in a sorted array.

Params:

NameTypeAttributeDescription
a Array<number>

The array to search through. Must be sorted, ascending or descending.

x number

The target number.

Return:

number

The array index whose value is closest to x. If x happens to be exactly between two values, then the lower index is returned.

Example:

var a = [2,5,8,12,13]
var i = CovUtils.indexOfNearest(a, 6)
// i == 1
var j = CovUtils.indexOfNearest(a, 7)
// j == 2
var k = CovUtils.indexOfNearest(a, 50)
// k == 4

public indicesOfNearest(a: Array<number>, x: number): [lo,hi] source

import {indicesOfNearest} from 'covutils/'

Return the indices of the two neighbors in the sorted array closest to the given number.

Params:

NameTypeAttributeDescription
a Array<number>

The array to search through. Must be sorted, ascending or descending.

x number

The target number.

Return:

[lo,hi]

The indices of the two closest values, may be equal. If x exists in the array, both neighbors point to x. If x is lower (greater if descending) than the first value, both neighbors point to 0. If x is greater (lower if descending) than the last value, both neighbors point to the last index.

Example:

var a = [2,5,8,12,13]
var i = CovUtils.indicesOfNearest(a, 6)
// i == [1,2]
var j = CovUtils.indicesOfNearest(a, 5)
// j == [1,1]
var k = CovUtils.indicesOfNearest(a, 50)
// k == [4,4]

public isCoverage(obj: *): * source

import {isCoverage} from 'covutils/'

Params:

NameTypeAttributeDescription
obj *

Return:

*

public isDomain(obj: *): * source

import {isDomain} from 'covutils/'

Params:

NameTypeAttributeDescription
obj *

Return:

*

public isEllipsoidalCRS(rs: *): * source

import {isEllipsoidalCRS} from 'covutils/'

Return whether the reference system is a CRS in which horizontal position is specified by geodetic latitude and longitude.

Params:

NameTypeAttributeDescription
rs *

Return:

*

public isISODateAxis(domain: *, axisName: *): * source

import {isISODateAxis} from 'covutils/'

Returns true if the given axis has ISO8601 date strings as axis values.

Params:

NameTypeAttributeDescription
domain *
axisName *

Return:

*

public iterateRange(range: *, fn: *) source

import {iterateRange} from 'covutils/'

Iterate over all range values and run a function for each value. No particular iteration order must be assumed.

Params:

NameTypeAttributeDescription
range *
fn *

public loadProjection(domain: Domain): Promise<IProjection> source

import {loadProjection} from 'covutils/'

Like getProjection but will also try to remotely load a projection definition via the uriproj library. On success, the loaded projection is automatically cached for later use and can be directly requested with getProjection.

Params:

NameTypeAttributeDescription
domain Domain

A coverage domain object.

Return:

Promise<IProjection>

A Promise succeeding with a stripped-down Leaflet IProjection object.

public mapRange(cov: Coverage, key: String, fn: Function, dataType: String): Coverage source

import {mapRange} from 'covutils/'

Params:

NameTypeAttributeDescription
cov Coverage

The coverage.

key String

The key of the parameter for which the mapping should be applied.

fn Function

A function getting called as fn(obj, range) where obj is the axis indices object and range is the original range object.

dataType String
  • optional

The new data type to use for the range. If omitted, the original type is used.

Return:

Coverage

public maskByPolygon(cov: Coverage, polygon: Object, axes: array): Promise<Coverage> source

import {maskByPolygon} from 'covutils/'

Returns a copy of the given Coverage object where the range values which belong to domain areas outside the given polygon are returned as null (no data).

Params:

NameTypeAttributeDescription
cov Coverage

A Coverage object.

polygon Object

A GeoJSON Polygon or MultiPolygon object.

axes array
  • optional
  • default: ['x','y']

The grid axes corresponding to the polygon coordinate components.

Return:

Promise<Coverage>

public minMax(arr: *): * source

import {minMax} from 'covutils/'

Params:

NameTypeAttributeDescription
arr *

Return:

*

public minMaxOfRange(range: Range<number>): [min,max] source

import {minMaxOfRange} from 'covutils/'

Return the minimum/maximum across all range values, ignoring null's.

Params:

NameTypeAttributeDescription
range Range<number>

The numeric coverage data range.

Return:

[min,max]

The minimum and maximum values of the range, or [undefined, undefined] if the range contains only null values.

public normalizeIndexSubsetConstraints(domain: *, constraints: *): * source

import {normalizeIndexSubsetConstraints} from 'covutils/'

After normalization, all constraints are start,stop,step objects. It holds that stop > start, step > 0, start >= 0, stop >= 1. For each axis, a constraint exists.

Params:

NameTypeAttributeDescription
domain *
constraints *

Return:

*

public reduceRange(range: Range, callback: function, start: *): * source

import {reduceRange} from 'covutils/'

Apply a reduce function over the range values.

Params:

NameTypeAttributeDescription
range Range

The coverage data range.

callback function

Function to execute on each value in the array with arguments (previousValue, currentValue).

start *

Value to use as the first argument to the first call of the callback.

Return:

*

The reduced value.

public renameAxes(cov: Coverage, mapping: Map<String, String>): Coverage source

import {renameAxes} from 'covutils/'

Params:

NameTypeAttributeDescription
cov Coverage

The coverage.

mapping Map<String, String>

Return:

Coverage

Example:

var cov = ...
var mapping = new Map()
mapping.set('lat', 'y').set('lon', 'x')
var newcov = CovUtils.renameAxes(cov, mapping)

public reproject(cov: Coverage, refDomain: Domain): Promise<Coverage> source

import {reproject} from 'covutils/'

Reproject a coverage.

Reprojecting means returning a new coverage where the horizontal CRS is replaced and the horizontal domain coordinates are reprojected.

Current limitations:

  • only point-type coverage domains are supported (Tuple only)
  • only horizontal CRSs (2-dimensional) are supported
  • non-lat/lon CRSs have to be pre-cached with loadProjection()

Params:

NameTypeAttributeDescription
cov Coverage

The Coverage object to reproject.

refDomain Domain

The reference domain from which the horizontal CRS is used.

Return:

Promise<Coverage>

A promise with the reprojected Coverage object as result.

public reprojectCoords(pos: *, fromProjection: *, toProjection: *): * source

import {reprojectCoords} from 'covutils/'

Reprojects coordinates from one projection to another.

Params:

NameTypeAttributeDescription
pos *
fromProjection *
toProjection *

Return:

*

public stringifyUnit(unit: *, language: *): * source

import {stringifyUnit} from 'covutils/'

Converts a unit object to a human-readable symbol or label, where symbols are preferred.

Params:

NameTypeAttributeDescription
unit *
language *

Return:

*

Example:

var unit = {
  symbol: '°C'
}
var str = CovUtils.stringifyUnit(unit) // str == '°C'
var unit = {
  symbol: {
    value: 'Cel',
    type: 'http://www.opengis.net/def/uom/UCUM/'
  },
  label: {
    en: 'Degree Celsius'
  }
}
var str = CovUtils.stringifyUnit(unit) // str == '°C'
var unit = {
  label: {
    en: 'Degree Celsius',
    de: 'Grad Celsius'
  }
}
var str = CovUtils.stringifyUnit(unit, 'en') // str == 'Degree Celsius'

public subsetByBbox(cov: Coverage, bbox: array, axes: array): Promise<Coverage> source

import {subsetByBbox} from 'covutils/'

Returns a copy of the grid coverage subsetted to the given bounding box.

Any grid cell is included which intersects with the bounding box.

Params:

NameTypeAttributeDescription
cov Coverage

A Coverage object with domain Grid.

bbox array

[xmin,ymin,xmax,ymax] in native CRS coordinates.

axes array
  • optional
  • default: ['x','y']

Axis names [x,y].

Return:

Promise<Coverage>

A promise with a Coverage object as result.

public subsetByIndex(cov: *, constraints: *): * source

import {subsetByIndex} from 'covutils/'

Generic subsetByIndex function that can be used when building new Coverage objects.

Params:

NameTypeAttributeDescription
cov *
constraints *

Return:

*

Example:

var cov = {
  type: 'Coverage',
  ...
  subsetByIndex: constraints => CovUtils.subsetByIndex(cov, constraints)
}

public subsetByValue(cov: *, constraints: *): * source

import {subsetByValue} from 'covutils/'

Generic subsetByValue function that can be used when building new Coverage objects. Requires cov.subsetByIndex function.

Params:

NameTypeAttributeDescription
cov *
constraints *

Return:

*

Example:

var cov = {
  type: 'Coverage',
  ...
  subsetByValue: constraints => CovUtils.subsetByValue(cov, constraints)
}

public subsetDomainByIndex(domain: *, constraints: *): * source

import {subsetDomainByIndex} from 'covutils/'

Params:

NameTypeAttributeDescription
domain *
constraints *

Return:

*

public withCategories(cov: Coverage, key: String, observedProperty: object, mapping: Map<String, String>): Coverage source

import {withCategories} from 'covutils/'

Returns a copy of the given Coverage object with the categories of a given parameter replaced by the supplied ones and the encoding adapted to the given mapping from old to new.

Params:

NameTypeAttributeDescription
cov Coverage

The Coverage object.

key String

The key of the parameter to work with.

observedProperty object

The new observed property including the new array of category objects that will be part of the returned coverage.

mapping Map<String, String>

A mapping from source category id to destination category id.

Return:

Coverage

public withDerivedParameter(cov: *, options: *): * source

import {withDerivedParameter} from 'covutils/'

Params:

NameTypeAttributeDescription
cov *
options *

Return:

*

Example:

var cov = ... // has parameters 'NIR', 'red', 'green', 'blue'
var newcov = CovUtils.withDerivedParameter(cov, {
  parameter: {
    key: 'NDVI',
    observedProperty: {
      label: { en: 'Normalized Differenced Vegetation Index' }
    }
  },
  inputParameters: ['NIR','red'],
  dataType: 'float',
  fn: function (obj, nirRange, redRange) {
    var nir = nirRange.get(obj)
    var red = redRange.get(obj)
    if (nir === null || red === null) return null
    return (nir - red) / (nir + red)
  }
})

public withDomainType(cov: Coverage, domainType: String): Coverage source

import {withDomainType} from 'covutils/'

Returns a new coverage where the domainType field of the coverage and the domain is set to the given one.

Params:

NameTypeAttributeDescription
cov Coverage

The Coverage object.

domainType String

The new domain type.

Return:

Coverage

public withParameters(cov: *, params: *): * source

import {withParameters} from 'covutils/'

Returns a copy of the given Coverage object with the parameters replaced by the supplied ones.

Note that this is a low-level function and no checks are done on the supplied parameters.

Params:

NameTypeAttributeDescription
cov *
params *

Return:

*

public withSimpleDerivedParameter(cov: *, options: *): * source

import {withSimpleDerivedParameter} from 'covutils/'

Params:

NameTypeAttributeDescription
cov *
options *

Return:

*

Example:

var cov = ... // has parameters 'NIR', 'red', 'green', 'blue'
var newcov = CovUtils.withSimpleDerivedParameter(cov, {
  parameter: {
    key: 'NDVI',
    observedProperty: {
      label: { en: 'Normalized Differenced Vegetation Index' }
    }
  },
  inputParameters: ['NIR','red'],
  dataType: 'float',
  fn: function (nir, red) {
    return (nir - red) / (nir + red)
  }
})