Permalink
Browse files

fix and test deduplication of ways with different versions

  • Loading branch information...
1 parent e6e80a5 commit beb94fdda0ccebff67393615581f870b381a2c29 @tyrasd committed Aug 28, 2016
Showing with 65 additions and 1 deletion.
  1. +7 −0 index.js
  2. +58 −1 test/osm.test.js
View
@@ -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++) {
@@ -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]];
}
@@ -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)
View
@@ -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;
@@ -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

0 comments on commit beb94fd

Please sign in to comment.