Refactor Intersection, Multipolygon from geo to osm

This commit is contained in:
Bryan Housel
2016-10-11 23:09:27 -04:00
parent 07fa5fcc34
commit f50e80d0b5
20 changed files with 111 additions and 106 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
import { geoJoinWays } from '../geo/index';
import { osmJoinWays } from '../osm/index';
export function actionAddMember(relationId, member, memberIndex) {
@@ -9,7 +9,7 @@ export function actionAddMember(relationId, member, memberIndex) {
var members = relation.indexedMembers();
members.push(member);
var joined = geoJoinWays(members, graph);
var joined = osmJoinWays(members, graph);
for (var i = 0; i < joined.length; i++) {
var segment = joined[i];
for (var j = 0; j < segment.length && segment.length >= 2; j++) {
+3 -4
View File
@@ -1,7 +1,6 @@
import _ from 'lodash';
import { actionDeleteWay } from './delete_way';
import { osmIsInterestingTag } from '../osm/index';
import { geoJoinWays } from '../geo/index';
import { osmIsInterestingTag, osmJoinWays } from '../osm/index';
// Join ways at the end node they share.
@@ -32,7 +31,7 @@ export function actionJoin(ids) {
}
}
var joined = geoJoinWays(ways, graph)[0];
var joined = osmJoinWays(ways, graph)[0];
survivor = survivor.update({nodes: _.map(joined.nodes, 'id')});
graph = graph.replace(survivor);
@@ -60,7 +59,7 @@ export function actionJoin(ids) {
if (ids.length < 2 || ids.length !== geometries.line.length)
return 'not_eligible';
var joined = geoJoinWays(ids.map(graph.entity, graph), graph);
var joined = osmJoinWays(ids.map(graph.entity, graph), graph);
if (joined.length > 1)
return 'not_adjacent';
+3 -3
View File
@@ -1,6 +1,6 @@
import _ from 'lodash';
import { geoJoinWays, geoPolygonContainsPolygon } from '../geo/index';
import { osmRelation } from '../osm/index';
import { geoPolygonContainsPolygon } from '../geo/index';
import { osmJoinWays, osmRelation } from '../osm/index';
export function actionMergePolygon(ids, newRelationId) {
@@ -31,7 +31,7 @@ export function actionMergePolygon(ids, newRelationId) {
// Each element is itself an array of objects with an id property, and has a
// locs property which is an array of the locations forming the polygon.
var polygons = entities.multipolygon.reduce(function(polygons, m) {
return polygons.concat(geoJoinWays(m.members, graph));
return polygons.concat(osmJoinWays(m.members, graph));
}, []).concat(entities.closedWay.map(function(d) {
var member = [{id: d.id}];
member.nodes = graph.childNodes(d);
+8 -4
View File
@@ -1,6 +1,10 @@
import { actionSplit } from './split';
import { geoInferRestriction } from '../geo/index';
import { osmRelation, osmWay } from '../osm/index';
import {
osmInferRestriction,
osmRelation,
osmWay
} from '../osm/index';
// Create a restriction relation for `turn`, which must have the following structure:
@@ -17,7 +21,7 @@ import { osmRelation, osmWay } from '../osm/index';
// (The action does not check that these entities form a valid intersection.)
//
// If `restriction` is not provided, it is automatically determined by
// geoInferRestriction.
// osmInferRestriction.
//
// If necessary, the `from` and `to` ways are split. In these cases, `from.node`
// and `to.node` are used to determine which portion of the split ways become
@@ -77,7 +81,7 @@ export function actionRestrictTurn(turn, projection, restrictionId) {
tags: {
type: 'restriction',
restriction: turn.restriction ||
geoInferRestriction(
osmInferRestriction(
graph,
turn.from,
turn.via,
+3 -3
View File
@@ -1,6 +1,6 @@
import _ from 'lodash';
import { osmRelation, osmWay } from '../osm/index';
import { geoIsSimpleMultipolygonOuterMember, geoSphericalDistance } from '../geo/index';
import { osmIsSimpleMultipolygonOuterMember, osmRelation, osmWay } from '../osm/index';
import { geoSphericalDistance } from '../geo/index';
import { actionAddMember } from './add_member';
import { utilWrap } from '../util/index';
@@ -79,7 +79,7 @@ export function actionSplit(nodeId, newWayIds) {
nodesA,
nodesB,
isArea = wayA.isArea(),
isOuter = geoIsSimpleMultipolygonOuterMember(wayA, graph);
isOuter = osmIsSimpleMultipolygonOuterMember(wayA, graph);
if (wayA.isClosed()) {
var nodes = wayA.nodes.slice(0, -1),
-12
View File
@@ -1,18 +1,6 @@
import _ from 'lodash';
export { geoExtent } from './extent.js';
export {
geoIntersection,
geoTurn,
geoInferRestriction
} from './intersection.js';
export {
geoIsSimpleMultipolygonOuterMember,
geoSimpleMultipolygonOuterMember,
geoJoinWays
} from './multipolygon.js';
export { geoRawMercator } from './raw_mercator.js';
+12
View File
@@ -3,6 +3,18 @@ export { osmNode } from './node';
export { osmRelation } from './relation';
export { osmWay } from './way';
export {
osmIntersection,
osmTurn,
osmInferRestriction
} from './intersection.js';
export {
osmIsSimpleMultipolygonOuterMember,
osmSimpleMultipolygonOuterMember,
osmJoinWays
} from './multipolygon.js';
export {
osmOneWayTags,
osmPavedTags,
@@ -1,16 +1,16 @@
import _ from 'lodash';
import { geoAngle } from './index';
import { osmWay } from '../osm/index';
import { geoAngle } from '../geo/index';
import { osmWay } from './way';
export function geoTurn(turn) {
if (!(this instanceof geoTurn))
return new geoTurn(turn);
export function osmTurn(turn) {
if (!(this instanceof osmTurn))
return new osmTurn(turn);
_.extend(this, turn);
}
export function geoIntersection(graph, vertexId) {
export function osmIntersection(graph, vertexId) {
var vertex = graph.entity(vertexId),
parentWays = graph.parentWays(vertex),
coincident = [],
@@ -114,7 +114,7 @@ export function geoIntersection(graph, vertexId) {
}
});
return geoTurn(turn);
return osmTurn(turn);
}
@@ -172,7 +172,7 @@ export function geoIntersection(graph, vertexId) {
}
export function geoInferRestriction(graph, from, via, to, projection) {
export function osmInferRestriction(graph, from, via, to, projection) {
var fromWay = graph.entity(from.way),
fromNode = graph.entity(from.node),
toWay = graph.entity(to.way),
@@ -4,7 +4,7 @@ import { actionReverse } from '../actions/reverse';
// For fixing up rendering of multipolygons with tags on the outer member.
// https://github.com/openstreetmap/iD/issues/613
export function geoIsSimpleMultipolygonOuterMember(entity, graph) {
export function osmIsSimpleMultipolygonOuterMember(entity, graph) {
if (entity.type !== 'way')
return false;
@@ -29,7 +29,7 @@ export function geoIsSimpleMultipolygonOuterMember(entity, graph) {
}
export function geoSimpleMultipolygonOuterMember(entity, graph) {
export function osmSimpleMultipolygonOuterMember(entity, graph) {
if (entity.type !== 'way')
return false;
@@ -66,16 +66,16 @@ export function geoSimpleMultipolygonOuterMember(entity, graph) {
// with appropriate order reversal and start/end coordinate de-duplication.
//
// Members of `array` must have, at minimum, `type` and `id` properties.
// Thus either an array of `iD.Way`s or a relation member array may be
// Thus either an array of `osmWay`s or a relation member array may be
// used.
//
// If an member has a `tags` property, its tags will be reversed via
// `iD.actionReverse` in the output.
// `actionReverse` in the output.
//
// Incomplete members (those for which `graph.hasEntity(element.id)` returns
// false) and non-way members are ignored.
//
export function geoJoinWays(array, graph) {
export function osmJoinWays(array, graph) {
var joined = [], member, current, nodes, first, last, i, how, what;
array = array.filter(function(member) {
+3 -3
View File
@@ -1,9 +1,9 @@
import * as d3 from 'd3';
import _ from 'lodash';
import { osmEntity } from './entity';
import { osmJoinWays } from './multipolygon';
import {
geoExtent,
geoJoinWays,
geoPolygonContainsPolygon,
geoPolygonIntersectsPolygon
} from '../geo/index';
@@ -263,8 +263,8 @@ _.extend(osmRelation.prototype, {
var outers = this.members.filter(function(m) { return 'outer' === (m.role || 'outer'); }),
inners = this.members.filter(function(m) { return 'inner' === m.role; });
outers = geoJoinWays(outers, resolver);
inners = geoJoinWays(inners, resolver);
outers = osmJoinWays(outers, resolver);
inners = osmJoinWays(inners, resolver);
outers = outers.map(function(outer) { return _.map(outer.nodes, 'loc'); });
inners = inners.map(function(inner) { return _.map(inner.nodes, 'loc'); });
+2 -3
View File
@@ -1,7 +1,6 @@
import * as d3 from 'd3';
import _ from 'lodash';
import { geoIsSimpleMultipolygonOuterMember } from '../geo/index';
import { osmEntity } from '../osm/index';
import { osmEntity, osmIsSimpleMultipolygonOuterMember } from '../osm/index';
import { svgPath, svgTagClasses } from './index';
@@ -45,7 +44,7 @@ export function svgAreas(projection, context) {
var entity = entities[i];
if (entity.geometry(graph) !== 'area') continue;
multipolygon = geoIsSimpleMultipolygonOuterMember(entity, graph);
multipolygon = osmIsSimpleMultipolygonOuterMember(entity, graph);
if (multipolygon) {
areas[multipolygon.id] = {
entity: multipolygon.mergeTags(entity.tags),
+2 -3
View File
@@ -7,8 +7,7 @@ import {
svgTagClasses
} from './index';
import { geoSimpleMultipolygonOuterMember } from '../geo/index';
import { osmEntity } from '../osm/index';
import { osmEntity, osmSimpleMultipolygonOuterMember } from '../osm/index';
import { utilDetect } from '../util/detect';
@@ -43,7 +42,7 @@ export function svgLines(projection) {
for (var i = 0; i < entities.length; i++) {
var entity = entities[i],
outer = geoSimpleMultipolygonOuterMember(entity, graph);
outer = osmSimpleMultipolygonOuterMember(entity, graph);
if (outer) {
ways.push(entity.mergeTags(outer.tags));
} else if (entity.geometry(graph) === 'line') {
+12 -9
View File
@@ -2,7 +2,13 @@ import * as d3 from 'd3';
import { t } from '../../util/locale';
import { behaviorHover } from '../../behavior/index';
import { osmEntity } from '../../osm/index';
import {
osmEntity,
osmIntersection,
osmInferRestriction,
osmTurn
} from '../../osm/index';
import {
actionRestrictTurn,
@@ -11,10 +17,7 @@ import {
import {
geoExtent,
geoIntersection,
geoRawMercator,
geoTurn,
geoInferRestriction
geoRawMercator
} from '../../geo/index';
import {
@@ -59,7 +62,7 @@ export function uiFieldRestrictions(field, context) {
.attr('class', 'restriction-help');
var intersection = geoIntersection(context.graph(), vertexID),
var intersection = osmIntersection(context.graph(), vertexID),
graph = intersection.graph,
vertex = graph.entity(vertexID),
filter = utilFunctor(true),
@@ -131,7 +134,7 @@ export function uiFieldRestrictions(field, context) {
if (datum instanceof osmEntity) {
fromNodeID = intersection.adjacentNodeId(datum.id);
render();
} else if (datum instanceof geoTurn) {
} else if (datum instanceof osmTurn) {
if (datum.restriction) {
context.perform(
actionUnrestrictTurn(datum, projection),
@@ -149,7 +152,7 @@ export function uiFieldRestrictions(field, context) {
function mouseover() {
var datum = d3.event.target.__data__;
if (datum instanceof geoTurn) {
if (datum instanceof osmTurn) {
var graph = context.graph(),
presets = context.presets(),
preset;
@@ -158,7 +161,7 @@ export function uiFieldRestrictions(field, context) {
preset = presets.match(graph.entity(datum.restriction), graph);
} else {
preset = presets.item('type/restriction/' +
geoInferRestriction(
osmInferRestriction(
graph,
datum.from,
datum.via,