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

184 wiersze
8.3 KiB
Java
Czysty Zwykły widok Historia

package com.onthegomap.planetiler.config;
2021-09-10 00:46:20 +00:00
import com.onthegomap.planetiler.collection.LongLongMap;
import com.onthegomap.planetiler.collection.Storage;
import com.onthegomap.planetiler.reader.osm.PolyFileReader;
import com.onthegomap.planetiler.util.Parse;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
2021-09-10 00:46:20 +00:00
import java.time.Duration;
import java.util.stream.Stream;
2021-09-10 00:46:20 +00:00
/**
* 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,
int featureWriteThreads,
int featureProcessThreads,
int featureReadThreads,
2021-09-10 00:46:20 +00:00
Duration logInterval,
int minzoom,
int maxzoom,
int maxzoomForRendering,
boolean force,
2021-09-10 00:46:20 +00:00
boolean gzipTempStorage,
boolean mmapTempStorage,
int sortMaxReaders,
int sortMaxWriters,
2021-09-10 00:46:20 +00:00
String nodeMapType,
String nodeMapStorage,
boolean nodeMapMadvise,
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,
double downloadMaxBandwidth,
2021-09-10 00:46:20 +00:00
double minFeatureSizeAtMaxZoom,
double minFeatureSizeBelowMaxZoom,
double simplifyToleranceAtMaxZoom,
double simplifyToleranceBelowMaxZoom,
boolean osmLazyReads,
2022-07-14 09:26:53 +00:00
boolean skipFilledTiles,
int tileWarningSizeBytes,
Boolean color
2021-09-10 00:46:20 +00:00
) {
public static final int MIN_MINZOOM = 0;
2022-07-26 11:51:31 +00:00
public static final int MAX_MAXZOOM = 15;
private static final int DEFAULT_MAXZOOM = 14;
2021-09-10 00:46:20 +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
}
public static PlanetilerConfig defaults() {
2021-09-10 00:46:20 +00:00
return from(Arguments.of());
}
public static PlanetilerConfig from(Arguments arguments) {
// 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);
int threads = arguments.threads();
int featureWriteThreads =
arguments.getInteger("write_threads", "number of threads to use when writing temp features",
// defaults: <48 cpus=1 writer, 48-80=2 writers, 80-112=3 writers, 112-144=4 writers, ...
Math.max(1, (threads - 16) / 32 + 1));
int featureProcessThreads =
arguments.getInteger("process_threads", "number of threads to use when processing input features",
Math.max(threads < 4 ? threads : (threads - featureWriteThreads), 1));
Bounds bounds = new Bounds(arguments.bounds("bounds", "bounds"));
Path polygonFile =
arguments.file("polygon", "a .poly file that limits output to tiles intersecting the shape", null);
if (polygonFile != null) {
try {
bounds.setShape(PolyFileReader.parsePolyFile(polygonFile));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
2022-07-26 11:51:31 +00:00
int minzoom = arguments.getInteger("minzoom", "minimum zoom level", MIN_MINZOOM);
int maxzoom = arguments.getInteger("maxzoom", "maximum zoom level up to " + MAX_MAXZOOM, DEFAULT_MAXZOOM);
int renderMaxzoom =
arguments.getInteger("render_maxzoom", "maximum rendering zoom level up to " + MAX_MAXZOOM,
Math.max(maxzoom, DEFAULT_MAXZOOM));
return new PlanetilerConfig(
2021-09-10 00:46:20 +00:00
arguments,
bounds,
threads,
featureWriteThreads,
featureProcessThreads,
arguments.getInteger("feature_read_threads", "number of threads to use when reading features at tile write time",
threads < 32 ? 1 : 2),
2021-09-10 00:46:20 +00:00
arguments.getDuration("loginterval", "time between logs", "10s"),
2022-07-26 11:51:31 +00:00
minzoom,
maxzoom,
renderMaxzoom,
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),
2022-05-28 09:23:36 +00:00
arguments.getBoolean("mmap_temp", "use memory-mapped IO for temp feature files", true),
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, one of " + Stream.of(LongLongMap.Type.values()).map(
t -> t.id()).toList(), LongLongMap.Type.SPARSE_ARRAY.id()),
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(),
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",
"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),
Parse.bandwidth(arguments.getString("download_max_bandwidth",
"Maximum bandwidth to consume when downloading files in units mb/s, mbps, kbps, etc.", "")),
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",
true),
arguments.getBoolean("skip_filled_tiles",
"Skip writing tiles containing only polygon fills to the output",
2022-07-14 09:26:53 +00:00
false),
(int) (arguments.getDouble("tile_warning_size_mb",
"Maximum size in megabytes of a tile to emit a warning about",
1d) * 1024 * 1024),
arguments.getBooleanObject("color", "Color the terminal output")
2021-09-10 00:46:20 +00:00
);
}
public double minFeatureSize(int zoom) {
return zoom >= maxzoomForRendering ? minFeatureSizeAtMaxZoom : minFeatureSizeBelowMaxZoom;
2021-09-10 00:46:20 +00:00
}
public double tolerance(int zoom) {
return zoom >= maxzoomForRendering ? simplifyToleranceAtMaxZoom : simplifyToleranceBelowMaxZoom;
2021-09-10 00:46:20 +00:00
}
}