Search in sources :

Example 1 with Element

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

the class AddAccessAction method perform.

public boolean perform(Element el) {
    // 1st build the value
    Element tags = valueTags != null ? valueTags : el;
    String accessValue = null;
    for (ValueBuilder value : getValueBuilder()) {
        accessValue = value.build(tags, el);
        if (accessValue != null) {
            break;
        }
    }
    if (accessValue == null) {
        return false;
    }
    for (Short accessTag : ACCESS_TAGS_COMPILED.keySet()) {
        setTag(el, accessTag, accessValue);
    }
    return true;
}
Also used : Element(uk.me.parabola.mkgmap.reader.osm.Element)

Example 2 with Element

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

the class ValueItem method getValue.

public String getValue(Element el, Element local_el) {
    if (tagname == null && value != null)
        // already known
        return value;
    if (tagname != null) {
        Element e = tagname_is_local ? local_el : el;
        String tagval = e.getTag(tagKey);
        if (filter != null)
            value = filter.filter(tagval, local_el);
        else
            value = tagval;
    }
    return value;
}
Also used : Element(uk.me.parabola.mkgmap.reader.osm.Element)

Example 3 with Element

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

the class O5mBinHandler method readRel.

/**
 * read a relation data set
 * @throws IOException
 */
private void readRel() throws IOException {
    lastRelId += readSignedNum64();
    if (bytesToRead == 0)
        // only relId: this is a delete action, we ignore it
        return;
    readVersionTsAuthor();
    if (bytesToRead == 0)
        // only relId + version: this is a delete action, we ignore it
        return;
    GeneralRelation rel = new GeneralRelation(lastRelId);
    long refSize = readUnsignedNum32();
    long stop = bytesToRead - refSize;
    while (bytesToRead > stop) {
        Element el = null;
        long deltaRef = readSignedNum64();
        int refType = readRelRef();
        String role = stringPair[1];
        lastRef[refType] += deltaRef;
        long memId = lastRef[refType];
        if (refType == 0) {
            el = saver.getNode(memId);
            if (el == null) {
                // we didn't make a node for this point earlier,
                // do it now (if it exists)
                Coord co = saver.getCoord(memId);
                if (co != null) {
                    el = new Node(memId, co);
                    saver.addNode((Node) el);
                }
            }
        } else if (refType == 1) {
            el = saver.getWay(memId);
        } else if (refType == 2) {
            el = saver.getRelation(memId);
            if (el == null) {
                saver.deferRelation(memId, rel, role);
            }
        } else {
            assert false;
        }
        if (// ignore non existing ways caused by splitting files
        el != null)
            rel.addElement(role, el);
    }
    boolean tagsIncomplete = readTags(rel);
    rel.setTagsIncomplete(tagsIncomplete);
    saver.addRelation(rel);
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) GeneralRelation(uk.me.parabola.mkgmap.reader.osm.GeneralRelation) Element(uk.me.parabola.mkgmap.reader.osm.Element) Node(uk.me.parabola.mkgmap.reader.osm.Node)

Example 4 with Element

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

the class ActionReaderTest method testApplyAction.

/**
 * The apply action works on the members of relations.
 */
@Test
public void testApplyAction() {
    List<Action> actions = readActionsFromString("{apply {" + "add route=bike;" + "set foo=bar; }" + "}\n");
    Relation rel = makeRelation();
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(rel, TypeResult.NULL_RESULT);
    assertNull("Tag not set on relation", rel.getTag("route"));
    // Will be set on all members as there is no role filter.
    List<Map.Entry<String, Element>> elements = rel.getElements();
    Element el1 = elements.get(0).getValue();
    assertEquals("route tag added to first", "bike", el1.getTag("route"));
    assertEquals("foo tag set to first", "bar", el1.getTag("foo"));
    Element el2 = elements.get(1).getValue();
    assertEquals("route tag added to second", "bike", el2.getTag("route"));
    assertEquals("foo tag set to second", "bar", el2.getTag("foo"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Relation(uk.me.parabola.mkgmap.reader.osm.Relation) GeneralRelation(uk.me.parabola.mkgmap.reader.osm.GeneralRelation) Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Test(org.junit.Test)

Example 5 with Element

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

the class ActionReaderTest method testSimpleSet.

@Test
public void testSimpleSet() {
    List<Action> actions = readActionsFromString("{set park=yes}");
    assertEquals("one action", 1, actions.size());
    Element el = stdElementRun(actions);
    assertEquals("park overwritten", "yes", el.getTag("park"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element) Test(org.junit.Test)

Aggregations

Element (uk.me.parabola.mkgmap.reader.osm.Element)94 Test (org.junit.Test)75 Way (uk.me.parabola.mkgmap.reader.osm.Way)48 GType (uk.me.parabola.mkgmap.reader.osm.GType)25 TestUtils.makeRuleSet (func.lib.TestUtils.makeRuleSet)23 Action (uk.me.parabola.mkgmap.osmstyle.actions.Action)15 Rule (uk.me.parabola.mkgmap.reader.osm.Rule)8 ArrayList (java.util.ArrayList)7 Node (uk.me.parabola.mkgmap.reader.osm.Node)7 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)7 Coord (uk.me.parabola.imgfmt.app.Coord)5 StringStyleFileLoader (func.lib.StringStyleFileLoader)4 Map (java.util.Map)4 GeneralRelation (uk.me.parabola.mkgmap.reader.osm.GeneralRelation)4 TypeResult (uk.me.parabola.mkgmap.reader.osm.TypeResult)4 HashMap (java.util.HashMap)3 IdentityHashMap (java.util.IdentityHashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Area (uk.me.parabola.imgfmt.app.Area)2