From d512731d0676de777a60121eae04d2ee7b4f7009 Mon Sep 17 00:00:00 2001 From: Emux Date: Thu, 12 Dec 2019 12:17:42 +0200 Subject: [PATCH] Mapsforge: reduce points on-the-fly while reading from map files --- .../tiling/source/mapfile/MapDatabase.java | 53 +++++++++++++------ vtm/src/org/oscim/utils/Parameters.java | 5 ++ 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/vtm/src/org/oscim/tiling/source/mapfile/MapDatabase.java b/vtm/src/org/oscim/tiling/source/mapfile/MapDatabase.java index fcdf2c57..f078243b 100644 --- a/vtm/src/org/oscim/tiling/source/mapfile/MapDatabase.java +++ b/vtm/src/org/oscim/tiling/source/mapfile/MapDatabase.java @@ -52,7 +52,7 @@ import static org.oscim.tiling.QueryResult.SUCCESS; /** * A class for reading binary map files. * - * @see Specification + * @see Specification */ public class MapDatabase implements ITileDataSource { /** @@ -187,6 +187,19 @@ public class MapDatabase implements ITileDataSource { public static boolean wayFilterEnabled = true; public static int wayFilterDistance = 20; + /** + * Reduce points on-the-fly while reading from map files. + */ + public static int SIMPLIFICATION_MIN_ZOOM = 8; + public static int SIMPLIFICATION_MAX_ZOOM = 11; + + /** + * Mapsforge artificial tags for land/sea areas. + */ + private static final Tag TAG_ISSEA = new Tag("natural", "issea"); + private static final Tag TAG_NOSEA = new Tag("natural", "nosea"); + private static final Tag TAG_SEA = new Tag("natural", "sea"); + private long mFileSize; private boolean mDebugFile; private RandomAccessFile mInputFile; @@ -250,20 +263,25 @@ public class MapDatabase implements ITileDataSource { mTileProjection.setTile(tile); //mTile = tile; - /* size of tile in map coordinates; */ - double size = 1.0 / (1 << tile.zoomLevel); + if (tile.zoomLevel < SIMPLIFICATION_MIN_ZOOM || tile.zoomLevel > SIMPLIFICATION_MAX_ZOOM) { + minDeltaLat = 0; + minDeltaLon = 0; + } else { + /* size of tile in map coordinates; */ + double size = 1.0 / (1 << tile.zoomLevel); - /* simplification tolerance */ - int pixel = (tile.zoomLevel > 11) ? 1 : 2; + /* simplification tolerance */ + int pixel = 2; - int simplify = Tile.SIZE / pixel; + int simplify = Tile.SIZE / pixel; - /* translate screen pixel for tile to latitude and longitude - * tolerance for point reduction before projection. */ - minDeltaLat = (int) (Math.abs(MercatorProjection.toLatitude(tile.y + size) - - MercatorProjection.toLatitude(tile.y)) * 1e6) / simplify; - minDeltaLon = (int) (Math.abs(MercatorProjection.toLongitude(tile.x + size) - - MercatorProjection.toLongitude(tile.x)) * 1e6) / simplify; + /* translate screen pixel for tile to latitude and longitude + * tolerance for point reduction before projection. */ + minDeltaLat = (int) (Math.abs(MercatorProjection.toLatitude(tile.y + size) + - MercatorProjection.toLatitude(tile.y)) * 1e6) / simplify; + minDeltaLon = (int) (Math.abs(MercatorProjection.toLongitude(tile.x + size) + - MercatorProjection.toLongitude(tile.x)) * 1e6) / simplify; + } QueryParameters queryParameters = new QueryParameters(); queryParameters.queryZoomLevel = @@ -797,11 +815,12 @@ public class MapDatabase implements ITileDataSource { } else if (lat == pLat && lon == pLon) { /* drop small distance intermediate nodes */ //log.debug("drop zero delta "); - } else /*if ((deltaLon > minDeltaLon || deltaLon < -minDeltaLon - || deltaLat > minDeltaLat || deltaLat < -minDeltaLat) - || e.tags.contains("natural", "nosea"))*/ { - // Avoid additional simplification - // https://github.com/mapsforge/vtm/issues/39 + } else if (!Parameters.SIMPLIFICATION + || (e.tags.contains(TAG_ISSEA) + || e.tags.contains(TAG_SEA) + || e.tags.contains(TAG_NOSEA) + || deltaLon > minDeltaLon || deltaLon < -minDeltaLon + || deltaLat > minDeltaLat || deltaLat < -minDeltaLat)) { outBuffer[outPos++] = pLon = lon; outBuffer[outPos++] = pLat = lat; cnt += 2; diff --git a/vtm/src/org/oscim/utils/Parameters.java b/vtm/src/org/oscim/utils/Parameters.java index 158fd742..3881201f 100644 --- a/vtm/src/org/oscim/utils/Parameters.java +++ b/vtm/src/org/oscim/utils/Parameters.java @@ -62,6 +62,11 @@ public final class Parameters { */ public static boolean POT_TEXTURES = false; + /** + * Reduce points on-the-fly while reading from map files. + */ + public static boolean SIMPLIFICATION = false; + /** * Texture atlas in themes. */