Search in sources :

Example 1 with BoundingBox

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

the class MapViewFrame method actionPerformed.

/**
	 * Defines what happens when a button is pressed.
	 */
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == loadButton) {
        String title = "Load OSM Data";
        if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)
            title += " (Bounding Box Mode)";
        if ((e.getModifiers() & KeyEvent.SHIFT_MASK) != 0)
            title += " (Overview Mode)";
        fileChooser.setDialogTitle(title);
        int returnVal = fileChooser.showDialog(this, "Load");
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
                // ctrl+load -> ask the user for a bounding box.
                BoundingBox bb = askForBoundingBox();
                if (bb != null)
                    mapReader.setFilter(bb);
                else
                    return;
            }
            if ((e.getModifiers() & KeyEvent.SHIFT_MASK) != 0) {
                EntityClassifier<Boolean> filter = createOverviewFilter();
                mapReader.setFilter(filter);
            }
            readMap(fileChooser.getSelectedFile());
        }
    } else if (e.getSource() == saveButton) {
        JFileChooser fc = new JFileChooser();
        String[] exts = mapWriter.fileFormatDescriptions();
        for (int i = 0; i < exts.length; i++) {
            FileFilter filter = new FileNameExtensionFilter(exts[i], mapWriter.fileFormatExtensions()[i]);
            fc.addChoosableFileFilter(filter);
        }
        fc.setFileFilter(fc.getChoosableFileFilters()[0]);
        fc.setCurrentDirectory(fileChooser.getCurrentDirectory());
        int returnVal = fc.showSaveDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION && (!fc.getSelectedFile().exists() || JOptionPane.showConfirmDialog(this, "File exists, overwrite?", "Confirm", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)) {
            mapWriter.writeMap(fc.getSelectedFile(), getMap(), view.getBoundingBox());
        }
    } else if (e.getSource() == statisticsButton) {
        Object[][] data = getMap().getStatistics();
        JTable table = new JTable(data, new String[] { "Attribute", "Value" });
        JScrollPane scroller = new JScrollPane(table);
        scroller.setPreferredSize(new Dimension(250, 300));
        JOptionPane.showConfirmDialog(this, scroller, "Map Statistics", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
    } else if (e.getSource() == sidebarCheckBox) {
        showSidebar(sidebarCheckBox.isSelected());
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JFileChooser(javax.swing.JFileChooser) BoundingBox(aimax.osm.data.BoundingBox) JTable(javax.swing.JTable) Dimension(java.awt.Dimension) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) FileFilter(javax.swing.filechooser.FileFilter)

Example 2 with BoundingBox

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

the class BoundElementProcessor method begin.

/**
	 * {@inheritDoc}
	 */
@Override
public void begin(Attributes attributes) {
    String boxString;
    String origin;
    String[] boundStrings;
    float right;
    float left;
    float top;
    float bottom;
    boxString = attributes.getValue(ATTRIBUTE_NAME_BOX);
    if (boxString == null) {
        throw new OsmRuntimeException("Missing required box attribute of bound element");
    }
    boundStrings = boxString.split(",");
    if (boundStrings.length != 4) {
        throw new OsmRuntimeException("Badly formed box attribute of bound element");
    }
    try {
        bottom = Float.parseFloat(boundStrings[0]);
        left = Float.parseFloat(boundStrings[1]);
        top = Float.parseFloat(boundStrings[2]);
        right = Float.parseFloat(boundStrings[3]);
    } catch (NumberFormatException e) {
        throw new OsmRuntimeException("Can't parse box attribute of bound element", e);
    }
    origin = attributes.getValue(ATTRIBUTE_NAME_ORIGIN);
    if (origin == null || origin.equals("")) {
        throw new OsmRuntimeException("Origin attribute of bound element is empty or missing.");
    }
    bb = new BoundingBox(bottom, left, top, right);
}
Also used : BoundingBox(aimax.osm.data.BoundingBox)

Example 3 with BoundingBox

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

the class UnifiedMapDrawer method drawMap.

public void drawMap(IMAGE_TYPE image, boolean adjustToFit) {
    imageBdr.initialize(image);
    imageBdr.setColor(UColor.WHITE);
    imageBdr.setAreaFilled(true);
    imageBdr.drawRect(0, 0, imageBdr.getWidth(), imageBdr.getHeight());
    if (imageBdr.getWidth() > 0 && map != null) {
        if (adjustToFit)
            getTransformer().adjustTransformation(getMap().getBoundingBox(), imageBdr.getWidth(), imageBdr.getHeight());
        float latMin = transformer.lat(imageBdr.getHeight());
        float lonMin = transformer.lon(0);
        float latMax = transformer.lat(0);
        float lonMax = transformer.lon(imageBdr.getWidth());
        float scale = transformer.computeScale();
        BoundingBox vbox = new BoundingBox(latMin, lonMin, latMax, lonMax);
        float viewScale = scale / renderer.getDisplayFactor();
        renderer.initForRendering(imageBdr, transformer, map);
        map.visitEntities(renderer, vbox, viewScale);
        for (MapEntity entity : map.getVisibleMarkersAndTracks(viewScale)) entity.accept(renderer);
        renderer.printBufferedObjects();
        if (renderer.isDebugModeEnabled() && map instanceof DefaultMap) {
            List<double[]> splits = ((DefaultMap) map).getEntityTree().getSplitCoords();
            imageBdr.setColor(UColor.LIGHT_GRAY);
            imageBdr.setLineStyle(false, 1f);
            imageBdr.setAreaFilled(false);
            CoordTransformer trans = renderer.getTransformer();
            for (double[] split : splits) imageBdr.drawLine(renderer.getTransformer().x(split[1]), trans.y(split[0]), trans.x(split[3]), trans.y(split[2]));
        }
    }
    image = imageBdr.getResult();
}
Also used : BoundingBox(aimax.osm.data.BoundingBox) MapEntity(aimax.osm.data.entities.MapEntity) DefaultMap(aimax.osm.data.impl.DefaultMap)

Example 4 with BoundingBox

use of aimax.osm.data.BoundingBox 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 5 with BoundingBox

use of aimax.osm.data.BoundingBox 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)

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