API_HELPER_METHODS_UTILITY

API_HELPER_METHODS_UTILITY

Source:

Methods

(static) exports.asFeature(geometry) → {number}

Source:
See:

Encapsulates turf function https://turfjs.org/docs/#feature to create a GeoJSON feature from a GeoJSON geometry.

Parameters:
Name Type Description
geometry Geometry

a GeoJSON Geometry (consisting of attributes type and coordinates).

Returns:

a GeoJSON feature wrapping the submitted GeoJSON geometry.

Type
number

(static) exports.asFeatureCollection(features) → {number}

Source:
See:

Encapsulates turf function https://turfjs.org/docs/#featureCollection to create a GeoJSON featureCollection from an array of GeoJSON features.

Parameters:
Name Type Description
features Array.<Feature>

an array of GeoJSON features.

Returns:

a GeoJSON FeatureCollection containing all the submitted features.

Type
number

(static) exports.getAggregationWeight(feature, weightValue) → {Feature}

Source:

Add a new weight-specific property ('aggregationWeight') to the feature. It can be utilized when aggregating lower spatial units to higher spatial units, where relevant features might be weighted differently in an average-based aggretation process.

Parameters:
Name Type Description
feature Feature

a valid GeoJSON Feature, which must contain a properties attribute storing certain property values

weightValue object

the value of the aggregation weight

Returns:

returns the submitted feature which was enriched with the submitted weight property (the property is available via feature.properties['aggregationWeight'] or via )

Type
Feature

