Search in sources :

Example 1 with FilterConfig

use of uk.me.parabola.mkgmap.filters.FilterConfig 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 2 with FilterConfig

use of uk.me.parabola.mkgmap.filters.FilterConfig in project mkgmap by openstreetmap.

the class MapBuilder method processShapes.

/**
 * Step through the polygons, filter, simplify if necessary, and create a map
 * shape which is then added to the map.
 *
 * Note that the location and resolution of map elements is relative to the
 * subdivision that they occur in.
 *
 * @param map	The map to add polygons to.
 * @param div	The subdivision that the polygons belong to.
 * @param shapes The polygons to be added.
 */
private void processShapes(Map map, Subdivision div, List<MapShape> shapes) {
    // Signal that we are beginning to draw the shapes.
    div.startShapes();
    int res = div.getResolution();
    FilterConfig config = new FilterConfig();
    config.setResolution(res);
    config.setLevel(div.getZoom().getLevel());
    config.setRoutable(doRoads);
    if (mergeShapes) {
        ShapeMergeFilter shapeMergeFilter = new ShapeMergeFilter(res, orderByDecreasingArea);
        List<MapShape> mergedShapes = shapeMergeFilter.merge(shapes);
        shapes = mergedShapes;
    }
    if (orderByDecreasingArea && shapes.size() > 1) {
        // sort so that the shape with the largest area is processed first
        Collections.sort(shapes, new Comparator<MapShape>() {

            public int compare(MapShape s1, MapShape s2) {
                return Long.compare(Math.abs(s2.getFullArea()), Math.abs(s1.getFullArea()));
            }
        });
    }
    preserveHorizontalAndVerticalLines(res, shapes);
    LayerFilterChain filters = new LayerFilterChain(config);
    filters.addFilter(new PolygonSplitterFilter());
    if (enableLineCleanFilters && (res < 24)) {
        filters.addFilter(new RoundCoordsFilter());
        int sizefilterVal = getMinSizePolygonForResolution(res);
        if (sizefilterVal > 0)
            filters.addFilter(new SizeFilter(sizefilterVal));
        // Is there an similar algorithm for polygons?
        if (reducePointErrorPolygon > 0)
            filters.addFilter(new DouglasPeuckerFilter(reducePointErrorPolygon));
    }
    filters.addFilter(new RemoveObsoletePointsFilter());
    filters.addFilter(new RemoveEmpty());
    filters.addFilter(new LinePreparerFilter(div));
    filters.addFilter(new ShapeAddFilter(div, map));
    for (MapShape shape : shapes) {
        if (shape.getMinResolution() > res)
            continue;
        filters.startFilter(shape);
    }
}
Also used : PolygonSplitterFilter(uk.me.parabola.mkgmap.filters.PolygonSplitterFilter) DouglasPeuckerFilter(uk.me.parabola.mkgmap.filters.DouglasPeuckerFilter) SizeFilter(uk.me.parabola.mkgmap.filters.SizeFilter) LinePreparerFilter(uk.me.parabola.mkgmap.filters.LinePreparerFilter) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) Point(uk.me.parabola.imgfmt.app.trergn.Point) RoundCoordsFilter(uk.me.parabola.mkgmap.filters.RoundCoordsFilter) RemoveEmpty(uk.me.parabola.mkgmap.filters.RemoveEmpty) ShapeMergeFilter(uk.me.parabola.mkgmap.filters.ShapeMergeFilter) RemoveObsoletePointsFilter(uk.me.parabola.mkgmap.filters.RemoveObsoletePointsFilter) FilterConfig(uk.me.parabola.mkgmap.filters.FilterConfig) MapShape(uk.me.parabola.mkgmap.general.MapShape)

Example 3 with FilterConfig

use of uk.me.parabola.mkgmap.filters.FilterConfig in project mkgmap by openstreetmap.

the class MapBuilder method processLines.

/**
 * Step through the lines, filter, simplify if necessary, and create a map
 * line which is then added to the map.
 *
 * Note that the location and resolution of map elements is relative to the
 * subdivision that they occur in.
 *
 * @param map	The map to add points to.
 * @param div	The subdivision that the lines belong to.
 * @param lines The lines to be added.
 */
