Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"name": "twkb",
"description": "TWKB format reader",
"version": "0.2.0",
"version": "0.2.1",
"homepage": "https://github.com/TWKB/twkb.js",
"repository": {
"type": "git",
Expand All @@ -30,17 +30,20 @@
"main": "index.js",
"scripts": {
"build": "rollup -c",
"test": "NODE_ENV=test eslint src && NODE_ENV=test mocha --compilers js:babel-register --recursive test"
"test": "NODE_ENV=test eslint src && NODE_ENV=test mocha -r @babel/register --recursive test"
},
"devDependencies": {
"@babel/core": "7.4.5",
"@babel/preset-env": "7.4.5",
"@babel/register": "7.4.4",
"babel-core": "6.26.3",
"babel-preset-env": "1.7.0",
"babel-register": "6.26.0",
"eslint": "4.19.1",
"mocha": "5.1.1",
"rollup": "0.58.2",
"rollup-plugin-babel": "3.0.4",
"rollup-plugin-uglify": "3.0.0"
"eslint": "5.16.0",
"mocha": "6.1.4",
"rollup": "1.14.2",
"rollup-plugin-babel": "4.3.2",
"rollup-plugin-terser": "5.0.0"
},
"optionalDependencies": {},
"standard": {
Expand Down
6 changes: 3 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import babel from 'rollup-plugin-babel'
import uglify from 'rollup-plugin-uglify'
import { terser } from 'rollup-plugin-terser'

export default {
input: 'src/twkb.js',
Expand All @@ -10,6 +10,6 @@ export default {
},
plugins: [
babel(),
uglify()
terser()
]
}
}
35 changes: 35 additions & 0 deletions test/twkb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,32 @@ describe('twkb', function () {
})
})

it('should decode a collection of multipolygons to geojson', function () {
// select encode(st_astwkb(array_agg(geom::geometry), array_agg(id)), 'hex') from (select 0 as id, 'multipolygon(((5 47,5 43,11 43,11 47,5 47)),((-1 50,-1 45,4 45,4 50,-1 50)))' as geom union all select 1 as id, 'multipolygon(((-5 29,-11 29,-11 34,-5 34,-5 29)),((-10 41,-10 36,-4 36,-4 41,-10 41)))' as geom) a;
var g = twkb.toGeoJSON(new Buffer('070402000206000201050a5e00070c0000080b0001050b0600090a00000a09000600020105093a0b00000a0c0000090105091800090c00000a0b00', 'hex'))
assert.deepEqual(g, {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
id: 0,
geometry: {
type: 'MultiPolygon',
coordinates: [[[[5,47],[5,43],[11,43],[11,47],[5,47]]],[[[-1,50],[-1,45],[4,45],[4,50],[-1,50]]]]
}
},
{
type: 'Feature',
id: 1,
geometry: {
type: 'MultiPolygon',
coordinates: [[[[-5,29],[-11,29],[-11,34],[-5,34],[-5,29]]],[[[-10,41],[-10,36],[-4,36],[-4,41],[-10,41]]]]
}
}
]
})
})

it('should read multiple features', function () {
var g = twkb.toGeoJSON(Buffer.from('0200020202080802000202020808', 'hex'))
assert.equal(g.features.length, 2)
Expand Down Expand Up @@ -198,5 +224,14 @@ describe('twkb', function () {
assert.equal(f.geoms[1].type, LINESTRING)
})

it('should decode a collection of multipolygons', function () {
// select st_astwkb(array_agg(geom::geometry), array_agg(id)) from (select 0 as id, 'multipolygon(((5 47,5 43,11 43,11 47,5 47)),((-1 50,-1 45,4 45,4 50,-1 50)))' as geom union all select 1 as id, 'multipolygon(((-5 29,-11 29,-11 34,-5 34,-5 29)),((-10 41,-10 36,-4 36,-4 41,-10 41)))' as geom) a;
var f = twkb.read(new Buffer('070402000206000201050a5e00070c0000080b0001050b0600090a00000a09000600020105093a0b00000a0c0000090105091800090c00000a0b00', 'hex'))[0]
assert.equal(f.type, COLLECTION)
assert.equal(f.geoms.length, 2)
assert.equal(f.geoms[0].type, MULTIPOLYGON)
assert.equal(f.geoms[1].type, MULTIPOLYGON)
})

})
})
Loading