(static) exports.getBaseIndicatorById(indicatorId, baseIndicatorsMap) → {FeatureCollection.<Polygon>

Source:

Acquires the base indicator with the id indicatorId from the submitted baseIndicatorsMap.

Parameters:
Name Type Description
indicatorId string

the name of the base indicator

baseIndicatorsMap map.<string, FeatureCollection.<Polygon>>

Map containing all indicators, whereas key='meaningful name or id of the indicator' and value='indicator as GeoJSON object' (it contains duplicate entries, one for the indicator name and one for the indicator id)

Throws:

if the baseIndicatorsMap does not contain an entry with key=indicatorId

Type
Error
Returns:

returns the base indicator as FeatureCollection.<Polygon> or throws an error if the baseIndicatorsMap does not contain an entry with key=indicatorId

Type
FeatureCollection.<Polygon>

(static) exports.getBaseIndicatorByName(indicatorName, baseIndicatorsMap) → {FeatureCollection.<Polygon>}

Source:

Acquires the base indicator with the name indicatorName from the submitted baseIndicatorsMap.

Parameters:
Name Type Description
indicatorName string

the name of the base indicator

baseIndicatorsMap map.<string, FeatureCollection.<Polygon>>

Map containing all indicators, whereas key='meaningful name or id of the indicator' and value='indicator as GeoJSON object' (it contains duplicate entries, one for the indicator name and one for the indicator id)

Throws:

if the baseIndicatorsMap does not contain an entry with key=indicatorName

Type
Error
Returns:

returns the base indicator as FeatureCollection.<Polygon> or throws an error if the baseIndicatorsMap does not contain an entry with key=indicatorName

Type
FeatureCollection.<Polygon>

(static) exports.getGeoresourceById(georesourceId, georesourcesMap) → {FeatureCollection.<(Polygon|LineString|Point)>}

Source:

Acquires the georesource with the id georesourceId from the submitted georesourcesMap.

Parameters:
Name Type Description
georesourceId string

the id of the georesources

georesourcesMap map.<string, FeatureCollection.<(Polygon|LineString|Point)>>

Map containing all georesources, whereas key='meaningful name or id of the georesource' and value='georesourc as GeoJSON object' (it contains duplicate entries, one for the georesource's name and one for the georesource's id)

Throws:

if the georesourcesMap does not contain an entry with key=georesourceId

Type
Error
Returns:

returns the georesource as LineString|Point> or throws an error if the georesourcesMap does not contain an entry with key=georesourceId

Type
FeatureCollection.<(Polygon|LineString|Point)>

(static) exports.getGeoresourceByName(georesourceName, georesourcesMap) → {FeatureCollection.<(Polygon|LineString|Point)>}

Source:

Acquires the georesource with the name georesourceName from the submitted georesourcesMap.

Parameters:
Name Type Description
georesourceName string

the name of the georesources

georesourcesMap map.<string, FeatureCollection.<(Polygon|LineString|Point)>>

Map containing all georesources, whereas key='meaningful name or id of the georesource' and value='georesourc as GeoJSON object' (it contains duplicate entries, one for the georesource's name and one for the georesource's id)

Throws:

if the georesourcesMap does not contain an entry with key=georesourceName

Type
Error
Returns:

returns the georesource as LineString|Point> or throws an error if the georesourcesMap does not contain an entry with key=georesourceName

Type
FeatureCollection.<(Polygon|LineString|Point)>

(static) exports.getIndicatorIdValueMap(featureCollection, targetDate) → {Map.<string, number>|null}

Source:

Aquire a map of all indicator id and value pairs for the specified targetDate, where key=id and value=indicatorValue.

Parameters:
Name Type Description
featureCollection FeatureCollection

a valid GeoJSON FeatureCollection, whose features must contain a properties attribute storing the indicator time series according to KomMonitor's data model

targetDate string

string representing the target date for which the indicator id value map shall be extracted, following the pattern YYYY-MM-DD, e.g. 2018-01-01

Returns:

returns map of all indicator id and value pairs for the specified targetDate, where key=id and value=indicatorValue; or null if the features do not contain an indicator value for the specified date.

Type
Map.<string, number> | null

(static) exports.getIndicatorValue(feature, targetDate) → {number|null}

Source:

Aquire the feature's indicator value for the specified targetDate.

Parameters:
Name Type Description
feature Feature

a valid GeoJSON Feature, which must contain a properties attribute storing the indicator time series according to KomMonitor's data model

targetDate string

string representing the target date for which the indicator value shall be extracted, following the pattern YYYY-MM-DD, e.g. 2018-01-01

Returns:

returns the indicator value for the specified targetDate or null if the feature does not contain an indicator value for the specified date.

Type
number | null

(static) exports.getIndicatorValueArray(featureCollection, targetDate) → {Array.<number>|null}

Source:

Aquire the array of indicator values for the specified targetDate.

Parameters:
Name Type Description
featureCollection FeatureCollection

a valid GeoJSON FeatureCollection, whose features must contain a properties attribute storing the indicator time series according to KomMonitor's data model

targetDate string

string representing the target date for which the indicator value array shall be extracted, following the pattern YYYY-MM-DD, e.g. 2018-01-01

Returns:

returns the indicator values of all features of the featureCollection for the specified targetDate or null if the features do not contain an indicator value for the specified date.

Type
Array.<number> | null

(static) exports.getIndicatorValueArray_fromIdValueMap(indicatorIdValueMap) → {Array.<number>}

Source:

Aquire the array of indicator values for the specified targetDate.

Parameters:
Name Type Description
indicatorIdValueMap Map.<string, number>

map of all indicator id and value pairs where key=id and value=indicatorValue

Returns:

returns all numeric indicator values of all features of the indicatorIdValueMap.

Type
Array.<number>

(static) exports.getProcessParameterByName_asBoolean(parameterName, processParameters) → {Object.<(true|false)>}

Source:

Acquires the process parameter with the name parameterName from the submitted processParametersObject.

Parameters:
Name Type Description
parameterName string

the name of the process parameter

processParameters Array.<Object.<string, (string|number|boolean)>>

an array containing objects representing variable additional process parameters that are required to perform the indicator computation. Each entry has properties Object.name and Object.value for name and value of the parameter.

Throws:

if the processParameters array does not contain an entry with Object.name=parameterName or if the parsing of the value from --> Number throws an error.

Type
Error
Returns:

returns the value of the requested process parameter as String. The value is parsed as false) and returned. Throws an error if the processParameters array does not contain an entry with Object.name=parameterName or if the parsing of the value from --> Number throws an error.

Type
Object.<(true|false)>

(static) exports.getProcessParameterByName_asNumber(parameterName, processParameters) → {Object.<Number>}

