-
Notifications
You must be signed in to change notification settings - Fork 46
/
index_test.ts
155 lines (143 loc) · 4.98 KB
/
index_test.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import test from "blue-tape"
import {
createReadStream,
createWriteStream,
ReadStream,
statSync,
writeFileSync,
} from "fs"
import ogr2ogr from "./"
let dir = __dirname + "/testdata/"
test(async (t) => {
const vers = await ogr2ogr.version()
t.match(vers, /^GDAL /)
interface TT {
file?: string
url?: string
out?: string
opts?: string[]
dest?: string
stream?: boolean
success: boolean
}
let table: TT[] = [
// URL tests.
{
url: "https://gist.github.com/wavded/7376428/raw/971548233e441615a426794c766223488492ddb9/test.geojson",
success: true,
},
{
url: "https://gist.github.com/wavded/7376428/raw/971548233e441615a426794c766223488492ddb9/test.georss",
success: true,
},
// From format conversions.
{file: "sample.bad", success: false},
{file: "sample.empty.zip", success: false},
{file: "sample.000", success: true},
{file: "sample.csv", success: true},
{file: "sample.dbf", success: true},
{file: "sample.dgn", success: true},
{file: "sample.dxf", success: true},
{file: "sample.gdb.zip", out: "dxf", success: true},
{file: "sample.geojson", success: true},
{file: "sample.gml", success: true},
{file: "sample.gmt", success: true},
{file: "sample.gxt", success: true},
{file: "sample.itf", success: true},
{file: "sample.json", success: true},
{file: "sample.jml", stream: true, success: true},
{file: "sample.kml", success: true},
{file: "sample.kmz", success: true},
{file: "sample.cryllic.kml", success: true},
{file: "sample.map.zip", success: true},
{file: "sample.mapml", stream: true, success: true},
{file: "sample.rss", success: true},
{file: "sample.rti.zip", out: "dxf", success: true},
{file: "sample.shp", success: true},
{file: "sample.shp.zip", success: true},
{file: "sample.large.shp.zip", success: true},
{file: "sample.vdv", stream: true, success: true},
// Using custom options.
{
file: "sample.no-shx.shp",
opts: ["--config", "SHAPE_RESTORE_SHX", "TRUE"],
success: true,
},
{
file: "sample.geom.csv",
opts: ["-oo", "GEOM_POSSIBLE_NAMES=the_geom"],
success: true,
},
// To format conversions.
{file: "sample.json", success: true, out: "csv"},
{file: "sample.json", success: true, out: "dgn"},
{file: "sample.json", success: true, out: "dxf"},
{file: "sample.json", success: true, out: "esri shapefile"},
{file: "sample.json", success: true, out: "flatgeobuf"},
{file: "sample.json", success: true, out: "geoconcept"},
{file: "sample.json", success: true, out: "geojson"},
{file: "sample.json", success: true, out: "geojsonseq"},
{file: "sample.json", success: true, out: "georss"},
{file: "sample.json", success: true, out: "gml"},
{file: "sample.json", success: true, out: "gmt"},
{file: "sample.json", success: true, out: "gpkg"},
{file: "sample.json", success: true, out: "gpx"},
{file: "sample.json", success: true, out: "jml"},
{file: "sample.json", success: true, out: "kml"},
{file: "sample.json", success: true, out: "mapml"},
{file: "sample.json", success: true, out: "mapinfo file"},
{file: "sample.json", success: true, out: "ods"},
{file: "sample.json", success: true, out: "pdf"},
{file: "sample.json", success: true, out: "vdv"},
{file: "sample.json", success: true, out: "xlsx"},
// Known supported stream conversions.
{file: "sample.csv", stream: true, success: false},
{file: "sample.json", stream: true, success: true},
{file: "sample.rss", stream: true, success: true},
{file: "sample.gml", stream: true, success: true},
{file: "sample.gmt", stream: true, success: true},
{file: "sample.gpx", stream: true, success: true},
{file: "sample.jml", stream: true, success: true},
{file: "sample.kml", stream: true, success: true},
{file: "sample.mapml", stream: true, success: true},
{file: "sample.vdv", stream: true, success: true},
// Custom destinations. (e.g. database)
{
file: "sample.json",
success: true,
dest: dir + "output/custom.geojson",
},
]
for (let tt of table) {
try {
let input: string | ReadStream = tt.url ? tt.url : dir + tt.file
if (tt.stream) {
input = createReadStream(input)
}
let res = await ogr2ogr(input, {
format: tt.out,
options: tt.opts,
destination: tt.dest,
maxBuffer: 1024 * 1024 * 1024,
})
if (tt.dest) {
statSync(tt.dest)
t.pass()
} else if (!tt.out) {
t.equal(res.data && res.data.type, "FeatureCollection", res.cmd)
} else {
t.ok(res.text || res.stream, res.cmd)
let fn = dir + "output/r_" + tt.out + res.extname
if (res.stream) {
res.stream.pipe(createWriteStream(fn))
} else {
writeFileSync(fn, res.text)
}
}
t.ok(tt.success)
} catch (err) {
console.log(err)
t.notOk(tt.success)
}
}
})