Skip to content

Commit

Permalink
fix and test deduplication of ways with different versions
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrasd committed Aug 28, 2016
1 parent e6e80a5 commit beb94fd
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ osmtogeojson = function( data, options ) {
has_interesting_tags(node.tags)) // this checks if the node has any tags other than "created_by"
poinids[node.id] = true;
}
// todo -> after deduplication of relations??
for (var i=0;i<rels.length;i++) {
if (_.isArray(rels[i].members)) {
for (var j=0;j<rels[i].members.length;j++) {
Expand All @@ -516,6 +517,7 @@ osmtogeojson = function( data, options ) {
wayids[way.id] = way;
if (_.isArray(way.nodes)) {
for (var j=0;j<way.nodes.length;j++) {
if (typeof way.nodes[j] === "object") continue; // ignore already replaced way node objects
waynids[way.nodes[j]] = true;
way.nodes[j] = nodeids[way.nodes[j]];
}
Expand Down Expand Up @@ -838,6 +840,11 @@ osmtogeojson = function( data, options ) {
}
// process lines and polygons
for (var i=0;i<ways.length;i++) {
// todo: refactor such that this loops over wayids instead of ways?
if (wayids[ways[i].id] !== ways[i]) {
// skip way because it's a deduplication artifact
continue;
}
if (!_.isArray(ways[i].nodes)) {
if (options.verbose) console.warn('Way',ways[i].type+'/'+ways[i].id,'ignored because it has no nodes');
continue; // ignore ways without nodes (e.g. returned by an ids_only query)
Expand Down
59 changes: 58 additions & 1 deletion test/osm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3623,6 +3623,63 @@ describe("duplicate elements", function () {
expect(geojson.features[0].geometry.coordinates).to.have.length(2);
});

it("way, different versions", function () {
var json, geojson;

// do not include full geometry nd's as node in output
json = {
elements: [
{
type: "way",
id: 1,
version: 1,
nodes: [1,2],
tags: {
"foo": "bar",
"dupe": "x"
}
},
{
type: "way",
id: 1,
version: 2,
nodes: [1,2,3],
tags: {
"asd": "fasd",
"dupe": "y"
}
},
{
type: "node",
id: 1,
lat: 1,
lon: 1
},
{
type: "node",
id: 2,
lat: 2,
lon: 2
},
{
type: "node",
id: 3,
lat: 3,
lon: 3
}
]
};
geojson = osmtogeojson.toGeojson(json);

expect(geojson.features.length).to.eql(1);
expect(geojson.features[0].id).to.eql("way/1");
expect(geojson.features[0].properties.meta.version).to.eql(2);
expect(geojson.features[0].properties.tags.foo).to.be(undefined);
expect(geojson.features[0].properties.tags.dupe).to.eql("y");
expect(geojson.features[0].properties.tags.asd).to.eql("fasd");
expect(geojson.features[0].geometry.coordinates).to.have.length(3);
});

it("relation", function () {
var json, geojson;

Expand Down Expand Up @@ -3688,7 +3745,7 @@ describe("duplicate elements", function () {
expect(geojson.features[0].properties.tags.foo).to.eql("2");
});

it("node, different version", function () {
it("custom deduplicator", function () {
var json, geojson;

// do not include full geometry nd's as node in output
Expand Down

0 comments on commit beb94fd

Please sign in to comment.