Search in sources :

Example 1 with MultiPolygonRelation

use of uk.me.parabola.mkgmap.reader.osm.MultiPolygonRelation in project mkgmap by openstreetmap.

the class PrecompSeaMerger method run.

public void run() {
    Area merge = null;
    try {
        merge = mergeData.toMerge.poll(5, TimeUnit.MILLISECONDS);
    } catch (InterruptedException exp) {
        exp.printStackTrace();
    }
    int merges = 0;
    while (merge != null) {
        Area landClipped = new Area(mergeData.bounds);
        landClipped.intersect(merge);
        mergeData.tmpLandPath.append(landClipped, false);
        merges++;
        if (merges % 500 == 0) {
            // store each 500 polygons into a temporary area
            // and merge them after that. That seems to be quicker
            // than adding lots of very small areas to a highly
            // scattered area
            Area tmpLandArea = new Area(mergeData.tmpLandPath);
            mergeData.landArea.add(tmpLandArea);
            mergeData.tmpLandPath.reset();
        }
        if (merges % 500 == 0) {
            break;
        }
        merge = mergeData.toMerge.poll();
    }
    if (mergeData.ready.get() == false || mergeData.toMerge.isEmpty() == false) {
        // repost the merge thread
        service.execute(this);
        return;
    }
    if (mergeData.landArea.isEmpty())
        mergeData.landArea = new Area(mergeData.tmpLandPath);
    else
        mergeData.landArea.add(new Area(mergeData.tmpLandPath));
    mergeData.tmpLandPath = null;
    // post processing //
    // convert the land area to a list of ways
    List<Way> ways = convertToWays(mergeData.landArea, "land");
    if (ways.isEmpty()) {
        // no land in this tile => create a sea way only
        ways.addAll(convertToWays(new Area(mergeData.bounds), "sea"));
    } else {
        Map<Long, Way> landWays = new HashMap<Long, Way>();
        List<List<Coord>> landParts = Java2DConverter.areaToShapes(mergeData.landArea);
        for (List<Coord> landPoints : landParts) {
            Way landWay = new Way(FakeIdGenerator.makeFakeId(), landPoints);
            landWays.put(landWay.getId(), landWay);
        }
        Way seaWay = new Way(FakeIdGenerator.makeFakeId());
        seaWay.addPoint(new Coord(-90.0d, -180.0d));
        seaWay.addPoint(new Coord(90.0d, -180.0d));
        seaWay.addPoint(new Coord(90.0d, 180.0d));
        seaWay.addPoint(new Coord(-90.0d, 180.0d));
        // close shape
        seaWay.addPoint(seaWay.getPoints().get(0));
        seaWay.setClosedInOSM(true);
        landWays.put(seaWay.getId(), seaWay);
        Relation rel = new GeneralRelation(FakeIdGenerator.makeFakeId());
        for (Way w : landWays.values()) {
            rel.addElement((w == seaWay ? "outer" : "inner"), w);
        }
        // process the tile as sea multipolygon to create simple polygons only
        MultiPolygonRelation mpr = new MultiPolygonRelation(rel, landWays, Java2DConverter.createBbox(new Area(mergeData.bounds))) {

            // do not calculate the area size => it is not required and adds
            // a superfluous tag
            protected boolean isAreaSizeCalculated() {
                return false;
            }
        };
        mpr.addTag("type", "multipolygon");
        mpr.addTag("natural", "sea");
        mpr.processElements();
        for (Way w : landWays.values()) {
            // be ignored here
            if (MultiPolygonRelation.STYLE_FILTER_POLYGON.equals(w.getTag(MultiPolygonRelation.STYLE_FILTER_TAG))) {
                String tag = w.getTag("natural");
                if ("sea".equals(tag) == false) {
                    // ignore the land polygons - we already have them in our list
                    continue;
                }
                w.deleteTag(MultiPolygonRelation.STYLE_FILTER_TAG);
                w.deleteTag(MultiPolygonRelation.MP_CREATED_TAG);
                ways.add(w);
            }
        }
    }
    try {
        // forward the ways to the queue of the saver thread
        saveQueue.put(new SimpleEntry<String, List<Way>>(mergeData.getKey(), ways));
    } catch (InterruptedException exp) {
        exp.printStackTrace();
    }
    // signal that this tile is finished
    signal.countDown();
}
Also used : HashMap(java.util.HashMap) Way(uk.me.parabola.mkgmap.reader.osm.Way) Coord(uk.me.parabola.imgfmt.app.Coord) Area(java.awt.geom.Area) Relation(uk.me.parabola.mkgmap.reader.osm.Relation) MultiPolygonRelation(uk.me.parabola.mkgmap.reader.osm.MultiPolygonRelation) GeneralRelation(uk.me.parabola.mkgmap.reader.osm.GeneralRelation) GeneralRelation(uk.me.parabola.mkgmap.reader.osm.GeneralRelation) MultiPolygonRelation(uk.me.parabola.mkgmap.reader.osm.MultiPolygonRelation) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Area (java.awt.geom.Area)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Coord (uk.me.parabola.imgfmt.app.Coord)1 GeneralRelation (uk.me.parabola.mkgmap.reader.osm.GeneralRelation)1 MultiPolygonRelation (uk.me.parabola.mkgmap.reader.osm.MultiPolygonRelation)1 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)1 Way (uk.me.parabola.mkgmap.reader.osm.Way)1