-
Notifications
You must be signed in to change notification settings - Fork 7
/
cycleHighways.ts
72 lines (59 loc) · 2 KB
/
cycleHighways.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import osmToGeojson from 'npm:osmtogeojson'
import { exec } from 'https://deno.land/x/exec/mod.ts'
import { parseArgs } from 'jsr:@std/cli/parse-args'
const flags = parseArgs(Deno.args, {
boolean: ['download'],
default: { download: true },
negatable: ['download'],
})
const overpassRequest = `
[out:json];
area["name"="France"]->.boundaryarea;
(
nwr["cycle_network"~"FR:REV|Les Voies Lyonnaises|FR:IDF"](area.boundaryarea);
nwr["network:type"="REV Rennes Métropole"](area.boundaryarea);
nwr[network=lcn][name~"Chronovélo |Vélostras "](area.boundaryarea);
nwr[cycle_highway](area.boundaryarea);
);
(._;>;);
/*end of auto repair*/
out;
`
const buildData = async () => {
const request = await fetch('https://overpass-api.de/api/interpreter', {
method: 'POST',
// The body contains the query
// to understand the query language see "The Programmatic Query Language" on
// https://wiki.openstreetmap.org/wiki/Overpass_API#The_Programmatic_Query_Language_(OverpassQL)
body: 'data=' + encodeURIComponent(overpassRequest),
})
const json = await request.json()
const relations = osmToGeojson(json).features.filter((feature) =>
feature.id.startsWith('relation')
)
const featureCollection = {
type: 'FeatureCollection',
features: relations,
}
return featureCollection
}
const geojsonFilename = './data/raw/cycleHighways.geojson',
pmtilesFilename = './data/pmtiles/cycleHighways.pmtiles'
if (flags.download) {
const data = await buildData()
await Deno.writeTextFile(geojsonFilename, JSON.stringify(data))
console.log('Cycle highways geojson file created')
}
try {
await Deno.lstat(geojsonFilename)
console.log(geojsonFilename + ' exists !')
await exec(
`tippecanoe -zg -Z7 -o ${pmtilesFilename} --drop-densest-as-needed ${geojsonFilename} --force --include=`
)
console.log(pmtilesFilename + ' written !')
} catch (err) {
if (!(err instanceof Deno.errors.NotFound)) {
throw err
}
console.log('Please download the geojson file beffore procuding pmtiles !')
}