Search in sources :

Example 71 with Way

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

the class RulesTest method checkEmpty.

/**
 * Check if this rule would match an empty way.
 *
 * Such rules are not allowed.
 *
 * The problem case is length().  The length of the test way is 3.3 and we always make
 * sure that length is only used in expressions with GTE and values of 1 or 2 so they
 * are always true.  However if there is a NOT in front if it it will then be false and
 * so the simple test of of an empty way returning true could miss this case.
 *
 * So we also check with a way of length zero.
 *
 * Then there is still the problem that we do not detect an expression such as (length()>=2 & !(length()>=2))
 *
 * So reject any rule that has length() beneath a not.
 */
private static boolean checkEmpty(Op expr) {
    Way way = makeWay();
    boolean invalid = expr.eval(way);
    Way way1 = new Way(2);
    way1.addPoint(new Coord(1, 1));
    if (expr.eval(way1))
        invalid = true;
    // So if there is a length() anywhere beneath a NOT then throw this rule out.
    if (checkNotLength(expr, expr.isType(NOT)))
        invalid = true;
    return invalid;
}
Also used : Coord(uk.me.parabola.imgfmt.app.Coord) Way(uk.me.parabola.mkgmap.reader.osm.Way)

Example 72 with Way

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

the class ElementQuadTreeNode method split.

/**
 * Splits this quadtree node into 4 subnodes.
 */
private void split() {
    if (bounds.getHeight() <= 5 || bounds.getWidth() <= 5) {
        log.error("Do not split more due to too small bounds: " + bounds);
        return;
    }
    int halfLat = (bounds.getMinLat() + bounds.getMaxLat()) / 2;
    int halfLong = (bounds.getMinLong() + bounds.getMaxLong()) / 2;
    children = new ElementQuadTreeNode[4];
    Area[] childBounds = new Area[4];
    childBounds[0] = new Area(bounds.getMinLat(), bounds.getMinLong(), halfLat, halfLong);
    childBounds[1] = new Area(halfLat, bounds.getMinLong(), bounds.getMaxLat(), halfLong);
    childBounds[2] = new Area(bounds.getMinLat(), halfLong, halfLat, bounds.getMaxLong());
    childBounds[3] = new Area(halfLat, halfLong, bounds.getMaxLat(), bounds.getMaxLong());
    List<Map<Element, List<Coord>>> childElems = new ArrayList<Map<Element, List<Coord>>>(4);
    for (int i = 0; i < 4; i++) {
        childElems.add(new HashMap<Element, List<Coord>>());
    }
    for (Entry<Element, List<Coord>> elem : elementMap.entrySet()) {
        if (elem.getKey() instanceof Node) {
            Node node = (Node) elem.getKey();
            for (int i = 0; i < childBounds.length; i++) {
                if (childBounds[i].contains(node.getLocation())) {
                    childElems.get(i).put(node, EMPTY_LIST);
                    break;
                }
            }
        } else if (elem.getKey() instanceof Way) {
            List<List<Coord>> points = new ArrayList<List<Coord>>(4);
            for (int i = 0; i < 4; i++) {
                // usually ways are quite local
                // therefore there is a high probability that only one child is covered
                // dim the new list as the old list
                points.add(new ArrayList<Coord>(elem.getValue().size()));
            }
            for (Coord c : elem.getValue()) {
                for (int i = 0; i < childBounds.length; i++) {
                    if (childBounds[i].contains(c)) {
                        points.get(i).add(c);
                        break;
                    }
                }
            }
            for (int i = 0; i < 4; i++) {
                if (points.get(i).isEmpty() == false) {
                    childElems.get(i).put(elem.getKey(), points.get(i));
                }
            }
        }
    }
    for (int i = 0; i < 4; i++) {
        children[i] = new ElementQuadTreeNode(childBounds[i], childElems.get(i));
    }
    elementMap = null;
}
Also used : Element(uk.me.parabola.mkgmap.reader.osm.Element) Node(uk.me.parabola.mkgmap.reader.osm.Node) ArrayList(java.util.ArrayList) Way(uk.me.parabola.mkgmap.reader.osm.Way) Coord(uk.me.parabola.imgfmt.app.Coord) Area(uk.me.parabola.imgfmt.app.Area) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 73 with Way

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

the class ElementQuadTreeNode method get.

/**
 * Retrieves all elements that intersects the given polygon.
 * @param polygon the polygon
 * @param resultList results are stored in this collection
 * @return the resultList
 */
public Set<Element> get(ElementQuadTreePolygon polygon, Set<Element> resultList) {
    if (isEmpty()) {
        return resultList;
    }
    if (polygon.getBbox().intersects(getBounds())) {
        if (isLeaf()) {
            for (Entry<Element, List<Coord>> elem : elementMap.entrySet()) {
                if (resultList.contains(elem.getKey())) {
                    continue;
                }
                if (elem.getKey() instanceof Node) {
                    Node n = (Node) elem.getKey();
                    Coord c = n.getLocation();
                    if (polygon.getArea().contains(c.getLongitude(), c.getLatitude())) {
                        resultList.add(n);
                    }
                } else if (elem.getKey() instanceof Way) {
                    for (Coord c : elem.getValue()) {
                        if (polygon.getArea().contains(c.getLongitude(), c.getLatitude())) {
                            resultList.add(elem.getKey());
                            break;
                        }
                    }
                }
            }
        } else {
            for (ElementQuadTreeNode child : children) {
                if (child.isEmpty() == false && polygon.getArea().intersects(child.getBoundsAsRectangle())) {
                    java.awt.geom.Area subArea = (java.awt.geom.Area) polygon.getArea().clone();
                    subArea.intersect(Java2DConverter.createBoundsArea(new Area(child.getBounds().getMinLat() - 1, child.getBounds().getMinLong() - 1, child.getBounds().getMaxLat() + 1, child.getBounds().getMaxLong() + 1)));
                    child.get(new ElementQuadTreePolygon(subArea), resultList);
                }
            }
        }
    }
    return resultList;
}
Also used : Element(uk.me.parabola.mkgmap.reader.osm.Element) Node(uk.me.parabola.mkgmap.reader.osm.Node) Way(uk.me.parabola.mkgmap.reader.osm.Way) Coord(uk.me.parabola.imgfmt.app.Coord) Area(uk.me.parabola.imgfmt.app.Area) ArrayList(java.util.ArrayList) List(java.util.List)

Example 74 with Way

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

the class ActionReaderTest method makeElement.

/**
 * Make a standard element for the tests.
 */
private Element makeElement() {
    Element el = new Way(0);
    el.addTag("park", "no");
    el.addTag("test", "1");
    return el;
}
Also used : Element(uk.me.parabola.mkgmap.reader.osm.Element) Way(uk.me.parabola.mkgmap.reader.osm.Way)

Example 75 with Way

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

the class RuleFileReaderTest method testContinueRepeat.

@Test
public void testContinueRepeat() {
    RuleSet rs = makeRuleSet("highway=primary [0x1 continue]" + "highway=primary [0x2 continue]" + "highway=primary [0x3]" + "highway=primary [0x4]");
    Way el = new Way(1);
    el.addTag("highway", "primary");
    for (int i = 0; i < 3; i++) {
        GType type = getFirstType(rs, el);
        assertNotNull(type);
        assertEquals("first type", 1, type.getType());
        assertEquals("continue search", true, type.isContinueSearch());
    }
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) GType(uk.me.parabola.mkgmap.reader.osm.GType) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

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