Search in sources :

Example 1 with Position

use of aimax.osm.data.Position in project aima-java by aimacode.

the class RouteCalculator method calculateRoute.

/**
	 * Template method, responsible for shortest path generation between two map
	 * nodes. It searches for way nodes in the vicinity of the given nodes which
	 * comply with the specified way selection, searches for a suitable paths,
	 * and adds the paths as tracks to the provided <code>map</code>. Various
	 * factory methods can be used to override aspects of the default behavior
	 * in subclasses if needed.
	 * 
	 * @param markers
	 *            Nodes, not necessarily way nodes. The first node is used as
	 *            start, last node as finish, all others as via nodes.
	 * @param map
	 *            The information source.
	 * @param taskSelection
	 *            Number, indicating which kinds of ways are relevant.
	 */
public List<Position> calculateRoute(List<MapNode> markers, OsmMap map, int taskSelection) {
    List<Position> result = new ArrayList<>();
    try {
        MapWayFilter wayFilter = createMapWayFilter(map, taskSelection);
        boolean ignoreOneways = (taskSelection == 0);
        List<MapNode[]> pNodeList = subdivideProblem(markers, map, wayFilter);
        MapNode prevNode = null;
        for (int i = 0; i < pNodeList.size() && !CancelableThread.currIsCanceled(); i++) {
            Problem<MapNode, OsmMoveAction> problem = createProblem(pNodeList.get(i), map, wayFilter, ignoreOneways, taskSelection);
            ToDoubleFunction<Node<MapNode, OsmMoveAction>> h = createHeuristicFunction(pNodeList.get(i), taskSelection);
            SearchForActions<MapNode, OsmMoveAction> search = createSearch(h, taskSelection);
            List<OsmMoveAction> actions = search.findActions(problem);
            if (actions.isEmpty())
                break;
            for (Object action : actions) {
                if (action instanceof OsmMoveAction) {
                    OsmMoveAction a = (OsmMoveAction) action;
                    for (MapNode node : a.getNodes()) {
                        if (prevNode != node) {
                            result.add(new Position(node.getLat(), node.getLon()));
                            prevNode = node;
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
Also used : MapWayFilter(aimax.osm.data.MapWayFilter) Position(aimax.osm.data.Position) Node(aima.core.search.framework.Node) MapNode(aimax.osm.data.entities.MapNode) ArrayList(java.util.ArrayList) MapNode(aimax.osm.data.entities.MapNode)

Example 2 with Position

use of aimax.osm.data.Position in project aima-java by aimacode.

the class DefaultEntityRenderer method getNextNode.

/**
	 * Returns the map node which is the nearest with respect to the specified
	 * view coordinates among the currently displayed nodes.
	 */
public MapNode getNextNode(int x, int y) {
    Position pos = new Position(transformer.lat(y), transformer.lon(x));
    MapNode nextNode = null;
    MapNode tmp = null;
    for (int i = 0; i < 2; i++) {
        List<MapWay> ways = (i == 0) ? areaBuffer : wayBuffer;
        for (MapWay way : ways) {
            tmp = pos.selectNearest(way.getNodes(), null);
            if (nextNode == null || pos.getDistKM(tmp) < pos.getDistKM(nextNode)) {
                nextNode = tmp;
            }
        }
    }
    for (MapEntity node : nodeBuffer) {
        if (node instanceof MapNode) {
            tmp = (MapNode) node;
            if (tmp != null && tmp.getAttributeValue("marker") == null && (nextNode == null || pos.getDistKM(tmp) < pos.getDistKM(nextNode))) {
                nextNode = tmp;
            }
        }
    }
    return nextNode;
}
Also used : MapWay(aimax.osm.data.entities.MapWay) Position(aimax.osm.data.Position) MapNode(aimax.osm.data.entities.MapNode) MapEntity(aimax.osm.data.entities.MapEntity)

Example 3 with Position

use of aimax.osm.data.Position in project aima-java by aimacode.

the class FindPanel method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == findButton) {
        entityFinder = view.getMap().getEntityFinder();
        Position pos = view.getCenterPosition();
        String pattern = findField.getText();
        switch(typeCombo.getSelectedIndex()) {
            case 0:
                entityFinder.findEntity(pattern, pos);
                break;
            case 1:
                entityFinder.findNode(pattern, pos);
                break;
            case 2:
                entityFinder.findWay(pattern, pos, null);
                break;
            case 3:
                entityFinder.findAddress(pattern, pos);
                break;
        }
        storedMarkers.addAll(currMarkers);
        currMarkers.clear();
    } else if (e.getSource() == findMoreButton) {
        if (!entityFinder.getIntermediateResults().isEmpty()) {
            List<MapEntity> entities = getSelectedEntities();
            if (entities.size() == 1)
                entityFinder.selectIntermediateResult(entities.get(0));
        }
        entityFinder.findMore();
    } else if (e.getSource() == clearButton) {
        entityFinder = null;
    }
    updateResults(entityFinder == null);
    updateEnabledState();
}
Also used : Position(aimax.osm.data.Position) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with Position

use of aimax.osm.data.Position in project aima-java by aimacode.

the class MapAdapter method getDistance.

@Override
public Double getDistance(String fromLocation, String toLocation) {
    MapNode node1 = getWayNode(fromLocation);
    MapNode node2 = getWayNode(toLocation);
    if (node1 != null && node2 != null && getPossibleNextLocations(fromLocation).contains(toLocation))
        return new Position(node1).getDistKM(node2);
    else
        return null;
}
Also used : Position(aimax.osm.data.Position) MapNode(aimax.osm.data.entities.MapNode)

Example 5 with Position

use of aimax.osm.data.Position in project aima-java by aimacode.

the class OsmRoutePlannerApp method calculateRoute.

/** Starts route generation after the calculate button has been pressed. */
public void calculateRoute() {
    OsmMap map = mapPaneCtrl.getMap();
    List<Position> positions = routeCalculator.calculateRoute(map.getMarkers(), map, taskCombo.getSelectionModel().getSelectedIndex());
    mapPaneCtrl.getMap().createTrack("Route", positions);
    statusLabel.setText(getTrackInfo(mapPaneCtrl.getMap().getTrack("Route")));
}
Also used : OsmMap(aimax.osm.data.OsmMap) Position(aimax.osm.data.Position)

Aggregations

Position (aimax.osm.data.Position)17 MapNode (aimax.osm.data.entities.MapNode)12 MapEntity (aimax.osm.data.entities.MapEntity)3 MapAdapter (aimax.osm.routing.MapAdapter)3 ArrayList (java.util.ArrayList)3 MapEvent (aimax.osm.data.MapEvent)2 OsmMap (aimax.osm.data.OsmMap)2 MapWay (aimax.osm.data.entities.MapWay)2 Node (aima.core.search.framework.Node)1 BoundingBox (aimax.osm.data.BoundingBox)1 MapWayFilter (aimax.osm.data.MapWayFilter)1 Track (aimax.osm.data.entities.Track)1 DecimalFormat (java.text.DecimalFormat)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1