forked from joseamidesfigueroa/ojo-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimerg_regions.js
44 lines (38 loc) · 865 Bytes
/
imerg_regions.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
// Convert imerg_regions to geojson
var fs = require('fs')
var inputFileName = 'imerg_regions.yaml'
var outputFileName = 'imerg_regions.geojson'
var imerg_regions = JSON.parse( fs.readFileSync(inputFileName))
var regions = {
type: 'FeatureCollection',
features: []
}
function ToPolygons(bbox) {
var poly = [
[bbox[0], bbox[1]],
[bbox[2], bbox[1]],
[bbox[2], bbox[3]],
[bbox[0], bbox[3]],
[bbox[0], bbox[1]]
]
return poly
}
for( var r in imerg_regions.regions) {
var region = imerg_regions.regions[r]
var feature = {
type: 'Feature',
id: region.id,
properties: {
name: region.name,
},
geometry: {
type: "Polygon",
coordinates: [
ToPolygons(region.bbox)
]
}
}
regions.features.push(feature)
}
fs.writeFileSync(outputFileName, JSON.stringify(regions,null,'\t'), 'utf-8')
console.log("Generated", outputFileName)