forked from yocontra/node-gdal-next
-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathopen_shp.test.ts
100 lines (90 loc) · 2.9 KB
/
open_shp.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
import * as gdal from 'gdal-async'
import * as path from 'path'
import { assert } from 'chai'
describe('Open', () => {
afterEach(() => void global.gc!())
describe('ESRI Shapefile', () => {
let filename, ds: gdal.Dataset
it('should not throw', () => {
filename = path.join(__dirname, 'data/shp/sample.shp')
ds = gdal.open(filename)
})
it('should be able to read layer count', () => {
assert.equal(ds.layers.count(), 1)
})
describe('layer', () => {
let layer: gdal.Layer
before(() => {
layer = ds.layers.get(0)
})
it('should have all fields defined', () => {
assert.equal(layer.fields.count(), 8)
assert.deepEqual(layer.fields.getNames(), [
'path',
'name',
'type',
'long_name',
'fips_num',
'fips',
'state_fips',
'state_abbr'
])
})
describe('field properties', () => {
let integerDs, integerLayer: gdal.Layer
before(() => {
integerDs = gdal.open(
path.join(__dirname, 'data/shp/sample_int64.shp')
)
integerLayer = integerDs.layers.get(0)
})
it('should evaluate datatypes', () => {
assert.equal(integerLayer.fields.get(0).type, 'string')
assert.equal(integerLayer.fields.get(3).type, 'integer64')
assert.equal(integerLayer.fields.get(5).type, 'real')
assert.equal(integerLayer.fields.get(10).type, 'date')
})
})
describe('features', () => {
it('should be readable', () => {
assert.equal(layer.features.count(), 23)
const feature = layer.features.get(0)
const fields = feature.fields.toObject()
assert.deepEqual(fields, {
fips: 'US56029',
fips_num: '56029',
long_name: 'Park County',
name: 'Park',
path: 'US.WY.PARK',
state_abbr: 'WY',
state_fips: '56',
type: 'County'
})
})
})
describe('integer64 fields', () => {
it('should be readable', () => {
const integerDs = gdal.open(
path.join(__dirname, 'data/shp/sample_int64.shp')
)
const integerLayer = integerDs.layers.get(0)
assert.equal(integerLayer.features.get(0).fields.get(3), 1)
})
})
describe('null fields', () => {
let nullDs, nullFeature: gdal.Feature
before(() => {
nullDs = gdal.open(
path.join(__dirname, 'data/shp/sample_null.shp')
)
nullFeature = nullDs.layers.get(0).features.get(0)
})
it('should return null value', () => {
assert.equal(nullFeature.fields.get('id'), null)
assert.equal(nullFeature.fields.get('name'), null)
assert.equal(nullFeature.fields.get('value'), null)
})
})
})
})
})