-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoGeojson.js
62 lines (55 loc) · 1.92 KB
/
toGeojson.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
const decompress = require("decompress");
const edigeoTogeojson = require("edigeo-to-geojson");
const fromText = _path => {
const pathBz = path.join(__dirname, _path);
const filesNames = fs.readdirSync(pathBz);
const bufferData = {
THF: undefined,
QAL: undefined,
GEO: undefined,
SCD: undefined,
VEC: []
};
for (let i = 0; i < filesNames.length; i++) {
if (/\.THF$/.test(filesNames[i])) {
bufferData.THF = fs.readFileSync(path.join(pathBz, filesNames[i]));
} else if (/\.VEC$/.test(filesNames[i])) {
bufferData.VEC.push(fs.readFileSync(path.join(pathBz, filesNames[i])));
} else if (/\.QAL$/.test(filesNames[i])) {
bufferData.QAL = fs.readFileSync(path.join(pathBz, filesNames[i]));
} else if (/\.GEO$/.test(filesNames[i])) {
bufferData.GEO = fs.readFileSync(path.join(pathBz, filesNames[i]));
} else if (/\.SCD$/.test(filesNames[i])) {
bufferData.SCD = fs.readFileSync(path.join(pathBz, filesNames[i]));
}
}
return edigeoTogeojson(bufferData);
};
const fromCompressed = async _path => {
const files = await decompress(_path);
const bufferData = {
THF: undefined,
QAL: undefined,
GEO: undefined,
SCD: undefined,
VEC: []
};
for (let i = 0; i < files.length; i++) {
if (/\.THF$/.test(files[i].path)) {
bufferData.THF = files[i].data;
} else if (/\.VEC$/.test(files[i].path)) {
bufferData.VEC.push(files[i].data);
} else if (/\.QAL$/.test(files[i].path)) {
bufferData.QAL = files[i].data;
} else if (/\.GEO$/.test(files[i].path)) {
bufferData.GEO = files[i].data;
} else if (/\.SCD$/.test(files[i].path)) {
bufferData.SCD = files[i].data;
}
}
if (!bufferData.THF){
return null;
}
return edigeoTogeojson(bufferData);
};
module.exports = { fromText, fromCompressed }