Source:

Acquires the process parameter with the name parameterName from the submitted processParametersObject.

Parameters:
Name Type Description
parameterName string

the name of the process parameter

processParameters Array.<Object.<string, (string|number|boolean)>>

an array containing objects representing variable additional process parameters that are required to perform the indicator computation. Each entry has properties Object.name and Object.value for name and value of the parameter.

Throws:

if the processParameters array does not contain an entry with Object.name=parameterName or if the parsing of the value from --> Number throws an error.

Type
Error
Returns:

returns the value of the requested process parameter as String. The value is parsed as Number and returned. Throws an error if the processParameters array does not contain an entry with Object.name=parameterName or if the parsing of the value from --> Number throws an error.

Type
Object.<Number>

(static) exports.getProcessParameterByName_asString(parameterName, processParameters) → {Object.<String>}

Source:

Acquires the process parameter with the name parameterName from the submitted processParametersObject.

Parameters:
Name Type Description
parameterName string

the name of the process parameter

processParameters Array.<Object.<string, (string|number|boolean)>>

an array containing objects representing variable additional process parameters that are required to perform the indicator computation. Each entry has properties Object.name and Object.value for name and value of the parameter.

Throws:

if the processParameters array does not contain an entry with Object.name=parameterName

Type
Error
Returns:

returns the value of the requested process parameter as String. Users should know the real type (i.e. number). Throws an error if the processParameters array does not contain an entry with Object.name=parameterName

Type
Object.<String>

(static) exports.getPropertyValue(feature, propertyName) → {number|null}

Source:

Aquire the feature's property value for the specified propertyName.

Parameters:
Name Type Description
feature Feature

a valid GeoJSON Feature, which must contain a properties attribute storing certain property values

propertyName string

string representing the name of the queried property

Returns:

returns the property value for the specified propertyName or null if the feature does not contain the relevant property.

Type
number | null

(static) exports.getPropertyValueArray(featureCollection, propertyName) → {Array.<Object>|null}

Source:

Aquire the array of property values for the specified propertyName.

Parameters:
Name Type Description
featureCollection FeatureCollection

a valid GeoJSON FeatureCollection, whose features must contain a properties attribute storing at least one property with the submitted propertyName

propertyName string

string representing the propertyName for which the value array shall be extracted

Returns:

returns the property values of all features of the featureCollection for the specified propertyName or null if the features do not contain the propertyName.

Type
Array.<Object> | null

(static) exports.getSpatialUnitFeatureIdValue(feature) → {string}

Source:

Acquires the unique id of the submitted GeoJSON feature representing a spatial unit (i.e. city districts, building blocks, etc).

Parameters:
Name Type Description
feature GeoJSONFeature.<Polygon>

the GeoJSON feature representing a spatial unit (i.e. city districts, building blocks, etc), which must accord to the KomMonitor specific data model. It then has a property named feature.properties.ID that holds the value of the unique feature id.

Returns:

returns the unique id of the submitted GeoJSON feature.

Type
string

(static) exports.getSpatialUnitFeatureNameValue(feature) → {string}

Source:

Acquires the unique name of the submitted GeoJSON feature representing a spatial unit (i.e. city districts, building blocks, etc).

Parameters:
Name Type Description
feature GeoJSONFeature.<Polygon>

the GeoJSON feature representing a spatial unit (i.e. city districts, building blocks, etc), which must accord to the KomMonitor specific data model. It then has a property named feature.properties.NAME that holds the value of the unique feature name.

Returns:

returns the unique name of the submitted GeoJSON feature.

Type
string

(static) exports.getTargetDateWithPropertyPrefix(targetDate) → {string}

Source:

Concatenates indicator date property prefix and submitted targetDate. I.e, for exemplar targetDate="2018-01-01" it produces targetDateWithPrefix="DATE_2018-01-01". This is necessary in order to query timeseries property values from an indicator feature.

indicatorFeature.properties[targetDate] --> null indicatorFeature.properties[targetDateWithPrefix] --> indicator value, (if timestamp is present)

Parameters:
Name Type Description
targetDate string

