Skip to content
This repository was archived by the owner on Dec 30, 2019. It is now read-only.

Commit 7dac71b

Browse files
committed
add support for converting GeometryCollections
1 parent 74fbe03 commit 7dac71b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

spec/wktSpec.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,22 @@ describe("WKT Convert", function () {
350350
expect(output).toEqual("MULTIPOLYGON EMPTY");
351351
});
352352

353+
it("should convert a GEOMETRYCOLLECTION", function(){
354+
var input = {
355+
"type": "GeometryCollection",
356+
"geometries": [
357+
{ "type": "Point",
358+
"coordinates": [100.0, 0.0]
359+
},
360+
{ "type": "LineString",
361+
"coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
362+
}
363+
]
364+
}
365+
var output = Terraformer.WKT.convert(input);
366+
expect(output).toEqual('GEOMETRYCOLLECTION(POINT (100 0), LINESTRING (101 0, 102 1))');
367+
});
368+
353369
it("should fail a conversion on an unknown type", function () {
354370
var input = { "type": "MultiPolygonLikeThingy",
355371
"coordinates": [ ]
@@ -714,5 +730,4 @@ describe("WKT Parser", function() {
714730
expect(output).toBeInstanceOfClass(Terraformer.MultiPolygon);
715731
expect(output.type).toEqual("MultiPolygon");
716732
});
717-
718733
});

src/module-source.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,18 @@
304304
return multiLineStringToWKTMultiLineString(primitive);
305305
case 'MultiPolygon':
306306
return multiPolygonToWKTMultiPolygon(primitive);
307+
case 'GeometryCollection':
308+
var ret = 'GEOMETRYCOLLECTION';
309+
var parts = [ ];
310+
for (i = 0; i < primitive.geometries.length; i++){
311+
parts.push(convert(primitive.geometries[i]));
312+
}
313+
return ret + '(' + parts.join(', ') + ')';
307314
default:
308315
throw Error ("Unknown Type: " + primitive.type);
309316
}
310317
}
311318

312-
313-
314319
exports.parser = parser;
315320
exports.Parser = parser.Parser;
316321
exports.parse = parse;

0 commit comments

Comments
 (0)