mapbox / shp-write

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

Error when export 2 or more Linestring geometries #44

Closed antoniocdff closed 10 months ago

antoniocdff commented 7 years ago

Hello! I'm trying to generate a shape file from Geojson below but it only generates a result (a geometric feature and a line in the data table). In other cases (polygon and dot) the export normally occurs inside my code.

{ "type": "FeatureCollection", "features": [{ "type": "Feature", "id": "eixo_logradouro_via.4961521", "properties": { "cd_eixo_logradouro_viario": 4961521, "sigla_fonte_original": "SMDU", "tx_logradouro_valido": null, "cd_logradouro_valido": null, "tx_classificacao_viaria_eixo": "COLETORA", "tx_observacao_eixo": null }, "geometry": { "type": "LineString", "coordinates": [
                [343345.429316384, 7392170.4119967],
                [343394.385137341, 7392153.78531118],
                [343423.451882614, 7392145.63693662]
            ] } }, { "type": "Feature", "id": "eixo_logradouro_via.4961522", "properties": { "cd_eixo_logradouro_viario": 4961522, "sigla_fonte_original": "SMDU", "tx_logradouro_valido": null, "cd_logradouro_valido": null, "tx_classificacao_viaria_eixo": "LOCAL", "tx_observacao_eixo": null }, "geometry": { "type": "LineString", "coordinates": [
                [343423.451882614, 7392145.63693662],
                [343480.966930678, 7392134.6891244]
            ] } }, { "type": "Feature", "id": "eixo_logradouro_via.4961523", "properties": { "cd_eixo_logradouro_viario": 4961523, "sigla_fonte_original": "SMDU", "tx_logradouro_valido": null, "cd_logradouro_valido": null, "tx_classificacao_viaria_eixo": "LOCAL", "tx_observacao_eixo": null }, "geometry": { "type": "LineString", "coordinates": [
                [343480.966930678, 7392134.6891244],
                [343531.126650327, 7392120.27200005]
            ] } }] }

Here is the snippet of my code:

arquivo = shpwrite.zip(shapes);
nomearquivo = _getFileName(queryparams.Layer.Name);
saveAs(arquivo, nomearquivo + ".zip");
cld-santos commented 7 years ago

As a complement. The resulting shapefile seems to merge all those three features, passed as parameters, then those features are cast to one row.

ximex commented 7 years ago

Change this: https://github.com/mapbox/shp-write/blob/master/src/geojson.js#L7-L12 to:

var oftype = gj.features.filter(isType(type));
var geometries;
if (TYPE === 'POLYGON') {
    geometries = [oftype.map(justCoords)];
} else if (TYPE === 'POLYLINE') {
    geometries = oftype.map(function(t) { return [justCoords(t)]; });
} else {
    geometries = oftype.map(justCoords);
}
return {
    geometries: geometries,
    properties: oftype.map(justProps),
    type: TYPE
};
alex116 commented 7 years ago

@ximex Thank you very much sir, that seems to have fixed it.

TBusan commented 3 years ago

大神,收下我的膝盖,苦苦调了好久的原因,一直以为是 setInt32 这个方法里面的偏移出现了问题。

sheindel commented 10 months ago

This should be resolved now, feel free to test against the latest version (v.0.4.0, not available on npm yet, hopefully soon)

sheindel commented 10 months ago

Good news: v0.4.2 is now available.

Less good news: Mapbox changed their deployment organization so this package is now hosted under a different package

@mapbox/shp-write https://unpkg.com/@mapbox/shp-write@latest/shpwrite.js