Search in sources :

Example 6 with MapNode

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

the class MapAdapter method getReachableLocations.

private List<String> getReachableLocations(String location, OneWayMode oneWayMode) {
    List<String> result = new ArrayList<>();
    MapNode node = getWayNode(location);
    if (node != null) {
        for (WayRef wref : node.getWayRefs()) {
            if (filter == null || filter.isAccepted(wref.getWay())) {
                MapWay way = wref.getWay();
                int nodeIdx = wref.getNodeIdx();
                List<MapNode> wayNodes = way.getNodes();
                MapNode next;
                if (wayNodes.size() > nodeIdx + 1 && (oneWayMode != OneWayMode.TRAVEL_BACKWARDS || !way.isOneway())) {
                    next = wayNodes.get(nodeIdx + 1);
                    result.add(Long.toString(next.getId()));
                }
                if (nodeIdx > 0 && (oneWayMode != OneWayMode.TRAVEL_FORWARD || !way.isOneway())) {
                    next = wayNodes.get(nodeIdx - 1);
                    result.add(Long.toString(next.getId()));
                }
            }
        }
    }
    return result;
}
Also used : WayRef(aimax.osm.data.entities.WayRef) MapWay(aimax.osm.data.entities.MapWay) ArrayList(java.util.ArrayList) MapNode(aimax.osm.data.entities.MapNode)

Example 7 with MapNode

use of aimax.osm.data.entities.MapNode 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 8 with MapNode

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

the class MapPaneCtrl method showMapEntityInfoDialog.

/**
     * Finds the visible entity next to the specified view coordinates and shows
     * informations about it.
     *
     * @param debug
     *            Enables a more detailed view.
     */
private void showMapEntityInfoDialog(MapEntity entity, boolean debug) {
    List<MapEntity> entities = new ArrayList<>();
    if (entity.getName() != null || entity.getAttributes().length > 0 || debug)
        entities.add(entity);
    if (entity instanceof MapNode) {
        MapNode mNode = (MapNode) entity;
        for (WayRef ref : mNode.getWayRefs()) {
            MapEntity me = ref.getWay();
            if (me.getName() != null || me.getAttributes().length > 0 || debug)
                entities.add(me);
        }
    }
    for (MapEntity me : entities) {
        String header = (me.getName() != null) ? me.getName() : "";
        StringBuilder content = new StringBuilder();
        if (debug)
            header += " (" + ((me instanceof MapNode) ? "Node " : "Way ") + me.getId() + ")";
        if (me instanceof MapNode) {
            content.append("Lat: ").append(((MapNode) me).getLat()).append(" Lon: ").append(((MapNode) me).getLon()).append(" ");
        }
        if (me.getAttributes().length > 0) {
            EntityAttribute[] atts = me.getAttributes();
            content.append("Attributs: ");
            for (EntityAttribute att : atts) {
                content.append(att.getKey()).append("=").append(att.getValue()).append(" ");
            }
        }
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Map Entity Info");
        alert.setHeaderText(header);
        alert.setContentText(content.toString());
        Optional<ButtonType> result = alert.showAndWait();
        if (!result.isPresent())
            break;
    }
}
Also used : WayRef(aimax.osm.data.entities.WayRef) EntityAttribute(aimax.osm.data.entities.EntityAttribute) ArrayList(java.util.ArrayList) Alert(javafx.scene.control.Alert) MapEntity(aimax.osm.data.entities.MapEntity) MapNode(aimax.osm.data.entities.MapNode) ButtonType(javafx.scene.control.ButtonType)

Example 9 with MapNode

use of aimax.osm.data.entities.MapNode 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 10 with MapNode

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

the class OsmWriter method writeMap.

/**
	 * Writes all data from <code>mapData</code> to a stream.
	 */
public void writeMap(OutputStreamWriter writer, OsmMap map, BoundingBox bb) {
    try {
        StringBuffer text = new StringBuffer();
        text.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        text.append("<osm version=\"0.6\" generator=\"aimax-osm-writer\">\n");
        text.append("<bound box=\"");
        text.append(bb.getLatMin() + ",");
        text.append(bb.getLonMin() + ",");
        text.append(bb.getLatMax() + ",");
        text.append(bb.getLonMax());
        text.append("\" origin=\"?\"/>\n");
        writer.write(text.toString());
        HashSet<MapNode> nodeHash = new HashSet<MapNode>();
        Collection<MapWay> ways = map.getWays(bb);
        for (MapWay way : ways) for (MapNode node : way.getNodes()) if (!nodeHash.contains(node)) {
            writeNode(writer, node);
            nodeHash.add(node);
        }
        for (MapNode poi : map.getPois(bb)) if (!nodeHash.contains(poi)) {
            writeNode(writer, poi);
            nodeHash.add(poi);
        }
        for (MapWay way : ways) writeWay(writer, way);
        writer.write("</osm>\n");
    } catch (IOException e) {
        throw new OsmRuntimeException("Unable to write XML output to file.", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                LOG.log(Level.SEVERE, "Unable to close output stream.", e);
            }
        }
    }
}
Also used : MapWay(aimax.osm.data.entities.MapWay) OsmRuntimeException(aimax.osm.reader.OsmRuntimeException) MapNode(aimax.osm.data.entities.MapNode) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

MapNode (aimax.osm.data.entities.MapNode)37 ArrayList (java.util.ArrayList)13 Position (aimax.osm.data.Position)12 MapWay (aimax.osm.data.entities.MapWay)6 MapEntity (aimax.osm.data.entities.MapEntity)5 BoundingBox (aimax.osm.data.BoundingBox)4 WayRef (aimax.osm.data.entities.WayRef)4 MapAdapter (aimax.osm.routing.MapAdapter)4 Point2D (aima.core.util.math.geom.shapes.Point2D)3 MapEvent (aimax.osm.data.MapEvent)3 EntityAttribute (aimax.osm.data.entities.EntityAttribute)3 Node (aima.core.search.framework.Node)2 LRTAStarAgent (aima.core.search.online.LRTAStarAgent)2 IOException (java.io.IOException)2 DecimalFormat (java.text.DecimalFormat)2 HashSet (java.util.HashSet)2 Agent (aima.core.agent.Agent)1 aima.core.environment.map (aima.core.environment.map)1 MapAgent (aima.core.environment.map.MapAgent)1 MapEnvironment (aima.core.environment.map.MapEnvironment)1