string representing the target date for which the indicator shall be computed, following the pattern YYYY-MM-DD, e.g. 2018-01-01

Returns:

the targetDate string with additional prefix from constant indicator_date_prefix --> i.e. DATE_2018-01-01

Type
string

(static) exports.hasMultiLineString(featureCollection_geoJSON) → {boolean}

Source:

Inspects the submitted GeoJSON FeatureCollection for any features of type MultiLineString.

Parameters:
Name Type Description
featureCollection_geoJSON FeatureCollection.<(LineString|MultiLineString)>

valid GeoJSON FeatureCollection with line geometries

Returns:

returns true, if the featureCollection contains any features of type MultiLineString; false otherwise

Type
boolean

(static) exports.hasMultiPolygon(featureCollection_geoJSON) → {boolean}

Source:

Inspects the submitted GeoJSON FeatureCollection for any features of type MultiPolygon.

Parameters:
Name Type Description
featureCollection_geoJSON FeatureCollection.<(Polygon|MultiPolygon)>

valid GeoJSON FeatureCollection with polygonal geometries

Returns:

returns true, if the featureCollection contains any features of type MultiPolygon; false otherwise

Type
boolean

(static) exports.indicatorValueIsNoDataValue(feature, targetDate) → {boolean}

Source:
See:
  • isNoDataValue

Checks if the features indicator value for the specified targetDate is a NoData value.

Parameters:
Name Type Description
feature Feature

a valid GeoJSON Feature

targetDate string

string representing the target date, following the pattern YYYY-MM-DD, e.g. 2018-01-01

Returns:

returns true if indicator value is NoData value (i.e. null, null or undefined)

Type
boolean

(static) exports.isGeoJSONFeature(feature)

Source:

Checks whether the submitted object is a valid GeoJSON feature. The feature must contain a property "type"="Feature" and a property named geometry, which must have a coordinates array and type property. The method does not check, if the feature contains a properties attribute.

Parameters:
Name Type Description
feature Object

a candidate for a GeoJSON feature.

Returns:

returns true if the object is a valid GeoJSON feature; false otherwise

(static) exports.isGeoJSONFeatureCollection(featureCollection)

Source:
See:
  • isGeoJSONFeature

Checks whether the submitted object is a valid GeoJSON FeatureCollection. The featureCollection must contain a property "type"="FeatureCollection" and a property named features, which must have an array of valid feature objects.

Parameters:
Name Type Description
featureCollection Object

a candidate for a GeoJSON FeatureCollection.

Returns:

returns true if the object is a valid GeoJSON feature; false otherwise

(static) exports.isGeoJSONLineStringFeature(feature)

Source:

Checks whether the submitted object is a valid GeoJSON feature with geometryType LineString or MultiLineString. The feature must contain a property "type"="Feature" and a property named geometry, which must have a coordinates array and MultiLineString property. The method does not check, if the feature contains a properties attribute.

Parameters:
Name Type Description
feature Object

a candidate for a GeoJSON LineString|MultiLineString feature.

Returns:

returns true if the object is a valid GeoJSON LineString|MultiLineString feature; false otherwise

(static) exports.isGeoJSONPointFeature(feature)

Source:

Checks whether the submitted object is a valid GeoJSON feature with geometryType Point. The feature must contain a property "type"="Feature" and a property named geometry, which must have a coordinates array and type=Point property. The method does not check, if the feature contains a properties attribute.

Parameters:
Name Type Description
feature Object

a candidate for a GeoJSON point feature.

Returns:

returns true if the object is a valid GeoJSON point feature; false otherwise

(static) exports.isGeoJSONPolygonFeature(feature)

Source:

Checks whether the submitted object is a valid GeoJSON feature with geometryType Polygon or MultiPolygon. The feature must contain a property "type"="Feature" and a property named geometry, which must have a coordinates array and MultiPolygon property. The method does not check, if the feature contains a properties attribute.

Parameters:
Name Type Description
feature Object

a candidate for a GeoJSON Polygon|MultiPolygon feature.

Returns:

returns true if the object is a valid GeoJSON Polygon|MultiPolygon feature; false otherwise

