Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from willemarcel/update-turf-libs
Browse files Browse the repository at this point in the history
Update turf libs
  • Loading branch information
Manohar Erikipati authored Dec 9, 2020
2 parents 64f8339 + ee9ffc5 commit ef292a7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ var changesetParser = R.pipe(

changesetParser.elementParser = elementParser;
module.exports = changesetParser;

34 changes: 19 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
}
Expand Down
19 changes: 13 additions & 6 deletions parsers/element.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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')
Expand All @@ -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));
}
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit ef292a7

Please sign in to comment.