Skip to content

Commit e324dd7

Browse files
committed
Bugfix: Zipping geojson with multilelinestring+linestring and multipolygon+polygon now saves all
1 parent 3c255ae commit e324dd7

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

Diff for: src/geojson.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function justType(gjType, shpType) {
1414
return function (gj) {
1515
var oftype = gj.features.filter(isType(gjType));
1616
return {
17-
geometries: shpType === 'POLYLINE' ? oftype.map(l => [justCoords(l)]) : oftype.map(justCoords),
17+
geometries: shpType === 'POLYLINE' ? [oftype.map(justCoords)] : oftype.map(justCoords),
1818
properties: oftype.map(justProps),
1919
type: shpType,
2020
};

Diff for: src/zip.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,28 @@ module.exports = function (
1818
var prj = (options && options.prj) ? options.prj : defaultPrj;
1919

2020
[
21-
geojson.point(gj),
22-
geojson.line(gj),
23-
geojson.polygon(gj),
24-
geojson.multipolygon(gj),
25-
geojson.multiline(gj),
26-
].forEach(function (l) {
27-
if (l.geometries.length && l.geometries[0].length) {
28-
write(
21+
[geojson.point(gj)],
22+
[geojson.line(gj), geojson.multiline(gj)],
23+
[geojson.polygon(gj), geojson.multipolygon(gj)],
24+
].forEach(function (l) {
25+
if ((l[0].geometries.length && l[0].geometries[0].length) || l[1] && l[1].geometries.length && l[1].geometries[0].length) {
26+
27+
const properties = l.flatMap(l => l.properties);
28+
const geometries = l.flatMap(l => l.geometries);
29+
const type = l[0].type;
30+
31+
write(
2932
// field definitions
30-
l.properties,
33+
properties,
3134
// geometry type
32-
l.type,
35+
l[0].type,
3336
// geometries
34-
l.geometries,
37+
geometries,
3538
function (err, files) {
3639
var fileName =
37-
options && options.types && options.types[l.type.toLowerCase()]
38-
? options.types[l.type.toLowerCase()]
39-
: l.type;
40+
options && options.types && options.types[type.toLowerCase()]
41+
? options.types[type.toLowerCase()]
42+
: type;
4043
zipTarget.file(fileName + ".shp", files.shp.buffer, { binary: true });
4144
zipTarget.file(fileName + ".shx", files.shx.buffer, { binary: true });
4245
zipTarget.file(fileName + ".dbf", files.dbf.buffer, { binary: true });

0 commit comments

Comments
 (0)