Search in sources :

Example 1 with MapElement

use of uk.me.parabola.mkgmap.general.MapElement in project mkgmap by openstreetmap.

the class StyleTester method formatResults.

/**
 * Print out the garmin elements that were produced by the rules.
 * @param prefix This string will be prepended to the formatted result.
 * @param lines The resulting map elements.
 */
private static List<String> formatResults(String prefix, List<MapElement> lines) {
    List<String> result = new ArrayList<>();
    int i = 0;
    for (MapElement el : lines) {
        String s;
        // So we can run against versions that do not have toString() methods
        if (el instanceof MapRoad)
            s = roadToString((MapRoad) el);
        else
            s = lineToString((MapLine) el);
        result.add(prefix + s);
    }
    return result;
}
Also used : MapElement(uk.me.parabola.mkgmap.general.MapElement) ArrayList(java.util.ArrayList) MapRoad(uk.me.parabola.mkgmap.general.MapRoad) MapPoint(uk.me.parabola.mkgmap.general.MapPoint)

Example 2 with MapElement

use of uk.me.parabola.mkgmap.general.MapElement in project mkgmap by openstreetmap.

the class MapArea method addPolygons.

/**
 * Add the polygons
 * @param src The map data.
 * @param resolution The current resolution of the layer.
 */
private void addPolygons(MapDataSource src, final int resolution) {
    MapFilterChain chain = new MapFilterChain() {

        public void doFilter(MapElement element) {
            MapShape shape = (MapShape) element;
            addShape(shape);
        }
    };
    PolygonSubdivSizeSplitterFilter filter = new PolygonSubdivSizeSplitterFilter();
    FilterConfig config = new FilterConfig();
    config.setResolution(resolution);
    config.setBounds(bounds);
    filter.init(config);
    for (MapShape s : src.getShapes()) {
        if (s.getMaxResolution() < resolution)
            continue;
        if (splitPolygonsIntoArea || this.bounds.isEmpty() || this.bounds.contains(s.getBounds()))
            // if splitPolygonsIntoArea, don't want to have other splitting as well.
            // PolygonSubdivSizeSplitterFilter is a bit drastic - filters by both size and number of points
            // so use splitPolygonsIntoArea logic for this as well. This is fine as long as there
            // aren't bits of the shape outside the initial area.
            addShape(s);
        else
            filter.doFilter(s, chain);
    }
}
Also used : PolygonSubdivSizeSplitterFilter(uk.me.parabola.mkgmap.filters.PolygonSubdivSizeSplitterFilter) MapElement(uk.me.parabola.mkgmap.general.MapElement) FilterConfig(uk.me.parabola.mkgmap.filters.FilterConfig) MapFilterChain(uk.me.parabola.mkgmap.filters.MapFilterChain) MapShape(uk.me.parabola.mkgmap.general.MapShape)

Example 3 with MapElement

use of uk.me.parabola.mkgmap.general.MapElement in project mkgmap by openstreetmap.

the class StyleTester method runSimpleTest.

/**
 * Run a simple test with a combined test file.
 * @param filename The test file contains text way definitions and a style
 * file all in one.
 */
public static void runSimpleTest(String filename) {
    try {
        FileReader reader = new FileReader(filename);
        BufferedReader br = new BufferedReader(reader);
        List<Way> ways = readSimpleTestFile(br);
        List<String> givenList = readGivenResults();
        boolean noStrict = false;
        if (!givenList.isEmpty() && Objects.equals(givenList.get(0), "NO-STRICT")) {
            givenList.remove(0);
            noStrict = true;
        }
        List<MapElement> strictResults = new ArrayList<>();
        List<MapElement> results = new ArrayList<>();
        List<String> actual = new ArrayList<>();
        List<String> expected = new ArrayList<>();
        for (Way w : ways) {
            OsmConverter normal = new StyleTester("styletester.style", new LocalMapCollector(results), false);
            String prefix = "WAY " + w.getId() + ": ";
            normal.convertWay(w.copy());
            normal.end();
            actual.addAll(formatResults(prefix, results));
            results.clear();
            if (!noStrict) {
                OsmConverter strict = new StyleTester("styletester.style", new LocalMapCollector(strictResults), true);
                strict.convertWay(w.copy());
                strict.end();
                expected.addAll(formatResults(prefix, strictResults));
                strictResults.clear();
            }
        }
        printResult("", actual);
        if (!noStrict && !Objects.equals(actual, expected)) {
            out.println("ERROR expected result is:");
            printResult("|", expected);
        }
        if ((!givenList.isEmpty() || forceUseOfGiven) && !Objects.equals(actual, givenList)) {
            out.println("ERROR given results were:");
            printResult("", givenList);
        }
    } catch (FileNotFoundException e) {
        System.err.println("Cannot open test file " + filename);
    } catch (IOException e) {
        System.err.println("Failure while reading test file " + filename);
    }
}
Also used : MapElement(uk.me.parabola.mkgmap.general.MapElement) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Way(uk.me.parabola.mkgmap.reader.osm.Way) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) OsmConverter(uk.me.parabola.mkgmap.reader.osm.OsmConverter)

Example 4 with MapElement

use of uk.me.parabola.mkgmap.general.MapElement in project mkgmap by openstreetmap.

the class MapArea method addLines.

/**
 * Add the lines, making sure that they are not too big for resolution
 * that we are working with.
 * @param src The map data.
 * @param resolution The current resolution of the layer.
 */
private void addLines(MapDataSource src, final int resolution) {
    // Split lines for size, such that it is appropriate for the
    // resolution that it is at.
    MapFilterChain chain = new MapFilterChain() {

        public void doFilter(MapElement element) {
            MapLine line = (MapLine) element;
            addLine(line);
        }
    };
    LineSizeSplitterFilter filter = new LineSizeSplitterFilter();
    FilterConfig config = new FilterConfig();
    config.setResolution(resolution);
    config.setBounds(bounds);
    filter.init(config);
    for (MapLine l : src.getLines()) {
        if (l.getMaxResolution() < resolution)
            continue;
        // %%% ??? if not appearing at this level no need to filter
        filter.doFilter(l, chain);
    }
}
Also used : MapElement(uk.me.parabola.mkgmap.general.MapElement) MapLine(uk.me.parabola.mkgmap.general.MapLine) LineSizeSplitterFilter(uk.me.parabola.mkgmap.filters.LineSizeSplitterFilter) FilterConfig(uk.me.parabola.mkgmap.filters.FilterConfig) MapFilterChain(uk.me.parabola.mkgmap.filters.MapFilterChain)

Aggregations

MapElement (uk.me.parabola.mkgmap.general.MapElement)4 ArrayList (java.util.ArrayList)2 FilterConfig (uk.me.parabola.mkgmap.filters.FilterConfig)2 MapFilterChain (uk.me.parabola.mkgmap.filters.MapFilterChain)2 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 LineSizeSplitterFilter (uk.me.parabola.mkgmap.filters.LineSizeSplitterFilter)1 PolygonSubdivSizeSplitterFilter (uk.me.parabola.mkgmap.filters.PolygonSubdivSizeSplitterFilter)1 MapLine (uk.me.parabola.mkgmap.general.MapLine)1 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)1 MapRoad (uk.me.parabola.mkgmap.general.MapRoad)1 MapShape (uk.me.parabola.mkgmap.general.MapShape)1 OsmConverter (uk.me.parabola.mkgmap.reader.osm.OsmConverter)1 Way (uk.me.parabola.mkgmap.reader.osm.Way)1