Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# [1.2.0](https://github.com/geops/tree-lib/compare/v1.1.0...v1.2.0) (2020-03-16)


### Features

* add ecogram data and transformation scripts ([#149](https://github.com/geops/tree-lib/issues/149)) ([eb09799](https://github.com/geops/tree-lib/commit/eb09799e42c07b8f96c299b879b6b745f5a92809))
* return options for locate result ([2996755](https://github.com/geops/tree-lib/commit/2996755af15b00c01c6505f587ef1d61b05c21f6))

# [1.1.0](https://github.com/geops/tree-lib/compare/v1.0.0...v1.1.0) (2020-03-10)


Expand Down
557 changes: 555 additions & 2 deletions data/ecograms.json

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions data/locations.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"M": { "20": "1" },
"J": { "20": "1" },
"1": { "20": "1" }
"1": { "20": 11, "40": 25, "50": 27, "60": 2, "81": 5, "90": 14, "100": 18 },
"3": { "83": 9, "90": 14, "100": 19 },
"4": { "20": 21, "82": 10, "83": 12, "90": 15, "100": 16 },
"2a": { "40": 26, "50": 1, "60": 3, "81": 6 },
"M": { "20": 11, "40": 25, "50": 27, "60": 2, "81": 5, "90": 14, "100": 18 },
"J": { "20": 11, "40": 25, "50": 27, "60": 2, "81": 5, "90": 14, "100": 18 },
"5b": { "10": 23, "20": 22, "30": 22, "70": 4 },
"2b": { "20": 20, "82": 7, "83": 8 },
"5a": { "81": 13 }
}
135 changes: 135 additions & 0 deletions data/nais/ecogram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/* eslint-disable no-console */
/* eslint-disable import/no-extraneous-dependencies */
const path = require('path');
const fs = require('fs');

const types = require('../types.json');

console.log(`
This script reads all geojson files in /data/nais/geojson/ and aggregate them
into two files: /data/nais/ecograms.json & /data/nais/locations.json
`);

const abortScript = alert => {
console.log(alert);
process.exit(1);
};

const getCoords = (coordinates, coordIdx, index) => {
const filteredCoords = coordinates.map(c => c[coordIdx].toFixed(3));

const coordsArray = [];
filteredCoords.forEach(f => {
if (!coordsArray.includes(f)) {
coordsArray.push(f);
}
});

return coordsArray[index] < 0 ? 0 : coordsArray[index];
};

const aggregateGeojson = (dir, geojsonFiles) => {
const newEcogramsJson = {};
const newLocationsJson = {};

geojsonFiles.forEach((filename, gIdx) => {
const geojsonIdx = gIdx + 1;
const { ext, name } = path.parse(filename);
const filepath = path.resolve(dir, filename);
console.log(` Start formating ${name}${ext}`);
const rawdata = fs.readFileSync(filepath);
const geojson = JSON.parse(rawdata);

const { forestEcoR, altZones } = geojson.features[0].properties;

if (!altZones) {
abortScript(`
/!\\ 'altZones' property not present or badly formated
in at least the first feature, to be converted to 'altitudinalZones' !
`);
}
const altitudinalZones = {};
altZones.split(',').forEach(zone => {
const type = types.altitudinalZone.find(t => t.code === zone);
if (!type) {
console.log(`Altitudinal zone ${zone} not found! Skipping ...`);
return;
}
altitudinalZones[zone] = geojsonIdx;
});

if (!forestEcoR) {
abortScript(`
/!\\ 'forestEcoR' property not present or badly formated
in at least the first feature, to be converted to 'forestEcoregions' !
`);
}
forestEcoR.split(',').forEach(region => {
const type = types.forestEcoregion.find(t => t.code === region);
if (!type) {
console.log(`Forest ecoregion ${region} not found! Skipping ...`);
return;
}

if (!newLocationsJson[region]) {
newLocationsJson[region] = altitudinalZones;
} else {
const keys = Object.keys(altitudinalZones);
keys.forEach(k => {
newLocationsJson[region][k] = altitudinalZones[k];
});
}
});

const features = [];
geojson.features.forEach(f => {
const { z, forTypes, otforTypes } = f.properties;
const { coordinates } = f.geometry;
const [coords] = coordinates[0];
// Remove last coord, which is the same as the first one.
coords.splice(coords.length - 1, coords.length);

const x1 = getCoords(coords, 0, 0);
const x2 = getCoords(coords, 0, 1);
const y1 = getCoords(coords, 1, 0);
const y2 = getCoords(coords, 1, 1);

const fT = forTypes ? forTypes.split(',') : [];
const oT = otforTypes ? otforTypes.split(',') : [];

features.push({
x: x1 * 1000,
y: 1000 - y1 * 1000 - (1000 - y1 * 1000 - (1000 - y2 * 1000)),
w: x2 * 1000 - x1 * 1000,
h: 1000 - y1 * 1000 - (1000 - y2 * 1000),
z,
f: [...fT, ...oT],
});
});

newEcogramsJson[geojsonIdx] = features;
});
const outputDirectory = path.join(__dirname, `../`);
// If no outputs folder, create it.
if (!fs.existsSync(outputDirectory)) {
fs.mkdirSync(outputDirectory);
}

fs.writeFileSync(
`${outputDirectory}/ecograms.json`,
JSON.stringify(newEcogramsJson),
);
fs.writeFileSync(
`${outputDirectory}/locations.json`,
JSON.stringify(newLocationsJson),
);

console.log(`
Building ecograms.json & locations.json successfuly!
`);
};

const geojsonFiles = fs
.readdirSync('data/nais/geojson/')
.filter(fileName => /.geojson/.test(fileName));
aggregateGeojson('data/nais/geojson/', geojsonFiles);
32 changes: 32 additions & 0 deletions data/nais/geojson/10_Reg_2a_Alt_50.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"type": "FeatureCollection",
"name": "10_",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "id": 1, "z": "1", "forTypes": "45", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.047403916308526, 0.020413552457389 ], [ 0.047403916308526, 0.136279092359486 ], [ 0.17643568556195, 0.136279092359486 ], [ 0.17643568556195, 0.020413552457389 ], [ 0.047403916308526, 0.020413552457389 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 2, "z": "1", "forTypes": "44", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.442407258201666, 0.0032813075421 ], [ 0.442407258201666, 0.058595844377107 ], [ 0.784730245598165, 0.058595844377107 ], [ 0.784730245598165, 0.0032813075421 ], [ 0.442407258201666, 0.0032813075421 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 3, "z": "2", "forTypes": "30", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.467417541006003, 0.069131110499162 ], [ 0.467417541006003, 0.132539146047727 ], [ 0.595196052560324, 0.132539146047727 ], [ 0.595196052560324, 0.069131110499162 ], [ 0.467417541006003, 0.069131110499162 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 4, "z": "1", "forTypes": "27", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.43976795455338, 0.062565225373305 ], [ 0.43976795455338, 0.133646172058208 ], [ 0.891375305957907, 0.133646172058208 ], [ 0.891375305957907, 0.062565225373305 ], [ 0.43976795455338, 0.062565225373305 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 5, "z": "1", "forTypes": "26", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.441081570547974, 0.140229067249161 ], [ 0.441081570547974, 0.219231217149584 ], [ 0.891379009762403, 0.219231217149584 ], [ 0.891379009762403, 0.140229067249161 ], [ 0.441081570547974, 0.140229067249161 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 6, "z": "1", "forTypes": "12S", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.725483137182005, 0.257413737699208 ], [ 0.725483137182005, 0.420670032275432 ], [ 0.884796114571451, 0.420670032275432 ], [ 0.884796114571451, 0.257413737699208 ], [ 0.725483137182005, 0.257413737699208 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 7, "z": "1", "forTypes": "8S", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.43450052725927, 0.257411295096198 ], [ 0.43450052725927, 0.420675587982177 ], [ 0.593815450969653, 0.420675587982177 ], [ 0.593815450969653, 0.257411295096198 ], [ 0.43450052725927, 0.257411295096198 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 8, "z": "2", "forTypes": "8b", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.258068684024928, 0.281111150656556 ], [ 0.258068684024928, 0.395660044263127 ], [ 0.387100686606665, 0.395660044263127 ], [ 0.387100686606665, 0.281111150656556 ], [ 0.258068684024928, 0.281111150656556 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 9, "z": "1", "forTypes": "4", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.135620600846933, 0.274528549648066 ], [ 0.135620600846933, 0.46285105731441 ], [ 0.288338233341486, 0.46285105731441 ], [ 0.288338233341486, 0.274528549648066 ], [ 0.135620600846933, 0.274528549648066 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 10, "z": "2", "forTypes": "8*", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.044770423446796, 0.290327118005045 ], [ 0.044770423446796, 0.498359176923487 ], [ 0.192235239655684, 0.498359176923487 ], [ 0.192235239655684, 0.290327118005045 ], [ 0.044770423446796, 0.290327118005045 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 11, "z": "2", "forTypes": "8d", "otForTypes": "8dFe", "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.254119229623894, 0.450959530400069 ], [ 0.254119229623894, 0.651089498972346 ], [ 0.383150737807412, 0.651089498972346 ], [ 0.383150737807412, 0.450959530400069 ], [ 0.254119229623894, 0.450959530400069 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 12, "z": "1", "forTypes": "8a", "otForTypes": "8aFe", "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.431868738383713, 0.450959514950125 ], [ 0.431868738383713, 0.566823730796441 ], [ 0.560899165071159, 0.566823730796441 ], [ 0.560899165071159, 0.450959514950125 ], [ 0.431868738383713, 0.450959514950125 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 13, "z": "1", "forTypes": "3", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.117186001893415, 0.504942609367811 ], [ 0.117186001893415, 0.68005633444335 ], [ 0.219885250618983, 0.68005633444335 ], [ 0.219885250618983, 0.504942609367811 ], [ 0.117186001893415, 0.504942609367811 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 14, "z": "2", "forTypes": "1", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.047387744045621, 0.518094845251428 ], [ 0.047387744045621, 0.72877366053295 ], [ 0.147469790059278, 0.72877366053295 ], [ 0.147469790059278, 0.518094845251428 ], [ 0.047387744045621, 0.518094845251428 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 15, "z": "1", "forTypes": "2", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.019757294080308, 0.731407422899589 ], [ 0.019757294080308, 0.798556187319811 ], [ 0.148786506257115, 0.798556187319811 ], [ 0.148786506257115, 0.731407422899589 ], [ 0.019757294080308, 0.731407422899589 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 16, "z": "1", "forTypes": "68,41*", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.011859570666992, 0.813039603536565 ], [ 0.011859570666992, 0.938121438876082 ], [ 0.226469231239656, 0.938121438876082 ], [ 0.226469231239656, 0.813039603536565 ], [ 0.011859570666992, 0.813039603536565 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 17, "z": "1", "forTypes": "12a", "otForTypes": "12aFe,12aG", "forestEcoR": "2a", "altZones": "5050" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.726798855584437, 0.440423597072077 ], [ 0.726798855584437, 0.564191239460583 ], [ 0.85582850394159, 0.564191239460583 ], [ 0.85582850394159, 0.440423597072077 ], [ 0.726798855584437, 0.440423597072077 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 18, "z": "1", "forTypes": "13a", "otForTypes": "13aFe", "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.865043028107827, 0.427259185711227 ], [ 0.865043028107827, 0.583938796145771 ], [ 0.992762061121222, 0.583938796145771 ], [ 0.992762061121222, 0.427259185711227 ], [ 0.865043028107827, 0.427259185711227 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 19, "z": "1", "forTypes": "12e", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.726799231441982, 0.570775888215208 ], [ 0.726799231441982, 0.686640937282753 ], [ 0.855830289265041, 0.686640937282753 ], [ 0.855830289265041, 0.570775888215208 ], [ 0.726799231441982, 0.570775888215208 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 20, "z": "1", "forTypes": "13e", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.859780088368043, 0.628707671311206 ], [ 0.859780088368043, 0.743256034054311 ], [ 0.988812126944426, 0.743256034054311 ], [ 0.988812126944426, 0.628707671311206 ], [ 0.859780088368043, 0.628707671311206 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 21, "z": "1", "forTypes": "14", "otForTypes": "14G", "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.725480047720204, 0.690590680594395 ], [ 0.725480047720204, 0.784073615495652 ], [ 0.853196413759893, 0.784073615495652 ], [ 0.853196413759893, 0.690590680594395 ], [ 0.725480047720204, 0.690590680594395 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 22, "z": "1", "forTypes": "15", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.434507745681303, 0.690590502208868 ], [ 0.434507745681303, 0.806445479468036 ], [ 0.562221792709064, 0.806445479468036 ], [ 0.562221792709064, 0.690590502208868 ], [ 0.434507745681303, 0.690590502208868 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 23, "z": "2", "forTypes": "16", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.722845828657827, 0.788021108800477 ], [ 0.722845828657827, 0.851222532059015 ], [ 0.851879789214308, 0.851222532059015 ], [ 0.851879789214308, 0.788021108800477 ], [ 0.722845828657827, 0.788021108800477 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 24, "z": "4", "forTypes": "40*", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.520084583899134, 0.811724364295333 ], [ 0.520084583899134, 0.893367918730372 ], [ 0.725485772780755, 0.893367918730372 ], [ 0.725485772780755, 0.811724364295333 ], [ 0.520084583899134, 0.811724364295333 ] ] ] ] } },
{ "type": "Feature", "properties": { "id": 25, "z": "2", "forTypes": "65", "otForTypes": null, "forestEcoR": "2a", "altZones": "50" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 0.725487578934206, 0.861762039495394 ], [ 0.725487578934206, 0.957871076917628 ], [ 0.854526406070832, 0.957871076917628 ], [ 0.854526406070832, 0.861762039495394 ], [ 0.725487578934206, 0.861762039495394 ] ] ] ] } }
]
}
Loading