Search in sources :

Example 11 with Coord

use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.

the class StyleTester method readWayTags.

/**
 * You can have a number of ways defined in the file.  If you give a
 * number after 'way' that is used as the way id so that you can identify
 * it in the results.
 *
 * A list of tags are read and added to the way up until a blank line.
 *
 * @param br Read from here.
 * @param waydef This will contain the way-id if one was given.  Otherwise
 * the way id will be 1.
 * @throws IOException If the file cannot be read.
 */
private static Way readWayTags(BufferedReader br, String waydef) throws IOException {
    int id = 1;
    String[] strings = SPACES_PATTERN.split(waydef);
    if (strings.length > 1)
        id = Integer.parseInt(strings[1]);
    Way w = new Way(id);
    w.addPoint(new Coord(1, 1));
    w.addPoint(new Coord(2, 2));
    String line;
    while ((line = br.readLine()) != null) {
        if (line.indexOf('=') < 0)
            break;
        String[] tagval = EQUAL_PATTERN.split(line, 2);
        if (tagval.length == 2)
            w.addTag(tagval[0], tagval[1]);
    }
    return w;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) Way(uk.me.parabola.mkgmap.reader.osm.Way)

Example 12 with Coord

use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.

the class StyleTester method lineToString.

/**
 * This is so we can run against versions of mkgmap that do not have
 * toString methods on MapLine and MapRoad.
 */
private static String lineToString(MapLine el) {
    Formatter fmt = new Formatter();
    fmt.format("Line 0x%x, labels=%s, res=%d-%d", el.getType(), Arrays.toString(el.getLabels()), el.getMinResolution(), el.getMaxResolution());
    if (el.isDirection())
        fmt.format(" oneway");
    fmt.format(" ");
    for (Coord co : el.getPoints()) fmt.format("(%s),", co);
    return fmt.toString();
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Formatter(java.util.Formatter)

Example 13 with Coord

use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.

the class OverlayReader method addLine.

public void addLine(MapLine line, LineAdder adder) {
    int origType = line.getType();
    List<Integer> integerList = overlays.get(origType);
    if (integerList != null) {
        MapLine newline = line.copy();
        newline.setType(integerList.get(0));
        List<Coord> points = line.getPoints();
        newline.setPoints(points);
        adder.add(newline);
        // Force all following types to be added as lines rather than roads.
        for (ListIterator<Integer> t = integerList.listIterator(1); t.hasNext(); ) {
            newline = new MapLine(line);
            newline.setType(t.next());
            newline.setPoints(new ArrayList<Coord>(points));
            adder.add(newline);
        }
    } else {
        adder.add(line);
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) MapLine(uk.me.parabola.mkgmap.general.MapLine)

Example 14 with Coord

use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.

the class RoadMerger method isAngleOK.

/**
 * Checks if the angle between the two {@link Way} objects of both roads
 * is not too sharp so that both roads can be merged.
 * @param mergePoint the coord where both roads should be merged
 * @param way1 1st way
 * @param way2 2nd way
 * @return {@code true} angle is okay, roads might be merged;
 *  {@code false} angle is so sharp that roads must not be merged
 */
private static boolean isAngleOK(Coord mergePoint, Way way1, Way way2) {
    // Check the angle of the two ways
    Coord cOnWay1;
    if (way1.getPoints().get(0) == mergePoint) {
        cOnWay1 = way1.getPoints().get(1);
    } else {
        cOnWay1 = way1.getPoints().get(way1.getPoints().size() - 2);
    }
    Coord cOnWay2;
    if (way2.getPoints().get(0) == mergePoint) {
        cOnWay2 = way2.getPoints().get(1);
    } else {
        cOnWay2 = way2.getPoints().get(way2.getPoints().size() - 2);
    }
    double angle = Math.abs(Utils.getAngle(cOnWay1, mergePoint, cOnWay2));
    if (angle > MAX_MERGE_ANGLE) {
        // The angle exceeds the limit => do not merge
        // Don't know if this is really required or not.
        // But the number of merges which do not succeed due to this
        // restriction is quite low and there have been requests
        // for this: http://www.mkgmap.org.uk/pipermail/mkgmap-dev/2013q3/018649.html
        log.info("Do not merge ways", way1.getId(), "and", way2.getId(), "because they span a too big angle", angle, "°");
        return false;
    }
    return true;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord)

Example 15 with Coord

use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.

the class RoadMerger method workoutRestrictionRelations.

/**
 * We must not merge roads at via points of restriction relations
 * if the way is referenced in the restriction.
 * @param restrictionRels
 */
private void workoutRestrictionRelations(List<RestrictionRelation> restrictionRels) {
    for (RestrictionRelation rel : restrictionRels) {
        Set<Long> restrictionWayIds = rel.getWayIds();
        for (Coord via : rel.getViaCoords()) {
            HashSet<ConvertedWay> roadAtVia = new HashSet<>();
            roadAtVia.addAll(startPoints.get(via));
            roadAtVia.addAll(endPoints.get(via));
            for (ConvertedWay r : roadAtVia) {
                long wayId = r.getWay().getId();
                if (restrictionWayIds.contains(wayId))
                    restrictions.add(via, wayId);
            }
        }
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) RestrictionRelation(uk.me.parabola.mkgmap.reader.osm.RestrictionRelation) HashSet(java.util.HashSet)

Aggregations

Coord (uk.me.parabola.imgfmt.app.Coord)178 ArrayList (java.util.ArrayList)71 Way (uk.me.parabola.mkgmap.reader.osm.Way)31 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)27 List (java.util.List)23 MapLine (uk.me.parabola.mkgmap.general.MapLine)16 Area (uk.me.parabola.imgfmt.app.Area)15 MapShape (uk.me.parabola.mkgmap.general.MapShape)15 CoordNode (uk.me.parabola.imgfmt.app.CoordNode)13 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)13 Node (uk.me.parabola.mkgmap.reader.osm.Node)13 HashMap (java.util.HashMap)12 IdentityHashMap (java.util.IdentityHashMap)11 Test (org.junit.Test)11 MapRoad (uk.me.parabola.mkgmap.general.MapRoad)9 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)8 Area (java.awt.geom.Area)8 HashSet (java.util.HashSet)8 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5