2021-12-23 10:42:24 +00:00
|
|
|
package com.onthegomap.planetiler.config;
|
2021-09-10 00:46:20 +00:00
|
|
|
|
2022-03-19 09:46:03 +00:00
|
|
|
import com.onthegomap.planetiler.collection.LongLongMap;
|
|
|
|
import com.onthegomap.planetiler.collection.Storage;
|
2021-09-10 00:46:20 +00:00
|
|
|
import java.time.Duration;
|
2022-03-19 09:46:03 +00:00
|
|
|
import java.util.stream.Stream;
|
2021-09-10 00:46:20 +00:00
|
|
|
|
|
|
|
/**
|
2021-12-23 10:42:24 +00:00
|
|
|
* Holder for common parameters used by many components in planetiler.
|
2021-09-10 00:46:20 +00:00
|
|
|
*/
|
2021-12-23 10:42:24 +00:00
|
|
|
public record PlanetilerConfig(
|
2021-09-10 00:46:20 +00:00
|
|
|
Arguments arguments,
|
|
|
|
Bounds bounds,
|
|
|
|
int threads,
|
|
|
|
Duration logInterval,
|
|
|
|
int minzoom,
|
|
|
|
int maxzoom,
|
|
|
|
boolean deferIndexCreation,
|
|
|
|
boolean optimizeDb,
|
|
|
|
boolean emitTilesInOrder,
|
2022-03-03 12:25:24 +00:00
|
|
|
boolean force,
|
2021-09-10 00:46:20 +00:00
|
|
|
boolean gzipTempStorage,
|
2021-10-21 00:17:59 +00:00
|
|
|
int sortMaxReaders,
|
|
|
|
int sortMaxWriters,
|
2021-09-10 00:46:20 +00:00
|
|
|
String nodeMapType,
|
|
|
|
String nodeMapStorage,
|
2022-03-09 12:22:33 +00:00
|
|
|
boolean nodeMapMadvise,
|
2022-03-23 00:34:54 +00:00
|
|
|
String multipolygonGeometryStorage,
|
|
|
|
boolean multipolygonGeometryMadvise,
|
2021-09-10 00:46:20 +00:00
|
|
|
String httpUserAgent,
|
2021-10-20 01:57:47 +00:00
|
|
|
Duration httpTimeout,
|
2022-03-05 13:52:20 +00:00
|
|
|
int httpRetries,
|
2021-10-20 01:57:47 +00:00
|
|
|
long downloadChunkSizeMB,
|
|
|
|
int downloadThreads,
|
2021-09-10 00:46:20 +00:00
|
|
|
double minFeatureSizeAtMaxZoom,
|
|
|
|
double minFeatureSizeBelowMaxZoom,
|
|
|
|
double simplifyToleranceAtMaxZoom,
|
2022-03-01 01:52:30 +00:00
|
|
|
double simplifyToleranceBelowMaxZoom,
|
|
|
|
boolean osmLazyReads
|
2021-09-10 00:46:20 +00:00
|
|
|
) {
|
|
|
|
|
|
|
|
public static final int MIN_MINZOOM = 0;
|
|
|
|
public static final int MAX_MAXZOOM = 14;
|
|
|
|
|
2021-12-23 10:42:24 +00:00
|
|
|
public PlanetilerConfig {
|
2021-09-10 00:46:20 +00:00
|
|
|
if (minzoom > maxzoom) {
|
|
|
|
throw new IllegalArgumentException("Minzoom cannot be greater than maxzoom");
|
|
|
|
}
|
|
|
|
if (minzoom < MIN_MINZOOM) {
|
|
|
|
throw new IllegalArgumentException("Minzoom must be >= " + MIN_MINZOOM + ", was " + minzoom);
|
|
|
|
}
|
|
|
|
if (maxzoom > MAX_MAXZOOM) {
|
|
|
|
throw new IllegalArgumentException("Max zoom must be <= " + MAX_MAXZOOM + ", was " + maxzoom);
|
|
|
|
}
|
2022-03-05 13:52:20 +00:00
|
|
|
if (httpRetries < 0) {
|
|
|
|
throw new IllegalArgumentException("HTTP Retries must be >= 0, was " + httpRetries);
|
|
|
|
}
|
2021-09-10 00:46:20 +00:00
|
|
|
}
|
|
|
|
|
2021-12-23 10:42:24 +00:00
|
|
|
public static PlanetilerConfig defaults() {
|
2021-09-10 00:46:20 +00:00
|
|
|
return from(Arguments.of());
|
|
|
|
}
|
|
|
|
|
2021-12-23 10:42:24 +00:00
|
|
|
public static PlanetilerConfig from(Arguments arguments) {
|
2022-03-23 00:34:54 +00:00
|
|
|
// use --madvise and --storage options as default for temp storage, but allow users to override them explicitly for
|
|
|
|
// multipolygon geometries or node locations
|
|
|
|
boolean defaultMadvise =
|
|
|
|
arguments.getBoolean("madvise",
|
|
|
|
"default value for whether to use linux madvise(random) to improve memory-mapped read performance for temporary storage",
|
|
|
|
true);
|
|
|
|
// nodemap_storage was previously the only option, so if that's set make it the default
|
|
|
|
String fallbackTempStorage = arguments.getArg("nodemap_storage", Storage.MMAP.id());
|
|
|
|
String defaultTempStorage = arguments.getString("storage",
|
|
|
|
"default storage type for temporary data, one of " + Stream.of(Storage.values()).map(
|
|
|
|
Storage::id).toList(),
|
|
|
|
fallbackTempStorage);
|
2021-12-23 10:42:24 +00:00
|
|
|
return new PlanetilerConfig(
|
2021-09-10 00:46:20 +00:00
|
|
|
arguments,
|
|
|
|
new Bounds(arguments.bounds("bounds", "bounds")),
|
|
|
|
arguments.threads(),
|
|
|
|
arguments.getDuration("loginterval", "time between logs", "10s"),
|
|
|
|
arguments.getInteger("minzoom", "minimum zoom level", MIN_MINZOOM),
|
|
|
|
arguments.getInteger("maxzoom", "maximum zoom level (limit 14)", MAX_MAXZOOM),
|
|
|
|
arguments.getBoolean("defer_mbtiles_index_creation", "skip adding index to mbtiles file", false),
|
|
|
|
arguments.getBoolean("optimize_db", "optimize mbtiles after writing", false),
|
|
|
|
arguments.getBoolean("emit_tiles_in_order", "emit tiles in index order", true),
|
2022-03-03 12:25:24 +00:00
|
|
|
arguments.getBoolean("force", "overwriting output file and ignore disk/RAM warnings", false),
|
2021-09-10 00:46:20 +00:00
|
|
|
arguments.getBoolean("gzip_temp", "gzip temporary feature storage (uses more CPU, but less disk space)", false),
|
2021-10-21 00:17:59 +00:00
|
|
|
arguments.getInteger("sort_max_readers", "maximum number of concurrent read threads to use when sorting chunks",
|
|
|
|
6),
|
|
|
|
arguments.getInteger("sort_max_writers", "maximum number of concurrent write threads to use when sorting chunks",
|
|
|
|
6),
|
2021-09-10 00:46:20 +00:00
|
|
|
arguments
|
2022-03-19 09:46:03 +00:00
|
|
|
.getString("nodemap_type", "type of node location map, one of " + Stream.of(LongLongMap.Type.values()).map(
|
|
|
|
t -> t.id()).toList(), LongLongMap.Type.SPARSE_ARRAY.id()),
|
2022-03-23 00:34:54 +00:00
|
|
|
arguments.getString("nodemap_storage", "storage for node location map, one of " + Stream.of(Storage.values()).map(
|
|
|
|
Storage::id).toList(), defaultTempStorage),
|
|
|
|
arguments.getBoolean("nodemap_madvise", "use linux madvise(random) for node locations", defaultMadvise),
|
|
|
|
arguments.getString("multipolygon_geometry_storage",
|
2022-03-25 23:47:31 +00:00
|
|
|
"storage for multipolygon geometries, one of " + Stream.of(Storage.values()).map(Storage::id).toList(),
|
2022-03-23 00:34:54 +00:00
|
|
|
defaultTempStorage),
|
|
|
|
arguments.getBoolean("multipolygon_geometry_madvise",
|
2022-03-25 23:47:31 +00:00
|
|
|
"use linux madvise(random) for temporary multipolygon geometry storage", defaultMadvise),
|
2021-09-10 00:46:20 +00:00
|
|
|
arguments.getString("http_user_agent", "User-Agent header to set when downloading files over HTTP",
|
2021-12-23 10:42:24 +00:00
|
|
|
"Planetiler downloader (https://github.com/onthegomap/planetiler)"),
|
2021-10-20 01:57:47 +00:00
|
|
|
arguments.getDuration("http_timeout", "Timeout to use when downloading files over HTTP", "30s"),
|
2022-03-05 13:52:20 +00:00
|
|
|
arguments.getInteger("http_retries", "Retries to use when downloading files over HTTP", 1),
|
2021-10-20 01:57:47 +00:00
|
|
|
arguments.getLong("download_chunk_size_mb", "Size of file chunks to download in parallel in megabytes", 100),
|
|
|
|
arguments.getInteger("download_threads", "Number of parallel threads to use when downloading each file", 1),
|
2021-09-10 00:46:20 +00:00
|
|
|
arguments.getDouble("min_feature_size_at_max_zoom",
|
|
|
|
"Default value for the minimum size in tile pixels of features to emit at the maximum zoom level to allow for overzooming",
|
|
|
|
256d / 4096),
|
|
|
|
arguments.getDouble("min_feature_size",
|
|
|
|
"Default value for the minimum size in tile pixels of features to emit below the maximum zoom level",
|
|
|
|
1),
|
|
|
|
arguments.getDouble("simplify_tolerance_at_max_zoom",
|
|
|
|
"Default value for the tile pixel tolerance to use when simplifying features at the maximum zoom level to allow for overzooming",
|
|
|
|
256d / 4096),
|
|
|
|
arguments.getDouble("simplify_tolerance",
|
|
|
|
"Default value for the tile pixel tolerance to use when simplifying features below the maximum zoom level",
|
2022-03-01 01:52:30 +00:00
|
|
|
0.1d),
|
|
|
|
arguments.getBoolean("osm_lazy_reads",
|
|
|
|
"Read OSM blocks from disk in worker threads",
|
|
|
|
false)
|
2021-09-10 00:46:20 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public double minFeatureSize(int zoom) {
|
|
|
|
return zoom >= maxzoom ? minFeatureSizeAtMaxZoom : minFeatureSizeBelowMaxZoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
public double tolerance(int zoom) {
|
|
|
|
return zoom >= maxzoom ? simplifyToleranceAtMaxZoom : simplifyToleranceBelowMaxZoom;
|
|
|
|
}
|
|
|
|
}
|