forked from ninnghazad/hipims-ocl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DomainBNG.js
99 lines (86 loc) · 2.91 KB
/
DomainBNG.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict';
var DomainBase = require('./DomainBase');
var BngTile = require('./BngTile');
var rasterTools = require('./RasterTools');
var downloadTools = require('./DownloadTools');
function DomainBNG (parentModel, cb) {
DomainBase.apply(this, Array.prototype.slice.call(arguments));
this.tiles = this.extent.getBngTileNames();
this.domainPrepare(cb);
};
DomainBNG.prototype = new DomainBase();
DomainBNG.prototype.domainPrepare = function (cb) {
console.log('--> Preparing domain data...');
this.bngTiles = {};
this.bngTileCount = this.tiles.length;
this.bngTileDone = 0;
this.clipDone = false;
this.clipCallback = cb;
this.tiles.forEach((tileName) => {
this.bngTiles[tileName] = new BngTile(tileName);
this.bngTiles[tileName].requireTile(this.domainPrepareTileFinished.bind(this));
});
};
DomainBNG.prototype.domainPrepareTileFinished = function (tileName) {
this.bngTileDone++;
console.log(' Tile ' + tileName + ' required for the domain is now ready.');
if (this.bngTileDone >= this.bngTileCount) {
console.log(' All tiles required for the domain are now ready.');
this.domainPrepareFinished();
}
};
DomainBNG.prototype.domainPrepareFinished = function (tileName) {
// Make a single VRT for the DTM and the DEM
rasterTools.mergeToVRT(
downloadTools.getDirectoryPath() + 'DOMAIN_DTM.vrt',
this.tiles.map((t) => { return downloadTools.getDirectoryPath() + t + '_DTM.vrt' }),
(err) => {
if (err) {
console.log(' Error creating a single DTM VRT for the whole domain area.');
} else {
console.log(' Whole domain DTM is now ready.');
this.domainReadyDTM = true;
if (this.domainReadyDEM && this.domainReadyDTM) this.domainClip();
}
}
);
rasterTools.mergeToVRT(
downloadTools.getDirectoryPath() + 'DOMAIN_DEM.vrt',
this.tiles.map((t) => { return downloadTools.getDirectoryPath() + t + '_DEM.vrt' }),
(err) => {
if (err) {
console.log(' Error creating a single DEM VRT for the whole domain area.');
} else {
console.log(' Whole domain DEM is now ready.');
this.domainReadyDEM = true;
if (this.domainReadyDEM && this.domainReadyDTM) this.domainClip();
}
}
);
};
DomainBNG.prototype.domainClip = function () {
console.log('--> Preparing to clip the domain...');
rasterTools.clipRaster(
downloadTools.getDirectoryPath() + 'DOMAIN_DEM.vrt',
downloadTools.getDirectoryPath() + 'CLIP_DTM.img',
'HFA',
this.extent,
(success) => {
if (success) {
this.clipDone = true;
this.domainClipFinished();
} else {
console.log(' An error occured clipping the domain.');
if (this.clipCallback) this.clipCallback(false);
}
}
);
}
DomainBNG.prototype.domainClipFinished = function () {
console.log(' Domain clipping is now complete.');
if (this.clipCallback) this.clipCallback(true);
}
DomainBNG.prototype.getPathTopography = function () {
return downloadTools.getDirectoryPath() + 'CLIP_DTM.img';
}
module.exports = DomainBNG;