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 #11 from willemarcel/fix/node-creation-error
Browse files Browse the repository at this point in the history
Avoid error when a node doesn't have lon & lat
  • Loading branch information
Alexander Burkut authored May 19, 2021
2 parents ef292a7 + 2d00fce commit 45f63a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "real-changesets-parser",
"version": "1.3.0",
"version": "1.3.1",
"description": "Convert JSONs returned by osm-adiff-parser to proper geojsons",
"main": "index.js",
"scripts": {
Expand Down
18 changes: 10 additions & 8 deletions parsers/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ function ElementParser(json) {
}

function createNode(data) {
var geometry = [data.lon, data.lat].map(parseFloat);
var properties = R.omit(['lon', 'lat'], data);
return turf.point(geometry, properties);
if (Object.keys(data).includes('lat') && Object.keys(data).includes('lon')) {
var geometry = [data.lon, data.lat].map(parseFloat);
var properties = R.omit(['lon', 'lat'], data);
return turf.point(geometry, properties);
}
}

function createWay(data) {
Expand All @@ -28,7 +30,7 @@ function ElementParser(json) {
}
var geometry = data.nodes
.filter(function(node) {
return Object.keys(node).includes('lat') && Object.keys(node).includes('lon')
return Object.keys(node).includes('lat') && Object.keys(node).includes('lon');
})
.map(function(node) {
return [node.lon, node.lat].map(parseFloat);
Expand All @@ -44,10 +46,10 @@ function ElementParser(json) {

function createRelation(data) {
if ('members' in data) {
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 R.omit(['bbox'], feature);
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 R.omit(['bbox'], feature);
}
return null;
}
Expand Down

0 comments on commit 45f63a6

Please sign in to comment.