From ee9ffc563ed54ce91c351b443e6e6f50f068f677 Mon Sep 17 00:00:00 2001 From: Wille Marcel Date: Wed, 9 Dec 2020 10:26:59 -0300 Subject: [PATCH] update turf libs --- index.js | 1 - package-lock.json | 34 +++++++++++++++++++--------------- package.json | 8 ++++---- parsers/element.js | 19 +++++++++++++------ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index dcf7e87..4ae5cf0 100644 --- a/index.js +++ b/index.js @@ -11,4 +11,3 @@ var changesetParser = R.pipe( changesetParser.elementParser = elementParser; module.exports = changesetParser; - diff --git a/package-lock.json b/package-lock.json index 4ca390a..369689c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,34 +1,38 @@ { "name": "real-changesets-parser", - "version": "1.2.4", + "version": "1.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { "@turf/bbox": { - "version": "3.14.0", - "resolved": "https://registry.npmjs.org/@turf/bbox/-/bbox-3.14.0.tgz", - "integrity": "sha1-zuXzlt3nisqc7eBeESLbGLxQRjU=", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@turf/bbox/-/bbox-6.0.1.tgz", + "integrity": "sha512-EGgaRLettBG25Iyx7VyUINsPpVj1x3nFQFiGS3ER8KCI1MximzNLsam3eXRabqQDjyAKyAE1bJ4EZEpGvspQxw==", "requires": { - "@turf/meta": "^3.14.0" + "@turf/helpers": "6.x", + "@turf/meta": "6.x" } }, "@turf/bbox-polygon": { - "version": "3.14.0", - "resolved": "https://registry.npmjs.org/@turf/bbox-polygon/-/bbox-polygon-3.14.0.tgz", - "integrity": "sha1-0ASwRT8IDo9PV19h3JNjIMVldHo=", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@turf/bbox-polygon/-/bbox-polygon-6.0.1.tgz", + "integrity": "sha512-f6BK6GOzUNjmJeOYHklk/5LNcQMQbo51gvAM10dTM5IqzKP01KM5bgV88uOKfSZB0HRQVpaRV1tgXk2bg5cPRg==", "requires": { - "@turf/helpers": "^3.13.0" + "@turf/helpers": "6.x" } }, "@turf/helpers": { - "version": "3.13.0", - "resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-3.13.0.tgz", - "integrity": "sha1-0GB4oUZM9WzbfqYk6h4TpxuIuAY=" + "version": "6.1.4", + "resolved": "https://registry.npmjs.org/@turf/helpers/-/helpers-6.1.4.tgz", + "integrity": "sha512-vJvrdOZy1ngC7r3MDA7zIGSoIgyrkWcGnNIEaqn/APmw+bVLF2gAW7HIsdTxd12s5wQMqEpqIQrmrbRRZ0xC7g==" }, "@turf/meta": { - "version": "3.14.0", - "resolved": "https://registry.npmjs.org/@turf/meta/-/meta-3.14.0.tgz", - "integrity": "sha1-jTBQwaD0S/QGpjO2vSjFEPe87ic=" + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@turf/meta/-/meta-6.0.2.tgz", + "integrity": "sha512-VA7HJkx7qF1l3+GNGkDVn2oXy4+QoLP6LktXAaZKjuT1JI0YESat7quUkbCMy4zP9lAUuvS4YMslLyTtr919FA==", + "requires": { + "@turf/helpers": "6.x" + } }, "array-filter": { "version": "1.0.0", diff --git a/package.json b/package.json index 97278b5..20d6b6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "real-changesets-parser", - "version": "1.2.4", + "version": "1.3.0", "description": "Convert JSONs returned by osm-adiff-parser to proper geojsons", "main": "index.js", "scripts": { @@ -20,9 +20,9 @@ "tape": "^5.0.1" }, "dependencies": { - "@turf/bbox": "^3.13.0", - "@turf/bbox-polygon": "^3.13.0", - "@turf/helpers": "^3.13.0", + "@turf/bbox": "^6.0.1", + "@turf/bbox-polygon": "^6.0.1", + "@turf/helpers": "^6.1.4", "id-area-keys": "^2.17.3", "ramda": "^0.27.1" } diff --git a/parsers/element.js b/parsers/element.js index e35c178..35bd720 100644 --- a/parsers/element.js +++ b/parsers/element.js @@ -1,7 +1,7 @@ var R = require('ramda'); var turf = require('@turf/helpers'); -var createBbox = require('@turf/bbox'); -var createBboxPolygon = require('@turf/bbox-polygon'); +var createBbox = require('@turf/bbox').default; +var createBboxPolygon = require('@turf/bbox-polygon').default; var ak = require('id-area-keys'); function ElementParser(json) { @@ -23,6 +23,9 @@ function ElementParser(json) { } function createWay(data) { + if (data.nodes.length === 0) { + return; + } var geometry = data.nodes .filter(function(node) { return Object.keys(node).includes('lat') && Object.keys(node).includes('lon') @@ -33,9 +36,9 @@ function ElementParser(json) { var properties = R.omit(['nodes'], data); if (data.tags && ak.isArea(data.tags) && isClosedWay(data.nodes)) { - return turf.polygon([geometry], properties); + return R.omit(['bbox'], turf.polygon([geometry], properties)); } else { - return turf.lineString(geometry, properties); + return R.omit(['bbox'], turf.lineString(geometry, properties)); } } @@ -44,7 +47,7 @@ function ElementParser(json) { data.relations = data.members.map(createFeature).filter(R.complement(R.isNil)); // filter out nulls var feature = createBboxPolygon(createBbox(turf.featureCollection(data.relations))); feature.properties = R.omit(['members'], data); - return feature; + return R.omit(['bbox'], feature); } return null; } @@ -93,7 +96,11 @@ function isClosedWay(nodes) { if (nodes.length > 3) { var firstNode = nodes[0]; var lastNode = nodes[nodes.length - 1]; - return (firstNode.lat === lastNode.lat && firstNode.lon === lastNode.lon); + return ( + Object.keys(firstNode).includes('lat') && Object.keys(firstNode).includes('lon') && + Object.keys(lastNode).includes('lat') && Object.keys(lastNode).includes('lon') && + firstNode.lat === lastNode.lat && firstNode.lon === lastNode.lon + ); } return false; }