Function
Static Public Summary | ||
public |
addCollectionQueryFunction(collection: *) Adds a basic query() function to the coverage collection object. |
|
public |
addLoadRangesFunction(cov: *) |
|
public |
addSubsetFunctions(cov: *) |
|
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 |
getHorizontalCRSComponents(domain: *): * Return the component names of the horizontal CRS of the domain. |
|
public |
getHorizontalCRSReferenceObject(domain: *): * Return the reference system connection object of the horizontal CRS of the domain,
or |
|
public |
getLanguageString(map: object, preferredLanguage: string): string |
|
public |
getLanguageTag(map: object, preferredLanguage: string): string |
|
public |
getPointInPolygonsFn(polygons: Array): function 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 |
indexOfNearest(a: Array<number>, x: number): number 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 |
|
|
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 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:
Name | Type | Attribute | Description |
collection | * |
public addLoadRangesFunction(cov: *) source
import {addLoadRangesFunction} from 'covutils/'
Params:
Name | Type | Attribute | Description |
cov | * |
public addSubsetFunctions(cov: *) source
import {addSubsetFunctions} from 'covutils/'
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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. |
public asTime(inp: *): * source
import {asTime} from 'covutils/'
Params:
Name | Type | Attribute | Description |
inp | * |
Return:
* |
public checkCoverage(obj: *) source
import {checkCoverage} from 'covutils/'
Params:
Name | Type | Attribute | Description |
obj | * |
public checkDomain(obj: *) source
import {checkDomain} from 'covutils/'
Params:
Name | Type | Attribute | Description |
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.
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:
Name | Type | Attribute | Description |
domain | Domain | the Domain object |
|
options.gridAxes | array |
|
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:
Name | Type | Attribute | Description |
xndarr | xndarray | Coordinates must be primitive, not tuples etc. |
|
options | object |
|
Options object. |
options.parameter | Parameter |
|
Specifies the parameter, default parameter has a key of 'p1'. |
options.domainType | string |
|
A domain type URI. |
options.referencing | Array<object> |
|
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
domain | * |
Return:
* |
public getLanguageString(map: object, preferredLanguage: string): string source
import {getLanguageString} from 'covutils/'
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/'
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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.
Return:
number | The array index whose value is closest to |
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.
Return:
[lo,hi] | The indices of the two closest values, may be equal.
If |
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:
Name | Type | Attribute | Description |
obj | * |
Return:
* |
public isDomain(obj: *): * source
import {isDomain} from 'covutils/'
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
domain | Domain | A coverage domain object. |
public mapRange(cov: Coverage, key: String, fn: Function, dataType: String): Coverage source
import {mapRange} from 'covutils/'
Params:
Name | Type | Attribute | Description |
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 |
|
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:
Name | Type | Attribute | Description |
cov | Coverage | A Coverage object. |
|
polygon | Object | A GeoJSON Polygon or MultiPolygon object. |
|
axes | array |
|
The grid axes corresponding to the polygon coordinate components. |
public minMax(arr: *): * source
import {minMax} from 'covutils/'
Params:
Name | Type | Attribute | Description |
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.
Return:
[min,max] | The minimum and maximum values of the range,
or [undefined, undefined] if the range contains only |
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:
Name | Type | Attribute | Description |
domain | * | ||
constraints | * |
Return:
* |
public reduceRange(range: Range, callback: function, start: *): * source
import {reduceRange} from 'covutils/'
Apply a reduce function over the range values.
Return:
* | The reduced value. |
public renameAxes(cov: Coverage, mapping: Map<String, String>): Coverage source
import {renameAxes} from 'covutils/'
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:
Name | Type | Attribute | Description |
cov | Coverage | The Coverage object to reproject. |
|
refDomain | Domain | The reference domain from which the horizontal CRS is used. |
public reprojectCoords(pos: *, fromProjection: *, toProjection: *): * source
import {reprojectCoords} from 'covutils/'
Reprojects coordinates from one projection to another.
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
cov | Coverage | A Coverage object with domain Grid. |
|
bbox | array | [xmin,ymin,xmax,ymax] in native CRS coordinates. |
|
axes | array |
|
Axis names [x,y]. |
public subsetByIndex(cov: *, constraints: *): * source
import {subsetByIndex} from 'covutils/'
Generic subsetByIndex function that can be used when building new Coverage objects.
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
cov | * | ||
constraints | * |
Return:
* |
Example:
var cov = {
type: 'Coverage',
...
subsetByValue: constraints => CovUtils.subsetByValue(cov, constraints)
}
public subsetDomainByIndex(domain: *, constraints: *): * source
import {subsetDomainByIndex} from 'covutils/'
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
cov | * | ||
params | * |
Return:
* |
public withSimpleDerivedParameter(cov: *, options: *): * source
import {withSimpleDerivedParameter} from 'covutils/'
Params:
Name | Type | Attribute | Description |
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)
}
})