Skip to content

Conversion for feature collections from TWKB to GeoJSON looks wrong #30

@savv

Description

@savv

The following code sample includes a repro. I start with a TWKB string generated using PostGIS, then compare the outputs of two libraries, wkx and twkb.

twkb yields the expected result, with 5 vertices. wkx generates one polygon (instead of two), with 912 vertices (instead of 5).

var wkx = require('wkx');
var twkb = require('twkb');

/* NOTE: generated from the following query:
 * select encode(st_astwkb(
 *   ARRAY['POLYGON((25.9601817282581 48.0424439290235,25.9665092948186 48.0409189127411,25.9689305626008 48.0454493856918,25.9624693171852 48.046795992248,25.9601817282581 48.0424439290235))'::GEOMETRY, 'POLYGON((25.9601817282581 48.0424439290235,25.9665092948186 48.0409189127411,25.9689305626008 48.0454493856918,25.9624693171852 48.046795992248,25.9601817282581 48.0424439290235))'::GEOMETRY]::geometry[]
 *   , ARRAY[123, 456], 5
 *   ), 'base64');
 */
var base64 = 'pgQC9gGQBwEF5PK8Aqi6ygTyCa8C5AOKB4sKjgLJA+cGAQUAAPIJrwLkA4oHiwqOAskD5wY=';

var buf = Buffer.from(base64, 'base64');


console.log('====== twkb:');
var twkbRes = twkb.toGeoJSON(buf);
console.log('twkb num features:', twkbRes.features.length);
console.log('twkb feature ids:', twkbRes.features.map(x => x.id));
console.log('twkb coords per feature:', twkbRes.features.map(x => x.geometry.coordinates[0].length));
console.log(JSON.stringify(twkbRes, null, 2));

console.log('====== wkx:');
var wkxRes = wkx.Geometry.parseTwkb(buf);
console.log('wkx num features:', wkxRes.polygons.length);
console.log('wkx feature ids:', wkxRes.polygons.map(x => x.id));
console.log('wkx coords per feature (ext ring):', wkxRes.polygons.map(x => x.exteriorRing.length));
// console.log(JSON.stringify(wkxRes, null, 2));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions