mapbox / mapbox/shp-write

Seperate linestrings are being combined into one multi-linestring.

Open
#117 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
321
Forks
195
PR merge metrics
No merged PRs in 30d

Description

When I try to use the package and export the shapefile of multiple linestrings, it automatically combines the linestrings into one single multi-linestring.
```js
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
```js
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.

Contributor guide

Open the contributing guide

Research direction

Start in src/geojson.js around line 17 and reproduce the issue with the FeatureCollection in the report. Check that separate LineString features remain separate in the exported shapefile while actual MultiLineString geometries are still handled correctly; done means the example produces two line features without regressing multi-line inputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.