add validation for almost junction

but avoid connect when the edge goes in parallel to the other road.
also added tests for the validation.
This commit is contained in:
Xiaoming Gao
2018-12-20 15:08:23 -05:00
parent 70d5529a58
commit ecacab3ffe
7 changed files with 314 additions and 2 deletions

View File

@@ -930,6 +930,9 @@ en:
crossing_ways:
message: Crossing ways without connection
tooltip: "Roads are crossing other roads, buildings, railroads, or waterways without connection nodes or a bridge tag."
highway_almost_junction:
message: Almost junction
tooltip: "This node is very close but not connected to way {wid}."
fix:
delete_feature:
title: Delete this feature

View File

@@ -1117,6 +1117,10 @@
"message": "Crossing ways without connection",
"tooltip": "Roads are crossing other roads, buildings, railroads, or waterways without connection nodes or a bridge tag."
},
"highway_almost_junction": {
"message": "Almost junction",
"tooltip": "This node is very close but not connected to way {wid}."
},
"fix": {
"delete_feature": {
"title": "Delete this feature"

View File

@@ -0,0 +1,115 @@
import {
geoExtent,
geoLineIntersection,
geoMetersToLat,
geoMetersToLon,
geoSphericalDistance,
geoVecInterp,
} from '../geo';
import { set as d3_set } from 'd3-collection';
import { t } from '../util/locale';
import {
ValidationIssueType,
ValidationIssueSeverity,
validationIssue,
} from './validation_issue';
/**
* Look for roads that can be connected to other roads with a short extension
*/
export function validationHighwayAlmostJunction() {
function isHighway(entity) {
return entity.type === 'way' && entity.tags.highway;
}
function findConnectableEndNodesByExtension(way, graph, tree) {
var results = [],
nidFirst = way.nodes[0],
nidLast = way.nodes[way.nodes.length - 1],
nodeFirst = graph.entity(nidFirst),
nodeLast = graph.entity(nidLast);
if (nidFirst === nidLast) return results;
if (!nodeFirst.tags.noexit && graph.parentWays(nodeFirst).length === 1) {
var widNearFirst = canConnectByExtend(way, 0, graph, tree);
if (widNearFirst !== null) {
results.push({
node: nodeFirst,
wid: widNearFirst,
});
}
}
if (!nodeLast.tags.noexit && graph.parentWays(nodeLast).length === 1) {
var widNearLast = canConnectByExtend(way, way.nodes.length - 1, graph, tree);
if (widNearLast !== null) {
results.push({
node: nodeLast,
wid: widNearLast,
});
}
}
return results;
}
function canConnectByExtend(way, endNodeIdx, graph, tree) {
var EXTEND_TH_METERS = 5,
tipNid = way.nodes[endNodeIdx], // the 'tip' node for extension point
midNid = endNodeIdx === 0 ? way.nodes[1] : way.nodes[way.nodes.length - 2], // the other node of the edge
tipNode = graph.entity(tipNid),
midNode = graph.entity(midNid),
lon = tipNode.loc[0],
lat = tipNode.loc[1],
lon_range = geoMetersToLon(EXTEND_TH_METERS, lat) / 2,
lat_range = geoMetersToLat(EXTEND_TH_METERS) / 2,
queryExtent = geoExtent([
[lon - lon_range, lat - lat_range],
[lon + lon_range, lat + lat_range]
]);
// first, extend the edge of [midNode -> tipNode] by EXTEND_TH_METERS and find the "extended tip" location
var edgeLen = geoSphericalDistance(midNode.loc, tipNode.loc),
t = EXTEND_TH_METERS / edgeLen + 1.0,
extTipLoc = geoVecInterp(midNode.loc, tipNode.loc, t);
// then, check if the extension part [tipNode.loc -> extTipLoc] intersects any other ways
var intersected = tree.intersects(queryExtent, graph);
for (var i = 0; i < intersected.length; i++) {
if (!isHighway(intersected[i]) || intersected[i].id === way.id) continue;
var way2 = intersected[i];
for (var j = 0; j < way2.nodes.length - 1; j++) {
var nA = graph.entity(way2.nodes[j]),
nB = graph.entity(way2.nodes[j + 1]);
if (geoLineIntersection([tipNode.loc, extTipLoc], [nA.loc, nB.loc])) {
return way2.id;
}
}
}
return null;
}
var validation = function(changes, graph, tree) {
var edited = changes.created.concat(changes.modified),
issues = [];
for (var i = 0; i < edited.length; i++) {
if (!isHighway(edited[i])) continue;
var extendableNodes = findConnectableEndNodesByExtension(edited[i], graph, tree);
for (var j = 0; j < extendableNodes.length; j++) {
issues.push(new validationIssue({
type: ValidationIssueType.highway_almost_junction,
severity: ValidationIssueSeverity.warning,
message: t('issues.highway_almost_junction.message'),
tooltip: t('issues.highway_almost_junction.tooltip', {wid: extendableNodes[j].wid}),
entities: [extendableNodes[j].node, graph.entity(extendableNodes[j].wid)],
coordinates: extendableNodes[j].node.loc,
}));
}
}
return issues;
};
return validation;
}

View File

@@ -1,6 +1,7 @@
export { validationDeprecatedTag } from './deprecated_tag';
export { validationDisconnectedHighway } from './disconnected_highway';
export { validationHighwayCrossingOtherWays } from './crossing_ways';
export { validationHighwayAlmostJunction } from './highway_almost_junction';
export { ValidationIssueType, ValidationIssueSeverity } from './validation_issue';
export { validationManyDeletions } from './many_deletions';
export { validationMapCSSChecks } from './mapcss_checks';

View File

@@ -10,7 +10,8 @@ var ValidationIssueType = Object.freeze({
old_multipolygon: 'old_multipolygon',
tag_suggests_area: 'tag_suggests_area',
map_rule_issue: 'map_rule_issue',
crossing_ways: 'crossing_ways'
crossing_ways: 'crossing_ways',
highway_almost_junction: 'highway_almost_junction',
});
@@ -47,7 +48,7 @@ export function validationIssue(attrs) {
this.tooltip = attrs.tooltip;
this.entities = attrs.entities; // expect an array of entities
this.coordinates = attrs.coordinates; // expect a [lon, lat] array
this.info = attrs.info; // an object containing arbitrary extra information
this.info = attrs.info; // an object containing arbitrary extra information
this.fixes = attrs.fixes; // expect an array of functions for possible fixes
if (this.fixes) {

View File

@@ -149,6 +149,7 @@
<script src='spec/validations/disconnected_highway.js'></script>
<script src='spec/validations/tag_suggests_area.js'></script>
<script src='spec/validations/crossing_ways.js'></script>
<script src='spec/validations/highway_almost_junction.js'></script>
<script src='spec/operations/detach_node.js'></script>
<script>
window.mocha.run();

View File

@@ -0,0 +1,187 @@
describe('iD.validations.highway_almost_junction', function () {
var context;
beforeEach(function() {
context = iD.Context();
});
function horizontalVertialCloserThanThd() {
// horizontal road
var n1 = iD.Node({id: 'n-1', loc: [22.42357, 0]});
var n2 = iD.Node({id: 'n-2', loc: [22.42367, 0]});
var w1 = iD.Way({id: 'w-1', nodes: ['n-1', 'n-2'], tags: { highway: 'residential' }});
context.perform(
iD.actionAddEntity(n1),
iD.actionAddEntity(n2),
iD.actionAddEntity(w1)
);
// vertical road to the west of w1 by 0.00001 logitude degree
// 5th digit after decimal point has a resolution of ~1 meter
var n3 = iD.Node({id: 'n-3', loc: [22.42356, 0.001]});
var n4 = iD.Node({id: 'n-4', loc: [22.42356, -0.001]});
var w2 = iD.Way({id: 'w-2', nodes: ['n-3', 'n-4'], tags: { highway: 'residential' }});
context.perform(
iD.actionAddEntity(n3),
iD.actionAddEntity(n4),
iD.actionAddEntity(w2)
);
}
function horizontalTiltedCloserThanThd() {
// horizontal road
var n1 = iD.Node({id: 'n-1', loc: [22.42357, 0]});
var n2 = iD.Node({id: 'n-2', loc: [22.42367, 0]});
var w1 = iD.Way({id: 'w-1', nodes: ['n-1', 'n-2'], tags: { highway: 'residential' }});
context.perform(
iD.actionAddEntity(n1),
iD.actionAddEntity(n2),
iD.actionAddEntity(w1)
);
// tilted road to the west of w1 by 0.00001 logitude degree
var n3 = iD.Node({id: 'n-3', loc: [22.423555, 0.001]});
var n4 = iD.Node({id: 'n-4', loc: [22.423565, -0.001]});
var w2 = iD.Way({id: 'w-2', nodes: ['n-3', 'n-4'], tags: { highway: 'residential' }});
context.perform(
iD.actionAddEntity(n3),
iD.actionAddEntity(n4),
iD.actionAddEntity(w2)
);
}
function horizontalVertialFurtherThanThd() {
// horizontal road
var n1 = iD.Node({id: 'n-1', loc: [22.42357, 0]});
var n2 = iD.Node({id: 'n-2', loc: [22.42367, 0]});
var w1 = iD.Way({id: 'w-1', nodes: ['n-1', 'n-2'], tags: { highway: 'residential' }});
context.perform(
iD.actionAddEntity(n1),
iD.actionAddEntity(n2),
iD.actionAddEntity(w1)
);
// vertical road to the west of w1 by 0.00007 logitude degree
var n3 = iD.Node({id: 'n-3', loc: [22.42350, 0.001]});
var n4 = iD.Node({id: 'n-4', loc: [22.42350, -0.001]});
var w2 = iD.Way({id: 'w-2', nodes: ['n-3', 'n-4'], tags: { highway: 'residential' }});
context.perform(
iD.actionAddEntity(n3),
iD.actionAddEntity(n4),
iD.actionAddEntity(w2)
);
}
function twoHorizontalCloserThanThd() {
// horizontal road
var n1 = iD.Node({id: 'n-1', loc: [22.42357, 0]});
var n2 = iD.Node({id: 'n-2', loc: [22.42367, 0]});
var w1 = iD.Way({id: 'w-1', nodes: ['n-1', 'n-2'], tags: { highway: 'residential' }});
context.perform(
iD.actionAddEntity(n1),
iD.actionAddEntity(n2),
iD.actionAddEntity(w1)
);
// another horizontal road to the north of w1 by 0.0001 latitude degree
var n3 = iD.Node({id: 'n-3', loc: [22.42357, 0.00001]});
var n4 = iD.Node({id: 'n-4', loc: [22.42367, 0.00001]});
var w2 = iD.Way({id: 'w-2', nodes: ['n-3', 'n-4'], tags: { highway: 'residential' }});
context.perform(
iD.actionAddEntity(n3),
iD.actionAddEntity(n4),
iD.actionAddEntity(w2)
);
}
function horizontalVertialWithNoExit() {
// horizontal road
var n1 = iD.Node({id: 'n-1', loc: [22.42357, 0], tags: { noexit: 'yes' }});
var n2 = iD.Node({id: 'n-2', loc: [22.42367, 0]});
var w1 = iD.Way({id: 'w-1', nodes: ['n-1', 'n-2'], tags: { highway: 'residential' }});
context.perform(
iD.actionAddEntity(n1),
iD.actionAddEntity(n2),
iD.actionAddEntity(w1)
);
// vertical road to the west of w1 by 0.00001 logitude degree
var n3 = iD.Node({id: 'n-3', loc: [22.42356, 0.001]});
var n4 = iD.Node({id: 'n-4', loc: [22.42356, -0.001]});
var w2 = iD.Way({id: 'w-2', nodes: ['n-3', 'n-4'], tags: { highway: 'residential' }});
context.perform(
iD.actionAddEntity(n3),
iD.actionAddEntity(n4),
iD.actionAddEntity(w2)
);
}
function validate() {
var validator = iD.validationHighwayAlmostJunction();
var changes = context.history().changes();
return validator(changes, context.graph(), context.history().tree());
}
it('has no errors on init', function() {
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('horizontal and vertical road, closer than threshold', function() {
horizontalVertialCloserThanThd();
var issues = validate();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql(iD.ValidationIssueType.highway_almost_junction);
expect(issue.entities).to.have.lengthOf(2);
expect(issue.entities[0].id).to.eql('n-1');
expect(issue.entities[1].id).to.eql('w-2');
expect(issue.coordinates).to.have.lengthOf(2);
expect(issue.coordinates[0]).to.eql(22.42357);
expect(issue.coordinates[1]).to.eql(0);
});
it('horizontal and tilted road, closer than threshold', function() {
horizontalTiltedCloserThanThd();
var issues = validate();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql(iD.ValidationIssueType.highway_almost_junction);
expect(issue.entities).to.have.lengthOf(2);
expect(issue.entities[0].id).to.eql('n-1');
expect(issue.entities[1].id).to.eql('w-2');
expect(issue.coordinates).to.have.lengthOf(2);
expect(issue.coordinates[0]).to.eql(22.42357);
expect(issue.coordinates[1]).to.eql(0);
});
it('horizontal and vertical road, further than threshold', function() {
horizontalVertialFurtherThanThd();
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('horizontal and vertical road, closer than threshold but with noexit tag', function() {
horizontalVertialWithNoExit();
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('two horizontal roads, closer than threshold', function() {
twoHorizontalCloserThanThd();
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
});