Search in sources :

Example 6 with Position

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

the class OsmRoutePlannerApp method getTrackInfo.

protected String getTrackInfo(Track track) {
    List<MapNode> nodes = track.getNodes();
    DecimalFormat f1 = new DecimalFormat("#0.00");
    double km = Position.getTrackLengthKM(nodes);
    String info = track.getName() + ": Length " + f1.format(km) + " km";
    if (nodes.size() == 2) {
        DecimalFormat f2 = new DecimalFormat("#000");
        MapNode m1 = nodes.get(nodes.size() - 2);
        MapNode m2 = nodes.get(nodes.size() - 1);
        int course = new Position(m1).getCourseTo(m2);
        info += "; Direction " + f2.format(course);
    }
    return info;
}
Also used : Position(aimax.osm.data.Position) DecimalFormat(java.text.DecimalFormat) MapNode(aimax.osm.data.entities.MapNode)

Example 7 with Position

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

the class OsmLRTAStarAgentApp method updateTrack.

/** Visualizes agent positions. Call from simulation thread. */
private void updateTrack(Agent agent, Metrics metrics) {
    MapAdapter map = (MapAdapter) env.getMap();
    MapNode node = map.getWayNode(env.getAgentLocation(agent));
    if (node != null) {
        Platform.runLater(() -> map.getOsmMap().addToTrack(TRACK_NAME, new Position(node.getLat(), node.getLon())));
    }
    simPaneCtrl.setStatus(metrics.toString());
}
Also used : Position(aimax.osm.data.Position) MapNode(aimax.osm.data.entities.MapNode) MapAdapter(aimax.osm.routing.MapAdapter)

Example 8 with Position

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

the class DefaultMap method createTrack.

/** {@inheritDoc} */
@Override
public void createTrack(String trackName, List<Position> positions) {
    clearTrack(trackName);
    Track track = new DefaultTrack(nextTrackId++, trackName, trackName);
    updateEntityViewInfo(track, false);
    tracks.add(track);
    for (Position pos : positions) track.addNode(pos);
    fireMapDataEvent(new MapEvent(this, MapEvent.Type.TRACK_MODIFIED, track.getId()));
}
Also used : Position(aimax.osm.data.Position) MapEvent(aimax.osm.data.MapEvent) Track(aimax.osm.data.entities.Track)

Example 9 with Position

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

the class DefaultEntityFinder method find.

/**
	 * Searches for entities which comply to the current search specification
	 * and stores them as results.
	 */
@Override
protected void find(boolean findMore) {
    BestMatchFinder bmf = new BestMatchFinder(pattern);
    List<MapEntity> results = getResults();
    BoundingBox bb = new BoundingBox(position, nextRadius);
    if (!results.isEmpty())
        bmf.checkMatchQuality(results.get(0));
    if (mode.equals(Mode.ENTITY) || mode.equals(Mode.NODE)) {
        for (MapNode node : getStorage().getPois(bb)) {
            int match = bmf.checkMatchQuality(node);
            if (match >= 0) {
                if (match > 0) {
                    results.clear();
                    bmf.useAsReference(node);
                }
                if (position.insertInAscendingDistanceOrder(results, node))
                    if (results.size() > 100)
                        results.remove(99);
            }
        }
    }
    if (mode.equals(Mode.ENTITY) || mode.equals(Mode.WAY)) {
        for (MapWay way : getStorage().getWays(bb)) {
            int match = bmf.checkMatchQuality(way);
            if (match >= 0) {
                if (match > 0) {
                    results.clear();
                    bmf.useAsReference(way);
                }
                if (position.insertInAscendingDistanceOrder(results, way))
                    if (results.size() > 100)
                        results.remove(99);
            }
        }
    }
    if (mode.equals(Mode.ADDRESS)) {
        List<MapEntity> iResults = getIntermediateResults();
        StringTokenizer tokenizer = new StringTokenizer(pattern, ",");
        String placeName = null;
        String wayName = null;
        if (tokenizer.hasMoreElements())
            placeName = tokenizer.nextToken();
        if (tokenizer.hasMoreElements())
            wayName = tokenizer.nextToken().trim();
        if (placeName != null && !findMore) {
            for (MapNode place : getStorage().getPlaces(placeName)) {
                position.insertInAscendingDistanceOrder(iResults, place);
                if (iResults.size() > 100)
                    iResults.remove(99);
            }
            nextRadius = -1;
        }
        if (iResults.size() == 1 && wayName != null) {
            MapNode place = (MapNode) iResults.get(0);
            findWay(wayName, new Position(place.getLat(), place.getLon()), null);
        }
    } else {
        nextRadius *= 2;
        if (results.isEmpty() && getIntermediateResults().isEmpty() && nextRadius <= getMaxRadius())
            find(true);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) MapWay(aimax.osm.data.entities.MapWay) Position(aimax.osm.data.Position) BoundingBox(aimax.osm.data.BoundingBox) MapEntity(aimax.osm.data.entities.MapEntity) MapNode(aimax.osm.data.entities.MapNode)

Example 10 with Position

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

the class OsmMoveAction method getTravelDistance.

/** Returns the distance in KM. */
public float getTravelDistance() {
    float result = 0f;
    int size = Math.abs(toIndex - fromIndex) + 1;
    List<MapNode> nodes = way.getNodes();
    Position pos = new Position(nodes.get(fromIndex));
    for (int i = 1; i < size; i++) {
        MapNode next = nodes.get(fromIndex < toIndex ? fromIndex + i : fromIndex - i);
        result += pos.getDistKM(next);
        pos = new Position(next);
    }
    return result;
}
Also used : Position(aimax.osm.data.Position) MapNode(aimax.osm.data.entities.MapNode)

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