/** * @param nodeA the node to compure the distance for * @return the distance */ private double getMetric(final Node nodeA) { double dist = Coordinate.distance( nodeA.getLatitude(), nodeA.getLongitude(), this.targetNode.getLatitude(), this.targetNode.getLongitude()); return dist; }
/** * Determines if a way lies within the bounding box. * * @param boundingBox The bounding box. * @param nodes The ordered nodes of the way in order. * @return True if the way is at least partially within the box. */ private boolean isWayInsideBox(Rectangle2D boundingBox, List<Node> nodes) { // If at least one node lies within the box, the way is inside the box. for (Node node : nodes) { if (isNodeInsideBox(boundingBox, node)) { return true; } } // Now we need to check if any of the segments cross the box. for (int i = 0; i < nodes.size() - 1; i++) { Node nodeA; Node nodeB; nodeA = nodes.get(i); nodeB = nodes.get(i + 1); if (boundingBox.intersectsLine( nodeA.getLongitude(), nodeA.getLatitude(), nodeB.getLongitude(), nodeB.getLatitude())) { return true; } } return false; }
/** * Determines if a node lies within the bounding box. * * @param boundingBox The bounding box. * @param node The node to be checked. * @return True if the node lies within the box. */ private boolean isNodeInsideBox(Rectangle2D boundingBox, Node node) { return boundingBox.contains(node.getLongitude(), node.getLatitude()); }
private void convertToOwnRepresentation() { ownNodes = new ArrayList<OSMNode>(nodesById.size()); ownWays = new ArrayList<OSMWay>(waysById.size()); ownRelations = new ArrayList<OSMRelation>(relationsById.size()); Map<Node, OSMNode> nodeMap = new HashMap<Node, OSMNode>(); Map<Way, OSMWay> wayMap = new HashMap<Way, OSMWay>(); Map<Relation, OSMRelation> relationMap = new HashMap<Relation, OSMRelation>(); for (Node node : nodesById.values()) { OSMNode ownNode = new OSMNode( node.getLatitude(), node.getLongitude(), tagGroupForEntity(node), node.getId()); ownNodes.add(ownNode); nodeMap.put(node, ownNode); } for (Way way : waysById.values()) { List<WayNode> origWayNodes = way.getWayNodes(); List<OSMNode> wayNodes = new ArrayList<OSMNode>(origWayNodes.size()); for (WayNode origWayNode : origWayNodes) { Node origNode = nodesById.get(origWayNode.getNodeId()); if (origNode != null) { wayNodes.add(nodeMap.get(origNode)); } } OSMWay ownWay = new OSMWay(tagGroupForEntity(way), way.getId(), wayNodes); ownWays.add(ownWay); wayMap.put(way, ownWay); } for (Relation relation : relationsById.values()) { OSMRelation ownRelation = new OSMRelation( tagGroupForEntity(relation), relation.getId(), relation.getMembers().size()); ownRelations.add(ownRelation); relationMap.put(relation, ownRelation); } // add relation members // (needs to be done *after* creation because relations can be members // of other relations) for (Relation relation : relationMap.keySet()) { OSMRelation ownRelation = relationMap.get(relation); for (org.openstreetmap.osmosis.core.domain.v0_6.RelationMember member : relation.getMembers()) { OSMElement memberObject = null; if (member.getMemberType() == EntityType.Node) { memberObject = nodeMap.get(nodesById.get(member.getMemberId())); } else if (member.getMemberType() == EntityType.Way) { memberObject = wayMap.get(waysById.get(member.getMemberId())); } else if (member.getMemberType() == EntityType.Relation) { memberObject = relationMap.get(relationsById.get(member.getMemberId())); } else { continue; } if (memberObject != null) { OSMMember ownMember = new OSMMember(member.getMemberRole(), memberObject); ownRelation.relationMembers.add(ownMember); } } } // give up references to original collections nodesById = null; waysById = null; relationsById = null; }