Search in sources :

Example 1 with QuadTree

use of uk.me.parabola.util.QuadTree in project mkgmap by openstreetmap.

the class SeaPolygonRelation method removeFloodedAreas.

private void removeFloodedAreas() {
    fillQuadTrees();
    // create a copy of all resulting ways - the tile way map contains only
    // polygons from
    // the sea generation
    ArrayList<Way> polygons = new ArrayList<Way>(getMpPolygons().values());
    log.info("Starting flood blocker. Polygons to check:", getMpPolygons().size());
    String baseName = GpxCreator.getGpxBaseName();
    if (debug) {
        GpxCreator.createAreaGpx(baseName + "bbox", getTileBounds());
    }
    // the other type
    for (Way p : polygons) {
        boolean sea = "sea".equals(p.getTag("natural"));
        QuadTree goodCoords = (sea ? seaCoords : landCoords);
        QuadTree badCoords = (sea ? landCoords : seaCoords);
        String polyType = (sea ? "sea" : "land");
        String otherType = (sea ? "land" : "sea");
        List<Coord> minusCoords = badCoords.get(p.getPoints(), getFloodBlockerGap());
        List<Coord> positiveCoords = goodCoords.get(p.getPoints());
        log.info(polyType, "polygon", p.getId(), "contains", minusCoords.size(), otherType, "coords and", positiveCoords.size(), polyType, "coords.");
        if (minusCoords.size() > 0) {
            double area = MultiPolygonRelation.calcAreaSize(p.getPoints());
            double ratio = ((minusCoords.size() - positiveCoords.size()) * 100000.0d / area);
            String areaFMT = format.format(area);
            String ratioFMT = format.format(ratio);
            log.info("Flood blocker for", polyType, "polygon", p.getId());
            log.info("area", areaFMT);
            log.info(polyType, positiveCoords.size());
            log.info(otherType, minusCoords.size());
            log.info("ratio", ratioFMT);
            if (debug) {
                GpxCreator.createGpx(baseName + p.getId() + "_" + polyType + "_" + minusCoords.size() + "_" + positiveCoords.size() + "_" + ratioFMT, p.getPoints());
                GpxCreator.createGpx(baseName + p.getId() + "_con_" + minusCoords.size() + "_" + positiveCoords.size() + "_" + ratioFMT, null, minusCoords);
                if (positiveCoords.isEmpty() == false) {
                    GpxCreator.createGpx(baseName + p.getId() + "_pro_" + minusCoords.size() + "_" + positiveCoords.size() + "_" + ratioFMT, null, positiveCoords);
                }
            }
            if (minusCoords.size() - positiveCoords.size() >= getFloodBlockerThreshold() && ratio > getFloodBlockerRatio()) {
                log.warn("Polygon", p.getId(), "type", polyType, "seems to be wrong. Changing it to", otherType);
                if (sea) {
                    p.deleteTag("natural");
                    p.addTag(landTag[0], landTag[1]);
                } else {
                    p.deleteTag(landTag[0]);
                    p.addTag("natural", "sea");
                }
            // getMpPolygons().remove(p.getId());
            } else {
                log.info("Polygon", p.getId(), "is not blocked");
            }
        }
    }
    log.info("Flood blocker finished. Resulting polygons:", getMpPolygons().size());
    landCoords.clear();
    seaCoords.clear();
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) QuadTree(uk.me.parabola.util.QuadTree) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 Coord (uk.me.parabola.imgfmt.app.Coord)1 QuadTree (uk.me.parabola.util.QuadTree)1