Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function convertGeoJSONtoJSTS(geojson, bufferSize, bufferPolys) {
const geojsonReader = new Reader();
const jstsGeoJSON = geojsonReader.read(geojson);
let geometry;
if (jstsGeoJSON.features) {
const { features } = jstsGeoJSON;
geometry = bufferGeometry(features[0].geometry, bufferSize, bufferPolys);
for (let i = 1; i < features.length; i += 1) {
geometry = UnionOp.union(
geometry,
bufferGeometry(features[i].geometry, bufferSize, bufferPolys),
);
}
} else if (jstsGeoJSON.geometries) {
const { geometries } = jstsGeoJSON;
geometry = bufferGeometry(geometries[0], bufferSize, bufferPolys);
for (let i = 1; i < geometries.length; i += 1) {
geometry = UnionOp.union(
geometry,
bufferGeometry(geometries[i], bufferSize, bufferPolys),
);
}
} else if (jstsGeoJSON.geometry) {
geometry = bufferGeometry(jstsGeoJSON.geometry, bufferSize, bufferPolys);
} else {
let geometry;
if (jstsGeoJSON.features) {
const { features } = jstsGeoJSON;
geometry = bufferGeometry(features[0].geometry, bufferSize, bufferPolys);
for (let i = 1; i < features.length; i += 1) {
geometry = UnionOp.union(
geometry,
bufferGeometry(features[i].geometry, bufferSize, bufferPolys),
);
}
} else if (jstsGeoJSON.geometries) {
const { geometries } = jstsGeoJSON;
geometry = bufferGeometry(geometries[0], bufferSize, bufferPolys);
for (let i = 1; i < geometries.length; i += 1) {
geometry = UnionOp.union(
geometry,
bufferGeometry(geometries[i], bufferSize, bufferPolys),
);
}
} else if (jstsGeoJSON.geometry) {
geometry = bufferGeometry(jstsGeoJSON.geometry, bufferSize, bufferPolys);
} else {
geometry = bufferGeometry(jstsGeoJSON, bufferSize, bufferPolys);
}
return geometry;
}