About

tree-lib

This library provides tree recommendations for different climate change scenarios.

Data

Data for tree type projections is provided as a CSV file and needs to be converted into JSON to be usable by the library.

  1. Install NodeJS, Yarn and Docker Compose.
  2. Install dependencies: yarn install
  3. Make sure Docker can overwrite JSON files (ie. on Linux chmod 777 data/*.json)
  4. Stop postgres if it is already running: sudo service postgresql stop
  5. Run transformation: yarn run data:transform

NaiS

NaiS data is provided as CSV files and imported into the PostgreSQL database for further processing. New data needs to be converted to UTF-8 encoding with the following command: iconv -f ISO-8859-1 -t UTF-8 [source].csv > [target].csv

Vector Tiles

Spatial data is downloaded from different sources and imported into the database. To add or update spatial data have a look into data/spatial. For the app we generate one vector tileset using the following commands:

  1. Restart database: yarn run data:stop, then yarn run data:start
  2. Export spatial data to GeoJSON files (might take a long time): yarn run data:spatial:export
  3. Transform GeoJSON files to single vector tileset: yarn run data:spatial:tile
  4. Generate font glyphs for Mapbox GL: yarn run data:spatial:fonts
  5. Deploy tiles local by running yarn run data:spatial:deploy:local and change REACT_APP_VECTOR_TILES_ENDPOINT to localhost in .env (reload new endppoint with yarn start)
  6. Change version number in src/service-worker.js to clear the tile cache and deploy repository changes
  7. Before deployment, check the vercel project ID in the .vercel folder in tiles. This folder is generated during the first deployemnt and prompts the definition of the vercel project. Depending on the current project ID and the target instance (tree-app or tg.tree-app), the folder needs to be deleted so the initial prompt is triggered again (e.g. if Thurgau tiles tiles-tg need to be deployed but the last deployment was made for 'tiles-staging', the folder needs to be recreated)
  8. Deploy tiles to a webserver or to Vercel (currently maintained by geOps) running yarn run data:spatial:deploy followed by vercel alias set [deployment-url] [custom-domain] (custom domain either tiles.tree-app.ch, tiles-staging.tree-app.ch, tiles-tg.tree-app.ch). The geops vercel team needs to be active locally (use https://vercel.com/docs/cli/switch) for this step.

Excluding specific canton data

Forest type data from any of the canton datasets can be excluded by commenting out the corresponding line in the import file and rebuilding the tiles.

Adding new SHAPE files

New data (e.g. for a new canton) is provided in the Seafile-Sharepoint and may need to be adjusted in QGIS. Once ready the folder containing the the SHAPE files needs to be extracted into lib/sata/spatial folder (the import script does this automatically, but to avoid issues with read/write access we recommentd to extract and import manually). Then add the folder name in the .gitignore file.

Bugs

Please use the GitHub issue tracker for all bugs and feature requests. Before creating a new issue, do a quick search to see if the problem has been reported already.

Development

Changelog

2.0.0 (2020-10-22)

Bug Fixes

  • adapt recommendation logic (9e64fc5)
  • add french translations to data transformation (afc4e74)
  • add info text (67e3237)
  • add missing CSS file (7217ef0)
  • add missing data to test fixture (315d9b0)
  • add missing legend info for Mendrisotto (44fbcce)
  • add new case to baumartenlogic (8ba2213)
  • add ol.css to fix event handling for new OL release (1a00f7f)
  • adjust font sizes to improve mobile UX (4e21953)
  • allow access to JSON files (7c01224)
  • avoid missing forest type options (555856d)
  • avoid missing Redux devtools (179b75a)
  • catch empty projections (46af026)
  • catch missing information about forest type height (ff2a659)
  • catch missing language for old versions (e5bfe73)
  • catch missing terrain and latin data (e3e6958)
  • catch unsupported languages (04c0137)
  • change color for sameAltitudinalZone message (0ab74e3)
  • check for treeType options (33b3d54)
  • check if tree-lib version is available (e0ba6d0)
  • clone lists to prevent outdated information (e6ee6dc)
  • close ecogram popup on outside click and improve text rendering (70875a6)
  • data transformation was wrongly grouped by relief (b0515e6)
  • disable search for aspect and slope location filter (f01cdec)
  • do not copy target forest type to location forest type (de6e91d)
  • do not download PDF files (fa2950b)
  • do not use isMulti for negative recommendation (440077e)
  • fall back to first option for field additional (1f76e2e)
  • fall back to first option for secondary projection fields (06ec27e)
  • fall back to unknown silver fir area (fe75d70)
  • filter location by altitudinalZoneForestEcoregion, aspect and slope (b4b0111)
  • force click (cfd12e9)
  • force click to avoid hidden elements (10edf60)
  • group only by main and other (247880e)
  • group other forest types by group (6c2571a)
  • handle digit keys in CSV translation files (6a24df9)
  • improve label placement (5437fc6)
  • improve label placement (d223709)
  • improve label placement for ecograms (0201350)
  • improve label placement for grid diagrams (ee9388e)
  • improve label wording (5817674)
  • increase font size for other forest type label (f3c8ec1)
  • increase font size on info page (7dd2334)
  • info integration test (ff2e5bc)
  • initial value for projectionResult (9a4c68f)
  • integration tests (51835f5)
  • layout improvements (58069b0)
  • linting and layout bug (39c8f41)
  • make permalink more robust (c80aeef)
  • make ribbon smaller (466c028)
  • make sure we reset empty form location fields (150c8f6)
  • max with for ecogram and better label placement (55c8d51)
  • move label styling to Dropdown component (2073987)
  • only publish build to NPM (615c4f2)
  • only show recommendation for found scenarios (35a8ec7)
  • only show recommendations for last projection (b47a75d)
  • prop types (53ed080)
  • read ecogram data from locate result (e1c9c8f)
  • read forest type from f attribute (da6a4e4)
  • remove key to prevent duplicat tabs (69ac94f)
  • remove remaining references to deprecated hochmontan zones (35b472e)
  • remove silver fir area from checked fields, because it's coming from the map (5f15936)
  • repair spatial import for non-nested ZIP files (faa02a6)
  • replace lost nat_naistyp data with previous data and fix join (983a3f8)
  • reset form location on map location change (933ca1c)
  • reset projection result to initial state to handle unchanged locations (8287c0f)
  • restore missing height for forest types (53c2156)
  • select first forest type if only one is provided (c5a3529)
  • select forest type only when clicking on select option (6a257a6)
  • set default language to German (faae773)
  • set initial locate result (f0b8cbb)
  • set silverFirArea and altitudinalZone depending on projection mode and form location (9440daa)
  • show attention trees (b920716)
  • show forest type name in modal (e5c15bf)
  • show full-size ecogram (cb25c75)
  • show geolocation button only on mobile devices (bb730f4)
  • show last recommendation in correct color (81b861c)
  • show level 4 trees in recommendation if they appear in any scenario (42d629a)
  • show location fields only in form mode (30dd31a)
  • show main header only if it has main group (bde8919)
  • show projection result only if forest type and panes are available (1e11dda)
  • show slope field only in projectionMode form (a1db466)
  • show update toast if new service worker is waiting (48e0495)
  • sort and update slope labels (8c88f7d)
  • sort ecogram boxes by z value (2f0d013)
  • sort options for field additional (46ac7b8)
  • sort recommended tree types like in list and add unit test (1601eee)
  • switch marker for endangered and pioneer tree type (b910eea)
  • switch symbols for endangered and pinoeer tree types (3cc85eb)
  • take unknown carbonate information into account (444a489)
  • trim altitudinal zone in source data to fix missing projection (1921d08)
  • unregister OpenLayers events correctly (e6b006d)
  • update filter data for forestType, treetype and indicator (372c8f6)
  • update French data translations (9c14f01)
  • update German UI strings (0a51873)
  • update map position icon (5fa997c)
  • update NaiS data fix encoding (90b49fd)
  • update string for altitudinal zone to match projection CSV data (6b33bdd)
  • update translations (e5e7ccb)
  • use correct coordinate transformation (922c56c)
  • use correct font size for info text (93cb0bb)
  • use correct links for reports (693eb30)
  • use correct projection result for recommendation (13c0dcc)
  • use correct variable name for slopes (b4550ca)
  • use correct variable name for treeTypes (564f74b)
  • use custom history to maintain permalink (4bb68b0)
  • use EPSG:2056 as default display projection (7b21b46)
  • use first option to fetch projection for secondary fields (a7e358b)
  • deps: pin dependency history to 4.10.1 (08b522b)
  • use original location if scenario does not change (c839150)
  • use simple unicode cross for endangered tree types (ecec636)
  • use stable sorting (19a6932)
  • use target column for silver fir area in data processing (288880d)
  • use trim to join naistyp data (ab61f7d)
  • deps: pin dependency lodash.get to 4.4.2 (964b913)

Features

  • add aspect and slope filter to location form (5e1f6df)
  • add button to forest type PDFs (90d3730)
  • add contact info (1ddd513)
  • add disclaimer to info page (a89148e)
  • add ecogram 10 and 12 to forest ecoregion 2b (9c344fd)
  • add forest type page for testing (aceb903)
  • add french translations to NAiS data (e33b881)
  • add general information to forest type modal (5c86fb1)
  • add German translation strings for forest type diagram (69d343a)
  • add help buttons to location components (d1225dc)
  • add indicator and extent foresttype information (70ede11)
  • add indicators filter to location form (1fe37ad)
  • add initial french translation to projection data (44fd01b)
  • add initial geolocation control (45f1949)
  • add legend for map vector layer (0b30ae3)
  • add location filter for carbonate, geomorphology and relief type (129d74e)
  • add location filter for tree type (73c6909)
  • add marker for pioneer tree types (2eb2ab2)
  • add more info text (a6a31d4)
  • add more location filters (f05dbd1)
  • add more type information (8c6f3d2)
  • add pioneer to treeType info based on nat_arten_baum table (2aa321d)
  • add project supervision to participants (378c043)
  • add reset button to location form (2ed8379)
  • add rows and silverFirArea to ecogram data and component (6b0d68a)
  • add scale bar to map (0e4947a)
  • add tile index file (8a8e0e2)
  • add tiles service worker for offline map (4607863)
  • add vegetation data and function (00ef840)
  • allow user to unregister old service worker (6d23809)
  • connect forest type diagram to data (9b00f24)
  • filter forest types (0f0ad45)
  • filter forestTypes by location groups (a592b90)
  • filter treeTypes and indicators by forestType and return grouped forestTypes (59db0d0)
  • for missing projections fallback to unknown secondary fields (2cc07af)
  • forest type needs to include all indicators and tree types (6c6ec80)
  • handle hochmontan altitudinal zones for locate function (b114ac8)
  • highlight only active ecogram boxes (ff19a60)
  • implement and use forest type button (556a209)
  • implement and use initial language switcher component for french (705894c)
  • implement initial forest type diagram (f576e9f)
  • implement initial location result component to show ecogram or forest type list (1169e50)
  • implement location filter for forest type hight and group (d217fc7)
  • implement modal to select forest type from ecogram (890732f)
  • import updated NAiS data NAT_LAGE and NAT_BODEN (f8147fa)
  • import updated spatial data from map.geo.admin.ch (790fbec)
  • import updated translations (8923ea4)
  • import updated translations from Google Sheet (0a876d0)
  • improve forest type description (da3670b)
  • improve labeling in forest type diagrams (4a152c5)
  • improve location result style and fix selection (deef714)
  • improve mobile support for forest type description (34f05f1)
  • improve styling for ecogram (506bab5)
  • include location.altitudinalZone in options for targetAltitudinalZone (f5a78cc)
  • initial ecogram visualisation (e5890a1)
  • initial location form (e8bae89)
  • make latin italic (d49296e)
  • merge hochmontan into single altitudinal zone (3580a80)
  • merge level 4 trees into level 3 for projection info (72f07f1)
  • move forest type description into tabs (7b4e12d)
  • move forest type group to location result (45a09d1)
  • preselect and fall back to normal location altitudinal zone for transition (b444cde)
  • remove test ribbon (c9b1b0f)
  • remove treeLayerHeightMin and treeLayerHeightMax from location filter (3e79a98)
  • replace forest type button with forest type modal (347150a)
  • reset form location if forest type is missing in options (34cec44)
  • reset form location on map location change (b2c5df9)
  • respond to tiles with cached data (fc3f87c)
  • run locate function on location changes (2c3ef95)
  • run projection for each scenario and handle altitudinal zone hochmontan (4284c40)
  • set default value to unknown (726d2ed)
  • show location page by default (980fc95)
  • show message if altitudinal zones do not change (c3ec2ac)
  • show message if ecogram is missing (f256c5f)
  • show message if user should check location fields because of missing projection (01e1dc8)
  • show no data hint if data is missing in diagrams (a111fcd)
  • show read-only location information in map mode (c5d2681)
  • show version information in about text (8bd8961)
  • store projection result for each scenario (690f8ba)
  • support multiple target altitudinal zones (2c1858d)
  • switch from modal to popup for ecogram forest type selection (2a85cce)
  • take forest type height and group into account for location (8a13866)
  • use options from locate function (953f113)

BREAKING CHANGES

  • will not include src files.

1.2.1 (2020-03-25)

Bug Fixes

  • correct forest types in ecogram data (01e1d83)

1.2.0 (2020-03-16)

Features

  • add ecogram data and transformation scripts (#149) (eb09799)
  • return options for locate result (2996755)

1.1.0 (2020-03-10)

Bug Fixes

  • import dump to speedup spatial import (24f2858)
  • update NaiS data provided on 2020-02-27 (#147) (f20c4e3)

Features

  • add version to default export (e8097ea)
  • fall back to first projection for secondary fields (#151) (ea1d4b1)
  • initial locate function (#152) (f79b68b)
  • return type list if no code is provided (b788208)
  • update projection data (3eef986)

1.0.0 (2019-12-20)

Initial stable release.

info

This function returns meta information about a given type and code. If the code parameter is missing a list of all available codes is returned. This meta information includes translations and type specific data. See data/types.json for all available types and codes.

info(type: string, code: string?, profile: string?, lookup: any): object
Parameters
type (string) A valid type.
code (string?) A valid code for the given type.
profile (string? = 'ch') Profile code.
lookup (any = 'code')
Returns
object: Includes all meta information.

list

This function lists all recommended tree types for the forest type at a given location.

list(location: object, mergeLevel4: boolean?): array
Parameters
location (object = {})
Name Description
location.forestType object Required code for forest type at current location.
location.transitionForestType object? Optional code for transition forest type at current location.
mergeLevel4 (boolean? = false) Optional flag to merge level 4 into level 3.
Returns
array: Nested arrays of recommended tree type codes.

locate

This function tries to locate the forest type for a given location.

locate(location: object, profile: string?): object
Parameters
location (object = {}) The current location.
profile (string? = 'ch') Profile code.
Returns
object: Includes ecogram, forest types and options.

project

This function projects the forest type for a given location into the future.

project(location: object, targetAltitude: string, previousResult: object?): object
Parameters
location (object = {}) The current location.
targetAltitude (string) Code for target altitudinal zone.
previousResult (object?) Only for internal use.
Returns
object: Includes projections and options.

recommend

This function recommends tree types based on a location and list of projections. Call this function with the result of the project() function.

recommend(location: object, projections: array, future: boolean?): array
Parameters
location (object = {}) The current location.
projections (array = []) The result of the project() function.
future (boolean? = false) Optional flag to include tree types for the future.
Returns
array: Nested arrays of recommended tree type codes.

getMapping

getMapping
Parameters
type (string) A type of mapping (see lib/src/mappings.index.mjs)
profile (string) A valid tree-app profile with relief mapping
Returns
(array | object): image path

getReliefImageUrl

getReliefImageUrl
Parameters
code (string) A valid forest type code
profile (any)
trimCode (boolean = false) Only uses the base code number when set to true (12a => 12)
activeProfile (string) A valid tree-app profile with relief mapping
Returns
string: image path

getImageHtml

getImageHtml
Parameters
imagePath (string) A valid path to an image
Returns
Promise: A promise, resolving in an

By default we fall back to the current (today) location in getProjectionResultLocation, which can result in different map TAZ and projectionResult AZ. Here we check for two conditions:

  • No projections were found for the scenario
  • The fallback AZ is different to the map TAZ

If the conditions are met we return null and surpress the scenario column creation

vegetation

This function lists all vegetations for the forest type at a given location.

vegetation(location: object): array
Parameters
location (object = {})
Name Description
location.forestType object Required code for forest type at current location.
Returns
array: Nested arrays of vegetation codes.