Search in sources :

Example 11 with Way

use of uk.me.parabola.mkgmap.reader.osm.Way 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 Way

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

the class StyleTester method readSimpleTestFile.

/**
 * Read in the combined test file.  This contains some ways and a style.
 * The style does not need to include 'version' as this is added for you.
 */
private static List<Way> readSimpleTestFile(BufferedReader br) throws IOException {
    List<Way> ways = new ArrayList<>();
    String line;
    while ((line = br.readLine()) != null) {
        line = line.trim();
        if (line.toLowerCase(Locale.ENGLISH).startsWith("way")) {
            Way w = readWayTags(br, line);
            ways.add(w);
        } else if (line.startsWith("<<<")) {
            // read the rest of the file
            readStyles(br, line);
        }
    /*else if ("".equals(line) || line.startsWith("#")) {
				// ignore blank lines.
			}*/
    }
    br.close();
    return ways;
}
Also used : ArrayList(java.util.ArrayList) Way(uk.me.parabola.mkgmap.reader.osm.Way)

Example 13 with Way

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

the class LengthFunction method calcLength.

private double calcLength(Element el) {
    if (el instanceof Way) {
        Way w = (Way) el;
        double length = 0;
        Coord prevC = null;
        for (Coord c : w.getPoints()) {
            if (prevC != null) {
                length += prevC.distance(c);
            }
            prevC = c;
        }
        return length;
    } else if (el instanceof Relation) {
        Relation rel = (Relation) el;
        double length = 0;
        for (Entry<String, Element> relElem : rel.getElements()) {
            if (relElem.getValue() instanceof Way || relElem.getValue() instanceof Relation) {
                if (rel == relElem.getValue()) {
                    // avoid recursive call
                    log.error("Relation " + rel.getId() + " contains itself as element. This is not supported.");
                } else {
                    length += calcLength(relElem.getValue());
                }
            }
        }
        return length;
    } else {
        throw new SyntaxException("length() cannot calculate elements of type " + el.getClass().getName());
    }
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Relation(uk.me.parabola.mkgmap.reader.osm.Relation) Entry(java.util.Map.Entry) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) Way(uk.me.parabola.mkgmap.reader.osm.Way)

Example 14 with Way

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

the class HousenumberMatch method isDirectlyConnected.

public boolean isDirectlyConnected(HousenumberMatch other) {
    if (getElement() instanceof Way && other.getElement() instanceof Way) {
        List<Coord> s1 = ((Way) getElement()).getPoints();
        List<Coord> s2 = ((Way) other.getElement()).getPoints();
        for (int i = 0; i + 1 < s1.size(); i++) {
            Coord co = s1.get(i);
            co.setPartOfShape2(false);
        }
        for (int i = 0; i + 1 < s2.size(); i++) {
            Coord co = s2.get(i);
            co.setPartOfShape2(true);
        }
        for (int i = 0; i + 1 < s1.size(); i++) {
            Coord co = s1.get(i);
            if (co.isPartOfShape2())
                return true;
        }
    }
    return false;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Way(uk.me.parabola.mkgmap.reader.osm.Way)

Example 15 with Way

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

the class O5mBinHandler method readWay.

/**
 * read a way data set
 * @throws IOException
 */
private void readWay() throws IOException {
    lastWayId += readSignedNum64();
    if (bytesToRead == 0)
        // only wayId: this is a delete action, we ignore it
        return;
    readVersionTsAuthor();
    if (bytesToRead == 0)
        // only wayId + version: this is a delete action, we ignore it
        return;
    Way way = startWay(lastWayId);
    long refSize = readUnsignedNum32();
    long stop = bytesToRead - refSize;
    while (bytesToRead > stop) {
        lastRef[0] += readSignedNum64();
        addCoordToWay(way, lastRef[0]);
    }
    readTags(way);
    endWay(way);
}
Also used : Way(uk.me.parabola.mkgmap.reader.osm.Way)

Aggregations

Way (uk.me.parabola.mkgmap.reader.osm.Way)142 Test (org.junit.Test)94 TestUtils.makeRuleSet (func.lib.TestUtils.makeRuleSet)70 GType (uk.me.parabola.mkgmap.reader.osm.GType)60 Element (uk.me.parabola.mkgmap.reader.osm.Element)48 Coord (uk.me.parabola.imgfmt.app.Coord)31 ArrayList (java.util.ArrayList)18 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)12 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)11 List (java.util.List)8 Node (uk.me.parabola.mkgmap.reader.osm.Node)8 HashMap (java.util.HashMap)7 IdentityHashMap (java.util.IdentityHashMap)6 Map (java.util.Map)6 StringStyleFileLoader (func.lib.StringStyleFileLoader)5 CoordNode (uk.me.parabola.imgfmt.app.CoordNode)5 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)5 CoordPOI (uk.me.parabola.mkgmap.reader.osm.CoordPOI)4 RestrictionRelation (uk.me.parabola.mkgmap.reader.osm.RestrictionRelation)4 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)3