Search in sources :

Example 1 with OsmRuntimeException

use of aimax.osm.reader.OsmRuntimeException 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)1 MapWay (aimax.osm.data.entities.MapWay)1 OsmRuntimeException (aimax.osm.reader.OsmRuntimeException)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1