mapbox / shp-write

create and write to shapefiles in pure javascript
BSD 3-Clause "New" or "Revised" License
292 stars 186 forks source link

multipolygon bug #17

Closed christophemacabiau closed 11 months ago

christophemacabiau commented 9 years ago

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);
jseppi commented 9 years ago

Your for loop only generates 3 points but you are writing feature data of length 5

christophemacabiau commented 9 years ago

sorry! I have updated the code

galharth commented 7 years ago

@cricri Have you solved this problem?

christophemacabiau commented 7 years ago

nope :-(

gxcodes commented 7 years ago

@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?

christophemacabiau commented 7 years ago

maybe you can use https://github.com/naturalatlas/node-gdal, which works fine for my use case

gxcodes commented 7 years ago

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 commented 7 years ago

I no longer maintain this module - contact Mapbox for assistance or support.

gxcodes commented 7 years ago

Hi @cricri do you have sample usage for the node-gdal link? This multipolygon bug is a real bummer. I'm stuck with an empty zip file if I try to save a multipolygon shape.

christophemacabiau commented 7 years ago

Hi @gxcodes, I added an example to create a shape using node-gdal https://github.com/naturalatlas/node-gdal/pull/205/commits/870b44b45075f41f7eae325b077392f5bada1aa5

gxcodes commented 7 years ago

@cricri thanks a lot! Really appreciate it.

danleydmello commented 6 years ago

Any update or fix for this bug?. The multipolygons are joined in the shape file.

serifea commented 6 years ago

I have a problem also multipolygon!!!!

I download polygon but coudn't for multipolygon

Is there any UPDATE????

Pllsss help !!!

hwbllmnn commented 5 years ago

65 possibly fixes your problem.

chwahab commented 2 years ago

Use Turf.js and flat your GeoJSON. shpwrite.download(turf.flatten(geojson))

sheindel commented 11 months ago

I know this is quite an old issue, but we should finally have this resolved as part of v0.4.0 (to be released soon, hopefully) https://github.com/mapbox/shp-write/releases/tag/v0.4.0