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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations