Search in sources :

Example 1 with ShapeMergeFilter

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

Aggregations

Point (uk.me.parabola.imgfmt.app.trergn.Point)1 DouglasPeuckerFilter (uk.me.parabola.mkgmap.filters.DouglasPeuckerFilter)1 FilterConfig (uk.me.parabola.mkgmap.filters.FilterConfig)1 LinePreparerFilter (uk.me.parabola.mkgmap.filters.LinePreparerFilter)1 PolygonSplitterFilter (uk.me.parabola.mkgmap.filters.PolygonSplitterFilter)1 RemoveEmpty (uk.me.parabola.mkgmap.filters.RemoveEmpty)1 RemoveObsoletePointsFilter (uk.me.parabola.mkgmap.filters.RemoveObsoletePointsFilter)1 RoundCoordsFilter (uk.me.parabola.mkgmap.filters.RoundCoordsFilter)1 ShapeMergeFilter (uk.me.parabola.mkgmap.filters.ShapeMergeFilter)1 SizeFilter (uk.me.parabola.mkgmap.filters.SizeFilter)1 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)1 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)1 MapShape (uk.me.parabola.mkgmap.general.MapShape)1