Search in sources :

Example 1 with ConvertedWay

use of uk.me.parabola.mkgmap.osmstyle.ConvertedWay in project mkgmap by openstreetmap.

the class DebugWriter method writeOSM.

/**
 * Convert list of ways to osm file for debugging purposes.
 * @param bbox the bounding box for the osm file
 * @param outPath the directory
 * @param name the file name
 * @param convertedWays the list of ways
 */
public static void writeOSM(Area bbox, String outPath, String name, List<ConvertedWay> convertedWays) {
    if (outPath == null)
        return;
    File outDir = new File(outPath + "/.");
    if (outDir.getParentFile() != null) {
        outDir.getParentFile().mkdirs();
    }
    Map<String, byte[]> dummyMap = new HashMap<>();
    for (int pass = 1; pass <= 2; pass++) {
        IdentityHashMap<Coord, Integer> allPoints = new IdentityHashMap<>();
        uk.me.parabola.splitter.Area bounds = new uk.me.parabola.splitter.Area(bbox.getMinLat(), bbox.getMinLong(), bbox.getMaxLat(), bbox.getMaxLong());
        O5mMapWriter writer = new O5mMapWriter(bounds, outDir, 0, 0, dummyMap, dummyMap);
        writer.initForWrite();
        Integer nodeId;
        try {
            for (ConvertedWay cw : convertedWays) {
                if (cw == null)
                    continue;
                for (Coord p : cw.getPoints()) {
                    nodeId = allPoints.get(p);
                    if (nodeId == null) {
                        nodeId = allPoints.size();
                        allPoints.put(p, nodeId);
                        uk.me.parabola.splitter.Node nodeOut = new uk.me.parabola.splitter.Node();
                        if (pass == 1)
                            // high prec
                            nodeOut.set(nodeId + 1000000000L, p.getLatDegrees(), p.getLonDegrees());
                        else
                            nodeOut.set(nodeId + 1000000000L, Utils.toDegrees(p.getLatitude()), Utils.toDegrees(p.getLongitude()));
                        if (p instanceof CoordPOI) {
                            for (Map.Entry<String, String> tagEntry : ((CoordPOI) p).getNode().getTagEntryIterator()) {
                                nodeOut.addTag(tagEntry.getKey(), tagEntry.getValue());
                            }
                        }
                        writer.write(nodeOut);
                    }
                }
            }
            for (int w = 0; w < convertedWays.size(); w++) {
                ConvertedWay cw = convertedWays.get(w);
                if (cw == null)
                    continue;
                Way way = cw.getWay();
                uk.me.parabola.splitter.Way wayOut = new uk.me.parabola.splitter.Way();
                for (Coord p : way.getPoints()) {
                    nodeId = allPoints.get(p);
                    assert nodeId != null;
                    wayOut.addRef(nodeId + 1000000000L);
                }
                for (Map.Entry<String, String> tagEntry : way.getTagEntryIterator()) {
                    wayOut.addTag(tagEntry.getKey(), tagEntry.getValue());
                }
                wayOut.addTag("aaa-osm-id", Long.toString(way.getId()));
                wayOut.setId(w);
                writer.write(wayOut);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        writer.finishWrite();
        File f = new File(outDir.getAbsoluteFile(), "00000000.o5m");
        File ren = new File(outDir.getAbsoluteFile(), name + ((pass == 1) ? "_hp" : "_mu") + ".o5m");
        if (ren.exists())
            ren.delete();
        f.renameTo(ren);
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) Way(uk.me.parabola.mkgmap.reader.osm.Way) ConvertedWay(uk.me.parabola.mkgmap.osmstyle.ConvertedWay) ConvertedWay(uk.me.parabola.mkgmap.osmstyle.ConvertedWay) CoordPOI(uk.me.parabola.mkgmap.reader.osm.CoordPOI) IOException(java.io.IOException) Coord(uk.me.parabola.imgfmt.app.Coord) Area(uk.me.parabola.imgfmt.app.Area) O5mMapWriter(uk.me.parabola.splitter.O5mMapWriter) File(java.io.File) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 Area (uk.me.parabola.imgfmt.app.Area)1 Coord (uk.me.parabola.imgfmt.app.Coord)1 ConvertedWay (uk.me.parabola.mkgmap.osmstyle.ConvertedWay)1 CoordPOI (uk.me.parabola.mkgmap.reader.osm.CoordPOI)1 Way (uk.me.parabola.mkgmap.reader.osm.Way)1 O5mMapWriter (uk.me.parabola.splitter.O5mMapWriter)1