shp-write: multipolygon bug

I think there is a bug with multipolygon shapes, I started from example/test_multiple_poly.js Open the generated shape in qgis you will see that there is a problem… Is there something wrong in my code ?

var write = require('shp-write').write,
    fs = require('fs');

var features = [];
var points = [];
for (var i=0; i<3; i++) {
  features.push({id: i});
  points.push([[i, 0], [i, 1], [i+1, 1], [i+1, 0], [i, 0]]);
};

console.log(features);
console.log(points);

function finish(err, files) {
    fs.writeFileSync('polygon.shp', toBuffer(files.shp.buffer));
    fs.writeFileSync('polygon.shx', toBuffer(files.shx.buffer));
    fs.writeFileSync('polygon.dbf', toBuffer(files.dbf.buffer));
    fs.writeFileSync('polygon.prj', files.prj);
}

function toBuffer(ab) {
    var buffer = new Buffer(ab.byteLength),
        view = new Uint8Array(ab);
    for (var i = 0; i < buffer.length; ++i) { buffer[i] = view[i]; }
    return buffer;
}

write(
    // feature data
    features,
    // geometry type
    'POLYGON',
    // geometries
    points,
    finish);

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 16 (3 by maintainers)

Most upvoted comments

Thanks for the link, will definitely check it out. Hopefully it doesn’t need any native dependencies as I’m developing a multi-platform app with electron.

@tmcw

Hi, is there any update on this problem? I use shpwrite.zip method and the shapefile produced joins all the polygon, and seems to only add one last feature.properties

I still face it and have been scratching my head over it. Any direction to fix this?