-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps.js
executable file
·73 lines (64 loc) · 1.58 KB
/
maps.js
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
73
#!/usr/bin/env node
import fs from 'fs'
import JSONStream from 'JSONStream'
import H from 'highland'
const features = fs
.createReadStream('./data/dighimapper.geojson')
.pipe(JSONStream.parse('features.*'))
async function createMap(feature) {
const id = feature.properties.identifier
const batch = feature.properties.batch
const imageUri = `https://images.dighimapper.eu/iiif/2/${id}.tif`
const imageInfoUrl = `${imageUri}/info.json`
let imageInfo
try {
console.error(`Downloading for batch ${batch}:`, imageInfoUrl)
imageInfo = await fetch(imageInfoUrl).then((response) => response.json())
} catch (err) {
console.error(`Error fetching for batch ${batch}:`, imageInfoUrl)
return
}
const pixelMask = [
[0, 0],
[imageInfo.width, 0],
[imageInfo.width, imageInfo.height],
[0, imageInfo.height]
]
const gcps = [
{
world: feature.geometry.coordinates[0][0],
image: pixelMask[0]
},
{
world: feature.geometry.coordinates[0][1],
image: pixelMask[1]
},
{
world: feature.geometry.coordinates[0][2],
image: pixelMask[2]
},
{
world: feature.geometry.coordinates[0][3],
image: pixelMask[3]
}
]
const map = {
version: 1,
image: {
uri: imageUri,
type: 'ImageService2',
width: imageInfo.width,
height: imageInfo.height
},
pixelMask,
gcps
}
return map
}
H(features)
.filter((feature) => feature.geometry)
.flatMap((feature) => H(createMap(feature)))
.compact()
.map(JSON.stringify)
.intersperse('\n')
.pipe(process.stdout)