Mapsforge: reduce points on-the-fly while reading from map files

This commit is contained in:
Emux
2019-12-12 12:17:42 +02:00
parent b2a8d3040a
commit d512731d06
2 changed files with 41 additions and 17 deletions

View File

@@ -52,7 +52,7 @@ import static org.oscim.tiling.QueryResult.SUCCESS;
/** /**
* A class for reading binary map files. * A class for reading binary map files.
* *
* @see <a href="http://code.google.com/p/mapsforge/wiki/SpecificationBinaryMapFile">Specification</a> * @see <a href="https://github.com/mapsforge/mapsforge/blob/master/docs/Specification-Binary-Map-File.md">Specification</a>
*/ */
public class MapDatabase implements ITileDataSource { public class MapDatabase implements ITileDataSource {
/** /**
@@ -187,6 +187,19 @@ public class MapDatabase implements ITileDataSource {
public static boolean wayFilterEnabled = true; public static boolean wayFilterEnabled = true;
public static int wayFilterDistance = 20; 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 long mFileSize;
private boolean mDebugFile; private boolean mDebugFile;
private RandomAccessFile mInputFile; private RandomAccessFile mInputFile;
@@ -250,11 +263,15 @@ public class MapDatabase implements ITileDataSource {
mTileProjection.setTile(tile); mTileProjection.setTile(tile);
//mTile = tile; //mTile = tile;
if (tile.zoomLevel < SIMPLIFICATION_MIN_ZOOM || tile.zoomLevel > SIMPLIFICATION_MAX_ZOOM) {
minDeltaLat = 0;
minDeltaLon = 0;
} else {
/* size of tile in map coordinates; */ /* size of tile in map coordinates; */
double size = 1.0 / (1 << tile.zoomLevel); double size = 1.0 / (1 << tile.zoomLevel);
/* simplification tolerance */ /* simplification tolerance */
int pixel = (tile.zoomLevel > 11) ? 1 : 2; int pixel = 2;
int simplify = Tile.SIZE / pixel; int simplify = Tile.SIZE / pixel;
@@ -264,6 +281,7 @@ public class MapDatabase implements ITileDataSource {
- MercatorProjection.toLatitude(tile.y)) * 1e6) / simplify; - MercatorProjection.toLatitude(tile.y)) * 1e6) / simplify;
minDeltaLon = (int) (Math.abs(MercatorProjection.toLongitude(tile.x + size) minDeltaLon = (int) (Math.abs(MercatorProjection.toLongitude(tile.x + size)
- MercatorProjection.toLongitude(tile.x)) * 1e6) / simplify; - MercatorProjection.toLongitude(tile.x)) * 1e6) / simplify;
}
QueryParameters queryParameters = new QueryParameters(); QueryParameters queryParameters = new QueryParameters();
queryParameters.queryZoomLevel = queryParameters.queryZoomLevel =
@@ -797,11 +815,12 @@ public class MapDatabase implements ITileDataSource {
} else if (lat == pLat && lon == pLon) { } else if (lat == pLat && lon == pLon) {
/* drop small distance intermediate nodes */ /* drop small distance intermediate nodes */
//log.debug("drop zero delta "); //log.debug("drop zero delta ");
} else /*if ((deltaLon > minDeltaLon || deltaLon < -minDeltaLon } else if (!Parameters.SIMPLIFICATION
|| deltaLat > minDeltaLat || deltaLat < -minDeltaLat) || (e.tags.contains(TAG_ISSEA)
|| e.tags.contains("natural", "nosea"))*/ { || e.tags.contains(TAG_SEA)
// Avoid additional simplification || e.tags.contains(TAG_NOSEA)
// https://github.com/mapsforge/vtm/issues/39 || deltaLon > minDeltaLon || deltaLon < -minDeltaLon
|| deltaLat > minDeltaLat || deltaLat < -minDeltaLat)) {
outBuffer[outPos++] = pLon = lon; outBuffer[outPos++] = pLon = lon;
outBuffer[outPos++] = pLat = lat; outBuffer[outPos++] = pLat = lat;
cnt += 2; cnt += 2;

View File

@@ -62,6 +62,11 @@ public final class Parameters {
*/ */
public static boolean POT_TEXTURES = false; 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. * Texture atlas in themes.
*/ */