Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function polygonDissolve(geojson, options) {
if (options === void 0) { options = {}; }
// Validation
if (invariant_1.getType(geojson) !== "FeatureCollection") {
throw new Error("geojson must be a FeatureCollection");
}
if (!geojson.features.length) {
throw new Error("geojson is empty");
}
// Clone geojson to avoid side effects
// Topojson modifies in place, so we need to deep clone first
if (options.mutate === false || options.mutate === undefined) {
geojson = clone_1.default(geojson);
}
var geoms = [];
meta_1.flattenEach(geojson, function (feature) {
geoms.push(feature.geometry);
});
var topo = topojson_1.topology({ geoms: helpers_1.geometryCollection(geoms).geometry });
var merged = topojson_1.merge(topo, topo.objects.geoms.geometries);
return merged;
}
exports.default = polygonDissolve;
// Optional parameters
options = options || {};
if (!helpers_1.isObject(options)) {
throw new Error("options is invalid");
}
var mutate = options.mutate;
// Validation
if (invariant_1.getType(geojson) !== "FeatureCollection") {
throw new Error("geojson must be a FeatureCollection");
}
if (!geojson.features.length) {
throw new Error("geojson is empty");
}
// Clone geojson to avoid side effects
if (mutate === false || mutate === undefined) {
geojson = clone_1.default(geojson);
}
var result = [];
var lastLine = meta_1.lineReduce(geojson, function (previousLine, currentLine) {
// Attempt to merge this LineString with the other LineStrings, updating
// the reference as it is merged with others and grows.
var merged = mergeLineStrings(previousLine, currentLine);
// Accumulate the merged LineString
if (merged) {
return merged;
// Put the unmerged LineString back into the list
}
else {
result.push(previousLine);
return currentLine;
}
});
options = options || {};
if (!helpers_1.isObject(options)) {
throw new Error("options is invalid");
}
var mutate = options.mutate;
// Validation
if (invariant_1.getType(geojson) !== "FeatureCollection") {
throw new Error("geojson must be a FeatureCollection");
}
if (!geojson.features.length) {
throw new Error("geojson is empty");
}
// Clone geojson to avoid side effects
// Topojson modifies in place, so we need to deep clone first
if (mutate === false || mutate === undefined) {
geojson = clone_1.default(geojson);
}
// Assert homogenity
var type = getHomogenousType(geojson);
if (!type) {
throw new Error("geojson must be homogenous");
}
// Data => Typescript hack
var data = geojson;
switch (type) {
case "LineString":
return turf_line_dissolve_1.default(data, options);
case "Polygon":
return turf_polygon_dissolve_1.default(data, options);
default:
throw new Error(type + " is not supported");
}