mapbox / shp-write

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

Seperate linestrings are being combined into one multi-linestring. #117

Open junyi2022 opened 11 months ago

junyi2022 commented 11 months ago

When I try to use the package and export the shapefile of multiple linestrings, it automatically combines the linestrings into one single multi-linestring.

const data = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {"id": 1},
      "geometry": {
        "coordinates": [
          [ 15.732725333712267, 18.51499012275039 ], [ 29.796471779359706, 18.19539060475546 ]
        ],
        "type": "LineString"
      }
    },
    {
      "type": "Feature",
      "properties": {"id": 2},
      "geometry": {
        "coordinates": [
          [ 16.008079368924513, 13.843031299450175 ], [ 29.25915144646919, 9.310680918508353 ]
        ],
        "type": "LineString"
      }
    }
  ]
}
const shpOptions = { outputType: 'blob'};
const blob = await shpwrite.zip( data, shpOptions);

The blob above will contain one multi-linestring. However, I expect to have two linestrings.

In the library, I changed the following line

https://github.com/mapbox/shp-write/blob/48a0fe72c09f74f6256ac8d4177af272d01317c3/src/geojson.js#L17

to

      geometries: shpType === 'POLYLINE' ? oftype.map(l => [justCoords(l)]) : oftype.map(justCoords),

This solved the issue to me, but not sure how it will do to actual multi-linestrings.