Search in sources :

Example 6 with BoundingBox

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

the class KDTree method insertEntity.

/**
	 * Adds an entity at the right position in the tree and extends
	 * the tree if necessary. It is assumed that the entity contains
	 * view information.
	 */
public void insertEntity(DefaultMapEntity entity) {
    if (children == null) {
        entities.add(entity);
        isSorted = false;
        if (entities.size() > maxEntities && depth < maxDepth) {
            computeSplitValues();
            BoundingBox c1bb;
            BoundingBox c2bb;
            if (splitAtLat) {
                c1bb = new BoundingBox(bb.getLatMin(), bb.getLonMin(), splitValue, bb.getLonMax());
                c2bb = new BoundingBox(splitValue, bb.getLonMin(), bb.getLatMax(), bb.getLonMax());
            } else {
                c1bb = new BoundingBox(bb.getLatMin(), bb.getLonMin(), bb.getLatMax(), splitValue);
                c2bb = new BoundingBox(bb.getLatMin(), splitValue, bb.getLatMax(), bb.getLonMax());
            }
            children = new KDTree[2];
            children[0] = new KDTree(c1bb, maxEntities, maxDepth, depth + 1);
            children[1] = new KDTree(c2bb, maxEntities, maxDepth, depth + 1);
            List<DefaultMapEntity> tmp = entities;
            entities = new ArrayList<DefaultMapEntity>();
            for (DefaultMapEntity ne : tmp) insertEntity(ne);
        }
    } else {
        int cr = (splitAtLat ? entity.compareLatitude(splitValue) : entity.compareLongitude(splitValue));
        if (cr < 0)
            children[0].insertEntity(entity);
        else if (cr > 0)
            children[1].insertEntity(entity);
        else {
            entities.add(entity);
            isSorted = false;
        }
    }
}
Also used : BoundingBox(aimax.osm.data.BoundingBox)

Example 7 with BoundingBox

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

the class MapAdapter method getLocations.

/** {@inheritDoc} Very expensive for large maps! */
@Override
public List<String> getLocations() {
    List<String> result = new ArrayList<>();
    HashSet<MapNode> nodeHash = new HashSet<>();
    for (MapWay way : osmMap.getWays(new BoundingBox(-90, -180, 90, 180))) {
        if (filter == null || filter.isAccepted(way)) {
            for (MapNode node : way.getNodes()) if (!nodeHash.contains(node)) {
                result.add(Long.toString(node.getId()));
                nodeHash.add(node);
            }
        }
    }
    return result;
}
Also used : MapWay(aimax.osm.data.entities.MapWay) BoundingBox(aimax.osm.data.BoundingBox) ArrayList(java.util.ArrayList) MapNode(aimax.osm.data.entities.MapNode) HashSet(java.util.HashSet)

Example 8 with BoundingBox

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

the class MapViewFrame method askForBoundingBox.

protected BoundingBox askForBoundingBox() {
    BoundingBox result = null;
    JTextField minLat = new JTextField("-90");
    JTextField minLon = new JTextField("-180");
    JTextField maxLat = new JTextField("90");
    JTextField maxLon = new JTextField("180");
    if (getMap().getMarkers().size() == 2) {
        MapNode m1 = getMap().getMarkers().get(0);
        MapNode m2 = getMap().getMarkers().get(1);
        minLat.setText(Float.toString(Math.min(m1.getLat(), m2.getLat())));
        minLon.setText(Float.toString(Math.min(m1.getLon(), m2.getLon())));
        maxLat.setText(Float.toString(Math.max(m1.getLat(), m2.getLat())));
        maxLon.setText(Float.toString(Math.max(m1.getLon(), m2.getLon())));
    }
    Object[] content = new Object[] { "Min Latitude:", minLat, "Min Longitude:", minLon, "Max Latitude:", maxLat, "Max Longitude:", maxLon };
    boolean done;
    do {
        done = true;
        if (JOptionPane.showConfirmDialog(this, content, "Specify Bounding Box", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
            try {
                result = new BoundingBox(Float.parseFloat(minLat.getText()), Float.parseFloat(minLon.getText()), Float.parseFloat(maxLat.getText()), Float.parseFloat(maxLon.getText()));
            } catch (NumberFormatException e) {
                done = false;
            }
        }
    } while (!done);
    return result;
}
Also used : BoundingBox(aimax.osm.data.BoundingBox) MapNode(aimax.osm.data.entities.MapNode) JTextField(javax.swing.JTextField)

Aggregations

BoundingBox (aimax.osm.data.BoundingBox)8 MapNode (aimax.osm.data.entities.MapNode)4 MapEntity (aimax.osm.data.entities.MapEntity)2 MapWay (aimax.osm.data.entities.MapWay)2 ArrayList (java.util.ArrayList)2 MapEvent (aimax.osm.data.MapEvent)1 Position (aimax.osm.data.Position)1 DefaultMap (aimax.osm.data.impl.DefaultMap)1 Dimension (java.awt.Dimension)1 HashSet (java.util.HashSet)1 StringTokenizer (java.util.StringTokenizer)1 JFileChooser (javax.swing.JFileChooser)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1 JTextField (javax.swing.JTextField)1 FileFilter (javax.swing.filechooser.FileFilter)1 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)1