(static) exports.isNoDataValue(value) → {boolean}

Source:

Checks if the value is a NoData value.

Parameters:
Name Type Description
value object

the value object to be inspected

Returns:

returns true if value is NoData value (i.e. null, null or undefined)

Type
boolean

(static) exports.log(logMessage)

Source:

Logs a custom message (i.e. to console).

Parameters:
Name Type Description
logMessage string

message that shall be logged.

(static) exports.logError(logMessage)

Source:

Logs a custom error message (i.e. to console).

Parameters:
Name Type Description
logMessage string

message that shall be logged.

(static) exports.minMaxNormalization_fromIdValueMap(indicatorIdValueMap) → {Map.<string, number>}

Source:

Implements a min max normalization algorithm using the formula - min) / (max - min); for an indicator id value map.

Parameters:
Name Type Description
indicatorIdValueMap Map.<string, number>

map of all indicator id and value pairs where key=id and value=indicatorValue

Returns:

returns the same map object, but instead of the original indicator value the respective normalized value is set as map value for each id value map entry.

Type
Map.<string, number>

(static) exports.minMaxNormalization_inverted_fromIdValueMap(indicatorIdValueMap) → {Map.<string, number>}

Source:

Implements an inverted min max normalization algorithm using the formula - ((value - min) / (max - min)); for an indicator id value map.

Parameters:
Name Type Description
indicatorIdValueMap Map.<string, number>

map of all indicator id and value pairs where key=id and value=indicatorValue

Returns:

returns the same map object, but instead of the original indicator value the respective normalized value is set as map value for each id value map entry.

Type
Map.<string, number>

(static) exports.rank_fromIdValueMap(indicatorIdValueMap) → {Map.<string, number>}

Source:

Encapsulates jStat's function https://jstat.github.io/all.html#rank to compute the corresponding ranks of the submitted indicator values for an indicator id value map.

Parameters:
Name Type Description
indicatorIdValueMap Map.<string, number>

map of all indicator id and value pairs where key=id and value=indicatorValue

Returns:

returns the same map object, but instead of the original indicator value the respective rank is set as map value for each id value map entry.

Type
Map.<string, number>

(static) exports.replaceMultiLineStringsByLineStrings(featureCollection_geoJSON) → {FeatureCollection.<LineString>}

Source:

Replaces any feature of type MultiLineString of the submitted featureCollection by the individual features of type LineString.

Parameters:
Name Type Description
featureCollection_geoJSON FeatureCollection.<(LineString|MultiLineString)>

valid GeoJSON FeatureCollection with line geometries (MultiLineStrings will be replaced by multiple lines).

Returns:

the GeoJSON FeatureCollection where features of type MultiLineString have been replaced by multiple features of type LineString.

Type
FeatureCollection.<LineString>

(static) exports.replaceMultiPolygonsByPolygons(featureCollection_geoJSON) → {FeatureCollection.<Polygon>}

Source:

Replaces any feature of type MultiPolygon of the submitted featureCollection by the individual features of type Polygon.

Parameters:
Name Type Description
featureCollection_geoJSON FeatureCollection.<(Polygon|MultiPolygon)>

valid GeoJSON FeatureCollection with polygonal geometries (MultiPolygons will be replaced by multiple polygons).

Returns:

the GeoJSON FeatureCollection where features of type MultiPolygon have been replaced by multiple features of type Polygon.

Type
FeatureCollection.<Polygon>

(static) exports.setAggregationWeight(feature, weightValue) → {Feature}

Source:

Add a new weight-specific property ('aggregationWeight') to the feature. It can be utilized when aggregating lower spatial units to higher spatial units, where relevant features might be weighted differently in an average-based aggretation process

Parameters:
Name Type Description
feature Feature

a valid GeoJSON Feature, which must contain a properties attribute storing certain property values

weightValue object

the value of the aggregation weight - if submitted value is NAN then default value of 1 will be set

Returns:

returns the submitted feature which was enriched with the submitted weight property (the property is available via feature.properties['aggregationWeight'] or via )

Type
Feature

