Skip to content

Commit

Permalink
Konvertering og deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornreppen committed Mar 20, 2020
1 parent e5ad363 commit aece799
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 10 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Lastejobb

Kjører en sekvens med steg (`stages/`) i alfabetisk rekkefølge.
Lager landskapskart i ulike formater

| Størrelse | Format | Filnavn | URL |
| --------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| 5M | Kodeliste | [metadata_med_undertyper.json](https://data.artsdatabanken.no/Natur_i_Norge/Landskap/metadata_med_undertyper.json) | https://data.artsdatabanken.no/Natur_i_Norge/Landskap/metadata_med_undertyper.json |
| 92M | GeoJSON | [polygon.32633.geojson](https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.32633.geojson) | https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.32633.geojson |
| 93M | GML | [polygon.32633.gml](https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.32633.gml) | https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.32633.gml |
| 96M | GeoPackage | [polygon.32633.gpkg](https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.32633.gpkg) | https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.32633.gpkg |
| 93M | Spatialite | [polygon.32633.spatialite.sqlite](https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.32633.spatialite.sqlite) | https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.32633.spatialite.sqlite |
| 1M | GML | [polygon.32633.xsd](https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.32633.xsd) | https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.32633.xsd |
| 204M | GeoJSON | [polygon.4326.geojson](https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.4326.geojson) | https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.4326.geojson |
| 93M | Spatialite | [polygon.4326.spatialite.sqlite](https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.4326.spatialite.sqlite) | https://data.artsdatabanken.no/Natur_i_Norge/Landskap/Typeinndeling/polygon.4326.spatialite.sqlite |

## Funksjoner

Expand Down
3 changes: 3 additions & 0 deletions stages/deploy/staging.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

scp build/* grunnkart@hydra:~/tilesdata/Natur_i_Norge/Landskap/Typeinndeling
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { http, log } = require("lastejobb");
const { http } = require("lastejobb");

const url = "https://data.artsdatabanken.no/Natur_i_Norge/Landskap/metadata_med_undertyper.json"
http.downloadJson(url, 'metadata.json')
3 changes: 0 additions & 3 deletions stages/download/10_sample.js

This file was deleted.

3 changes: 0 additions & 3 deletions stages/transform/10_sample.js

This file was deleted.

7 changes: 7 additions & 0 deletions stages/transform/50_vector_formats.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e
cd build
ogr2ogr -f GML polygon.32633.gml polygon.32633.geojson
ogr2ogr polygon.32633.spatialite.sqlite polygon.32633.geojson
ogr2ogr -t_srs EPSG:4326 polygon.4326.geojson polygon.32633.geojson
ogr2ogr -f GPKG polygon.32633.gpkg polygon.32633.geojson
32 changes: 30 additions & 2 deletions stages/transform/step2.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const { io, json } = require('lastejobb')
const fs = require("fs");

const json = read("temp/landskap_32633.geojson", "S_kode");
var meta = io.lesTempJson('metadata.json')
meta = json.arrayToObject(meta.items, { uniqueKey: "kode" })
const geojson = read("temp/landskap_32633.geojson", "S_kode");
geojson.name = "NiN Landskap"
console.log("Mapping to GeoJSON");
fs.writeFileSync("build/polygon.32633.geojson", JSON.stringify(json));
//fs.writeFileSync("build/polygon.32633.geojson", JSON.stringify(geojson));
io.skrivBuildfil("polygon.32633.geojson", geojson)

function read(fn) {
const json = JSON.parse(fs.readFileSync(fn));
Expand All @@ -22,13 +27,36 @@ function floatToInt(geom) {
function map(props) {
props.kode = fixKode(props.S_kode)
props.KLG_RE_ID = props.KLG_RE_ID_
const metadata = meta["NN-" + props.kode]
props.navn = metadata.tittel.nb
props.grunntype = props["GT_nr"]
delete props["GT_nr"]
props.hovedtype = props.HT[1]
delete props.HT
props.hovedtypegruppe = props.HTG
delete props.HTG
props.arealbrukspreg = metadata.flagg["NN-LA-TI-AP-AL"] ? 1 : 0
// TODO: if (props.Arealbrukspreg != props.Naturlands) debugger
delete props.Naturlands
delete props.Navn
delete props.KLG_RE_ID_
delete props.S_kode
delete props.Shape_Leng
delete props.Shape_Area
delete props.UID_GT
delete props.Nivå
delete props.Pred_Lnr
const klger = ["AI", "AI_KS", "BP", "IP", "IYK", "JP", "KA", "RE_IA", "RE_ID", "RE_KS", "VE", "VP"]
for (var k of klger)
klg(props, "KLG_" + k)
}

function klg(props, srcKey) {
const destKey = srcKey.toLowerCase()
var value = props[srcKey]
if (value !== "NA") value = parseInt(value)
props[destKey] = value
delete props[srcKey]
}

function fixKode(kode) {
Expand Down

0 comments on commit aece799

Please sign in to comment.