-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
open_shp.test.js
88 lines (80 loc) · 2.46 KB
/
open_shp.test.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
const gdal = require('../lib/gdal.js')
const path = require('path')
const assert = require('chai').assert
describe('Open', () => {
afterEach(gc)
describe('ESRI Shapefile', () => {
let filename, ds
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
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
before(() => {
integerDs = gdal.open(
path.join(__dirname, 'data/shp/sample_int64.shp')
)
integerLayer = integerDs.layers.get(0)
})
it('should evaluate datatypes', () => {
const version_major = Number(gdal.version.split('.')[0])
assert.equal(integerLayer.fields.get(0).type, 'string')
assert.equal(
integerLayer.fields.get(3).type,
version_major >= 2 ? 'integer64' : 'integer'
)
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)
})
})
})
})
})