planetiler/planetiler-core/src/main/java/com/onthegomap/planetiler/config/PlanetilerConfig.java

110 wiersze
4.6 KiB
Java
Czysty Zwykły widok Historia

package com.onthegomap.planetiler.config;
2021-09-10 00:46:20 +00:00
import java.time.Duration;
/**
* Holder for common parameters used by many components in planetiler.
2021-09-10 00:46:20 +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,
boolean force,
2021-09-10 00:46:20 +00:00
boolean gzipTempStorage,
int sortMaxReaders,
int sortMaxWriters,
2021-09-10 00:46:20 +00:00
String nodeMapType,
String nodeMapStorage,
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,
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;
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
}
public static PlanetilerConfig defaults() {
2021-09-10 00:46:20 +00:00
return from(Arguments.of());
}
public static PlanetilerConfig from(Arguments arguments) {
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),
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),
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
.getString("nodemap_type", "type of node location map: noop, sortedtable, or sparsearray", "sortedtable"),
arguments.getString("nodemap_storage", "storage for location map: mmap or ram", "mmap"),
arguments.getString("http_user_agent", "User-Agent header to set when downloading files over HTTP",
"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",
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;
}
}