Add gitignore, add scripts to generate the required data
This commit is contained in:
parent
e07050059d
commit
78a31678d8
3 changed files with 74 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*~
|
18
scripts/mapbuilder.sh
Executable file
18
scripts/mapbuilder.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
||||
|
||||
temp=$(mktemp -d)
|
||||
|
||||
mkdir "$temp/data"
|
||||
for i in "$1/data/"*
|
||||
do
|
||||
ogrmerge.py -single -o "$temp/$i.json" "$i"/*
|
||||
done
|
||||
|
||||
|
||||
tippecanoe -aN -z10 -o "$temp/strecken.pmtiles" $temp/data/*.json
|
||||
|
||||
mv $temp/strecken.pmtiles "$2"
|
||||
|
||||
rm -r $temp
|
55
scripts/umap-extractor.py
Executable file
55
scripts/umap-extractor.py
Executable file
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import re
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
url = sys.argv[1]
|
||||
outdir = sys.argv[2]
|
||||
|
||||
base = url.split("/map/")[0]
|
||||
r = requests.get(url)
|
||||
|
||||
regexp = re.compile(r'U.MAP = new U.Map[(]"map", (.+) }\)', re.DOTALL)
|
||||
|
||||
data = json.loads(regexp.findall(r.text, re.DOTALL)[0].replace("})","}"))
|
||||
|
||||
properties = data["properties"]
|
||||
layers = properties["datalayers"]
|
||||
map_id = properties["umap_id"]
|
||||
|
||||
config = {}
|
||||
config["name"] = properties["name"]
|
||||
colors = {}
|
||||
config["layers"] = colors
|
||||
config["tilelayer"] = properties["tilelayer"]
|
||||
|
||||
config["tilelayer"]["attribution"] = re.sub(r'\[\[([^|]+)\|([^|]+)\]\]', r'<a href="\1" >\2</a>', config["tilelayer"]["attribution"])
|
||||
|
||||
def normalize_name(name) :
|
||||
return name.replace("/", "_").replace("-","").replace(" ","")
|
||||
|
||||
datadir = os.path.join(outdir,"data")
|
||||
if not os.path.exists(datadir) :
|
||||
os.mkdir(datadir)
|
||||
|
||||
for layer in layers :
|
||||
layer_id = layer["id"]
|
||||
req = requests.get(f"{base}/datalayer/{map_id}/{layer_id}/")
|
||||
options = req.json()["_umap_options"]
|
||||
nname = normalize_name(options['name'])
|
||||
if not os.path.exists(os.path.join(datadir,nname)) :
|
||||
os.mkdir(os.path.join(datadir,nname))
|
||||
with open(os.path.join(datadir,nname,f"{nname}.json"), "w") as f :
|
||||
f.write(req.text)
|
||||
colors[nname] = { "color" : options["color"] if "color" in options else "DarkGreen" , "humanname" : options["name"] }
|
||||
if "weight" in options :
|
||||
colors[nname]["width"] = options["weight"]
|
||||
else:
|
||||
colors[nname]["width"] = 2
|
||||
|
||||
with open(os.path.join(outdir,"layers.json"), "w") as f :
|
||||
json.dump(config, f, indent=4)
|
Loading…
Reference in a new issue