private void processLines(Map map, Subdivision div, List<MapLine> lines) {
    // Signal that we are beginning to draw the lines.
    div.startLines();
    int res = div.getResolution();
    FilterConfig config = new FilterConfig();
    config.setResolution(res);
    config.setLevel(div.getZoom().getLevel());
    config.setRoutable(doRoads);
    // Maybe more efficient if merging before creating subdivisions.
    if (mergeLines) {
        LineMergeFilter merger = new LineMergeFilter();
        lines = merger.merge(lines, res);
    }
    LayerFilterChain filters = new LayerFilterChain(config);
    if (enableLineCleanFilters && (res < 24)) {
        filters.addFilter(new RoundCoordsFilter());
        filters.addFilter(new SizeFilter(MIN_SIZE_LINE));
        if (reducePointError > 0)
            filters.addFilter(new DouglasPeuckerFilter(reducePointError));
    }
    filters.addFilter(new LineSplitterFilter());
    filters.addFilter(new RemoveEmpty());
    filters.addFilter(new RemoveObsoletePointsFilter());
    filters.addFilter(new LinePreparerFilter(div));
    filters.addFilter(new LineAddFilter(div, map, doRoads));
    for (MapLine line : lines) {
        if (line.getMinResolution() > res)
            continue;
        filters.startFilter(line);
    }
}
Also used : MapLine(uk.me.parabola.mkgmap.general.MapLine) DouglasPeuckerFilter(uk.me.parabola.mkgmap.filters.DouglasPeuckerFilter) SizeFilter(uk.me.parabola.mkgmap.filters.SizeFilter) LinePreparerFilter(uk.me.parabola.mkgmap.filters.LinePreparerFilter) LineMergeFilter(uk.me.parabola.mkgmap.filters.LineMergeFilter) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint) Point(uk.me.parabola.imgfmt.app.trergn.Point) RoundCoordsFilter(uk.me.parabola.mkgmap.filters.RoundCoordsFilter) RemoveEmpty(uk.me.parabola.mkgmap.filters.RemoveEmpty) RemoveObsoletePointsFilter(uk.me.parabola.mkgmap.filters.RemoveObsoletePointsFilter) FilterConfig(uk.me.parabola.mkgmap.filters.FilterConfig) LineSplitterFilter(uk.me.parabola.mkgmap.filters.LineSplitterFilter)

Example 4 with FilterConfig

use of uk.me.parabola.mkgmap.filters.FilterConfig 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

FilterConfig (uk.me.parabola.mkgmap.filters.FilterConfig)4 Point (uk.me.parabola.imgfmt.app.trergn.Point)2 DouglasPeuckerFilter (uk.me.parabola.mkgmap.filters.DouglasPeuckerFilter)2 LinePreparerFilter (uk.me.parabola.mkgmap.filters.LinePreparerFilter)2 MapFilterChain (uk.me.parabola.mkgmap.filters.MapFilterChain)2 RemoveEmpty (uk.me.parabola.mkgmap.filters.RemoveEmpty)2 RemoveObsoletePointsFilter (uk.me.parabola.mkgmap.filters.RemoveObsoletePointsFilter)2 RoundCoordsFilter (uk.me.parabola.mkgmap.filters.RoundCoordsFilter)2 SizeFilter (uk.me.parabola.mkgmap.filters.SizeFilter)2 MapElement (uk.me.parabola.mkgmap.general.MapElement)2 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)2 MapLine (uk.me.parabola.mkgmap.general.MapLine)2 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)2 MapShape (uk.me.parabola.mkgmap.general.MapShape)2 LineMergeFilter (uk.me.parabola.mkgmap.filters.LineMergeFilter)1 LineSizeSplitterFilter (uk.me.parabola.mkgmap.filters.LineSizeSplitterFilter)1 LineSplitterFilter (uk.me.parabola.mkgmap.filters.LineSplitterFilter)1 PolygonSplitterFilter (uk.me.parabola.mkgmap.filters.PolygonSplitterFilter)1 PolygonSubdivSizeSplitterFilter (uk.me.parabola.mkgmap.filters.PolygonSubdivSizeSplitterFilter)1 ShapeMergeFilter (uk.me.parabola.mkgmap.filters.ShapeMergeFilter)1