(static) exports.setIndicatorValue(feature, targetDate, value) → {Feature

Source:

Set the feature's indicator value for the specified targetDate with the specified value.

Parameters:
Name Type Description
feature Feature

a valid GeoJSON Feature

targetDate string

string representing the target date for which the indicator value shall be set, following the pattern YYYY-MM-DD, e.g. 2018-01-01

value number

a numeric value which shall be set as the feature's indicator value for the specified targetDate

Returns:

returns the GeoJSON Feature

Type
Feature

(static) exports.setIndicatorValue_asNoData(feature, targetDate) → {Feature}

Source:
See:
  • indicatorValueIsNoDataValue

Set the feature's indicator value for the specified targetDate s so-called DATA value, i.e. as null. I.e. if there are data protection mechanisms that mark a certain feature's indicator value as too low, then the value must be set as NoData. Or another reason could be, that when performing spatial analysis, certain Features simply do not contain the queried elements. To distuinguish between features whose indicator value is actually {@linkode 0}, one might set the value as {@linkode NoData}. Which can be very important when average-aggregating indicaors from lower spatial units to upper spatial units, as {@linkode NoData} means somenhing different than {@linkode 0}.

Parameters:
Name Type Description
feature Feature

a valid GeoJSON Feature

targetDate string

string representing the target date for which the indicator value shall be set, following the pattern YYYY-MM-DD, e.g. 2018-01-01

Returns:

returns the GeoJSON Feature

Type
Feature

(static) exports.setIndicatorValues_fromIdValueMap(targetFeatureCollection, targetDate, indicatorIdValueMap) → {Feature}

Source:

Set the feature's indicator value for all features of the targetFeatureCollection for the specified targetDate with the respective indicator value from the input indicatorIdValueMap.

Parameters:
Name Type Description
targetFeatureCollection Feature

a valid GeoJSON FeatureCollection containing all target features

targetDate string

string representing the target date for which the indicator value shall be set, following the pattern YYYY-MM-DD, e.g. 2018-01-01

indicatorIdValueMap number

a map of indicator features (key=featureId, value=indicatorValue) whose values shall be set as the respective target features indicator value for the specified targetDate

Returns:

returns the GeoJSON FeatureCollection

Type
Feature

(static) exports.setPropertyValue(feature, propertyName, propertyValue) → {Feature}

Source:

Add a new property to the feature

Parameters:
Name Type Description
feature Feature

a valid GeoJSON Feature, which must contain a properties attribute storing certain property values

propertyName string

string representing the name of the property

propertyValue object

the value of the property

Returns:

returns the submitted feature which was enriched with the submitted property (the property is available via feature.properties[propertyName])

Type
Feature

(static) exports.throwError(message)

Source:

Utility method to throw an Error object with custom message.

Parameters:
Name Type Description
message string

the message that the Error object should contain

Throws:

throws an Error object with custom error message

Type
Error

(static) exports.transformMultiLineStringToLineStrings(featureCollection_geoJSON) → {Object}

Source:

Inspects the submitted GeoJSON FeatureCollection for any features of type MultiLineString and replaces them by the individual features of type LineString.

Parameters:
Name Type Description
featureCollection_geoJSON FeatureCollection.<(LineString|MultiLineString)>

valid GeoJSON FeatureCollection with line geometries (MultiLineStrings will be transformed to multiple lines).

Returns:

the GeoJSON FeatureCollection without any features of type MultiLineString. It may have an increased number of total features, if any MultiLineString was replaced by its individual features of type LineString.

Type
Object

(static) exports.transformMultiPolygonsToPolygons(featureCollection_geoJSON) → {Object}

Source:

Inspects the submitted GeoJSON FeatureCollection for any features of type MultiPolygon and replaces them by the individual features of type Polygon.

Parameters:
Name Type Description
featureCollection_geoJSON FeatureCollection.<(Polygon|MultiPolygon)>

valid GeoJSON FeatureCollection with polygonal geometries (MultiPolygons will be transformed to multiple polygons).

Returns:

the GeoJSON FeatureCollection without any features of type MultiPolygon. It may have an increased number of total features, if any MultiPolygon was replaced by its individual features of type Polygon.

Type
Object