Search in sources :

Example 11 with MapNode

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

the class DefaultMap method compile.

/**
	 * Separates way nodes from points of interests, cleans up useless garbage
	 * and creates a kd-tree for the remaining entities. Always call this method
	 * before using using the container for viewing.
	 */
public void compile() {
    ArrayList<Long> toDelete = new ArrayList<Long>();
    for (MapNode node : nodes.values()) {
        if (node.hasPosition()) {
            if (node.getName() != null || node.getAttributes().length > 0)
                pois.add(node);
            else if (node.getWayRefs().isEmpty())
                toDelete.add(node.getId());
        } else {
            LOG.warning("No definition found for referenced node " + node.getId() + ".");
            toDelete.add(node.getId());
        }
    }
    for (long id : toDelete) {
        nodes.remove(id);
    }
    BoundingBox bbAllNodes = new BoundingBox();
    bbAllNodes.adjust(nodes.values());
    bbAllNodes.adjust(pois);
    if (boundingBox == null)
        boundingBox = bbAllNodes;
    else
        boundingBox.intersectWith(bbAllNodes);
    applyClassifierAndUpdateTree(bbAllNodes);
    fireMapDataEvent(new MapEvent(this, MapEvent.Type.MAP_NEW));
}
Also used : BoundingBox(aimax.osm.data.BoundingBox) MapEvent(aimax.osm.data.MapEvent) ArrayList(java.util.ArrayList) MapNode(aimax.osm.data.entities.MapNode)

Example 12 with MapNode

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

the class DefaultMapBuilder method isNodeDefined.

/** {@inheritDoc} */
@Override
public boolean isNodeDefined(long id, BoundingBox bb) {
    MapNode node = result.getNode(id);
    boolean result = (node != null && node.hasPosition());
    if (result && bb != null)
        result = bb.isInside(node.getLat(), node.getLon());
    return result;
}
Also used : MapNode(aimax.osm.data.entities.MapNode)

Example 13 with MapNode

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

the class DefaultMapWay method toString.

@Override
public String toString() {
    StringBuffer result = new StringBuffer("Way(" + id + ", [ ");
    for (MapNode node : nodes) result.append(node.getId() + " ");
    result.append("])");
    return result.toString();
}
Also used : MapNode(aimax.osm.data.entities.MapNode)

Example 14 with MapNode

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

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

the class DefaultMap method getWayNodes.

/** Reduces the level of detail by selecting some of the given nodes. */
@Override
public List<MapNode> getWayNodes(MapWay way, float scale) {
    List<MapNode> wayNodes = way.getNodes();
    int zoomLevel;
    if (scale <= 1f / 10000000)
        zoomLevel = 3;
    else if (scale <= 1f / 750000)
        zoomLevel = 2;
    else if (scale <= 1f / 350000)
        zoomLevel = 1;
    else
        zoomLevel = 0;
    if (zoomLevel > 0) {
        int size = wayNodes.size();
        List<MapNode> result = new ArrayList<MapNode>(size / zoomLevel + 2);
        int i = 0;
        for (MapNode node : wayNodes) {
            if (i == 0 || i == size - 1 || node.getId() % (4 * zoomLevel) == 0)
                result.add(node);
            i++;
        }
        if (wayNodes.get(0) == wayNodes.get(size - 1) && result.size() < 4)
            result.clear();
        return result;
    } else {
        return Collections.unmodifiableList(wayNodes);
    }
}
Also used : ArrayList(java.util.ArrayList) MapNode(aimax.osm.data.entities.MapNode)

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