use old mbtiles options as fallbacks

use-pmtiles-tile-archive
Mike Barry 2023-03-17 11:35:05 -04:00
rodzic 8050ec4863
commit 30f611649f
11 zmienionych plików z 117 dodań i 80 usunięć

Wyświetl plik

@ -541,39 +541,59 @@ public class Planetiler {
}
/**
* Sets the location of the output archive to write rendered tiles to. Fails if the archive already exists.
* <p>
* To override the location of the file, set {@code argument=newpath} in the arguments.
* Sets the location of the output archive to write rendered tiles to.
*
* @param argument the argument key to check for an override to {@code fallback}
* @param fallback the fallback value if {@code argument} is not set in arguments
* @return this runner instance for chaining
* @see TileArchiveWriter
* @deprecated Use {@link #setOutput(String)} instead
*/
@Deprecated
public Planetiler setOutput(String argument, Path fallback) {
return setOutput(argument, fallback.toString());
}
public Planetiler setOutput(String argument, String fallback) {
this.output = TileArchiveConfig.from(arguments.getString(argument, "output tile archive", fallback));
this.output =
TileArchiveConfig
.from(arguments.getString("output|" + argument, "output tile archive path", fallback.toString()));
return this;
}
/**
* Sets the location of the output archive to write rendered tiles to. Overwrites file if it already exists.
* Sets the location of the output archive to write rendered tiles to. Fails if the archive already exists.
* <p>
* To override the location of the file, set {@code argument=newpath} in the arguments.
* To override the location of the file, set {@code argument=newpath} in the arguments. To set options for the output
* drive add {@code output.mbtiles?arg=value} or add command-line argument {@code mbtiles_arg=value}.
*
* @param argument the argument key to check for an override to {@code fallback}
* @param fallback the fallback value if {@code argument} is not set in arguments
* @param defaultOutputUri The default output URI string to write to.
* @return this runner instance for chaining
* @see TileArchiveWriter
* @see TileArchiveConfig For details on URI strings
*/
public Planetiler setOutput(String defaultOutputUri) {
this.output = TileArchiveConfig.from(arguments.getString("output", "output tile archive URI", defaultOutputUri));
return this;
}
/**
* Sets the location of the output archive to write rendered tiles to.
*
* @deprecated Use {@link #overwriteOutput(String)} instead
*/
@Deprecated
public Planetiler overwriteOutput(String argument, Path fallback) {
this.overwrite = true;
return setOutput(argument, fallback);
}
/**
* Sets the location of the output archive to write rendered tiles to. Overwrites if the archive already exists.
* <p>
* To override the location of the file, set {@code argument=newpath} in the arguments. To set options for the output
* drive add {@code output.mbtiles?arg=value} or add command-line argument {@code mbtiles_arg=value}.
*
* @param defaultOutputUri The default output URI string to write to.
* @return this runner instance for chaining
* @see TileArchiveConfig For details on URI strings
*/
public Planetiler overwriteOutput(String defaultOutputUri) {
this.overwrite = true;
return setOutput(defaultOutputUri);
}
/**
* Reads all elements from all sourced that have been added, generates map features according to the profile, and
* writes the rendered tiles to the output archive.
@ -613,10 +633,10 @@ public class Planetiler {
} else if (overwrite || config.force()) {
output.delete();
} else if (output.exists()) {
throw new IllegalArgumentException(output + " already exists, use the --force argument to overwrite.");
throw new IllegalArgumentException(output.uri() + " already exists, use the --force argument to overwrite.");
}
LOGGER.info("Building {} profile into {} in these phases:", profile.getClass().getSimpleName(), output);
LOGGER.info("Building {} profile into {} in these phases:", profile.getClass().getSimpleName(), output.uri());
if (!toDownload.isEmpty()) {
LOGGER.info(" download: Download sources {}", toDownload.stream().map(d -> d.id).toList());

Wyświetl plik

@ -260,7 +260,7 @@ public class TileArchiveWriter {
lastEncoded = encoded;
lastBytes = bytes;
last = tileFeatures;
if (en.likelyToBeDuplicated() && bytes != null) {
if (archive.deduplicates() && en.likelyToBeDuplicated() && bytes != null) {
tileDataHash = generateContentHash(bytes);
} else {
tileDataHash = null;

Wyświetl plik

@ -22,7 +22,10 @@ public class TileArchives {
throws IOException {
var options = archive.applyFallbacks(config.arguments());
return switch (archive.format()) {
case MBTILES -> Mbtiles.newWriteToFileDatabase(archive.getLocalPath(), options);
case MBTILES ->
// pass-through legacy arguments for fallback
Mbtiles.newWriteToFileDatabase(archive.getLocalPath(), options.orElse(config.arguments()
.subset(Mbtiles.LEGACY_VACUUM_ANALYZE, Mbtiles.LEGACY_COMPACT_DB, Mbtiles.LEGACY_SKIP_INDEX_CREATION)));
case PMTILES -> WriteablePmtiles.newWriteToFile(archive.getLocalPath());
};
}

Wyświetl plik

@ -14,21 +14,12 @@ import javax.annotation.concurrent.NotThreadSafe;
@NotThreadSafe
public interface WriteableTileArchive extends Closeable {
interface TileWriter extends Closeable {
void write(TileEncodingResult encodingResult);
// TODO: exists for compatibility reasons
default void write(com.onthegomap.planetiler.mbtiles.TileEncodingResult encodingResult) {
write(new TileEncodingResult(encodingResult.coord(), encodingResult.tileData(), encodingResult.tileDataHash()));
}
@Override
void close();
default void printStats() {}
}
/**
* Returns true if this tile archive deduplicates tiles with the same content.
* <p>
* If false, then {@link TileWriter} will skip computing tile hashes.
*/
boolean deduplicates();
/**
* Specify the preferred insertion order for this archive, e.g. {@link TileOrder#TMS} or {@link TileOrder#HILBERT}.
@ -53,5 +44,20 @@ public interface WriteableTileArchive extends Closeable {
*/
void finish();
interface TileWriter extends Closeable {
void write(TileEncodingResult encodingResult);
// TODO: exists for compatibility reasons
default void write(com.onthegomap.planetiler.mbtiles.TileEncodingResult encodingResult) {
write(new TileEncodingResult(encodingResult.coord(), encodingResult.tileData(), encodingResult.tileDataHash()));
}
@Override
void close();
default void printStats() {}
}
// TODO update archive metadata
}

Wyświetl plik

@ -12,6 +12,7 @@ import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
@ -226,7 +227,7 @@ public class Arguments {
value = provider.apply(normalize(option));
if (value != null) {
if (i != 0) {
LOGGER.warn("Argument '{}' is deprecated, please switch to '{}'", option, options[0]);
LOGGER.warn("Argument '{}' is deprecated", option);
}
break;
}
@ -528,4 +529,15 @@ public class Arguments {
key -> normalize(key.replaceFirst("^" + Pattern.quote(prefix) + "[-_.]?", ""))
);
}
public Arguments subset(String... allowedKeys) {
Set<String> allowed = new HashSet<>();
for (String key : allowedKeys) {
allowed.add(normalize(key));
}
return new Arguments(
key -> allowed.contains(normalize(key)) ? provider.apply(key) : null,
() -> keys.get().stream().filter(key -> allowed.contains(normalize(key))).toList()
);
}
}

Wyświetl plik

@ -58,6 +58,11 @@ public final class Mbtiles implements WriteableTileArchive, ReadableTileArchive
public static final String SKIP_INDEX_CREATION = "no_index";
public static final String VACUUM_ANALYZE = "vacuum_analyze";
public static final String LEGACY_COMPACT_DB = "compact_db";
public static final String LEGACY_SKIP_INDEX_CREATION = "skip_mbtiles_index_creation";
public static final String LEGACY_VACUUM_ANALYZE = "optimize_db";
// https://www.sqlite.org/src/artifact?ci=trunk&filename=magic.txt
private static final int MBTILES_APPLICATION_ID = 0x4d504258;
@ -104,17 +109,17 @@ public final class Mbtiles implements WriteableTileArchive, ReadableTileArchive
private Mbtiles(Connection connection, Arguments arguments) {
this.connection = connection;
this.compactDb = arguments.getBoolean(
COMPACT_DB,
COMPACT_DB + "|" + LEGACY_COMPACT_DB,
"mbtiles: reduce the DB size by separating and deduping the tile data",
true
);
this.skipIndexCreation = arguments.getBoolean(
SKIP_INDEX_CREATION,
SKIP_INDEX_CREATION + "|" + LEGACY_SKIP_INDEX_CREATION,
"mbtiles: skip adding index to sqlite DB",
false
);
this.vacuumAnalyze = arguments.getBoolean(
VACUUM_ANALYZE,
VACUUM_ANALYZE + "|" + LEGACY_VACUUM_ANALYZE,
"mbtiles: vacuum analyze sqlite DB after writing",
false
);
@ -186,6 +191,11 @@ public final class Mbtiles implements WriteableTileArchive, ReadableTileArchive
}
}
@Override
public boolean deduplicates() {
return compactDb;
}
@Override
public TileOrder tileOrder() {
return TileOrder.TMS;

Wyświetl plik

@ -122,6 +122,11 @@ public final class WriteablePmtiles implements WriteableTileArchive {
return new WriteablePmtiles(bytes);
}
@Override
public boolean deduplicates() {
return true;
}
@Override
public TileOrder tileOrder() {
return TileOrder.HILBERT;

Wyświetl plik

@ -334,4 +334,19 @@ class ArgumentsTest {
), args.toMap());
assertEquals("value1", args.getArg("key1"));
}
@Test
void testSubset() {
var args = Arguments.of(Map.of(
"key_1", "val_1",
"key-2", "val_2",
"key-3", "val_3"
)).subset("key-1", "key-2");
assertEquals(Map.of(
"key-1", "val_1",
"key-2", "val_2"
), args.toMap());
assertEquals("val_1", args.getArg("key-1"));
assertNull(args.getArg("key-3"));
}
}

Wyświetl plik

@ -144,6 +144,7 @@ to regenerate:
cat planetiler-custommap/planetiler.schema.json | jq -r '.properties.args.properties | to_entries[] | "- `" + .key + "` - " + .value.description' | pbcopy
-->
- `threads` - Default number of threads to use.
- `write_threads` - Default number of threads to use when writing temp features
- `process_threads` - Default number of threads to use when processing input features
@ -151,8 +152,6 @@ cat planetiler-custommap/planetiler.schema.json | jq -r '.properties.args.proper
- `minzoom` - Minimum tile zoom level to emit
- `maxzoom` - Maximum tile zoom level to emit
- `render_maxzoom` - Maximum rendering zoom level up to
- `skip_mbtiles_index_creation` - Skip adding index to mbtiles file
- `optimize_db` - Vacuum analyze mbtiles file after writing
- `force` - Overwriting output file and ignore warnings
- `gzip_temp` - Gzip temporary feature storage (uses more CPU, but less disk space)
- `mmap_temp` - Use memory-mapped IO for temp feature files
@ -175,7 +174,6 @@ cat planetiler-custommap/planetiler.schema.json | jq -r '.properties.args.proper
maximum zoom level to allow for overzooming
- `simplify_tolerance` - Default value for the tile pixel tolerance to use when simplifying features below the maximum
zoom level
- `compact_db` - Reduce the DB size by separating and deduping the tile data
- `skip_filled_tiles` - Skip writing tiles containing only polygon fills to the output
- `tile_warning_size_mb` - Maximum size in megabytes of a tile to emit a warning about
@ -442,7 +440,7 @@ nested, so each child context can also access the variables from its parent.
>> ##### process feature context
>>
>> Context available when processing an input feature, for example testing whether to include it from `include_when`.
>> Available variables:
> > Available variables:
>>
>> - `feature.tags` - map with key/value tags from the input feature
>> - `feature.id` - numeric ID of the input feature
@ -459,7 +457,7 @@ nested, so each child context can also access the variables from its parent.
>>>> ##### configure attribute context
>>>>
>>>> Context available after the value of an attribute has been computed, for example: set min zoom to render an
>>>> attribute. Adds variables:
> > > > attribute. Adds variables:
>>>>
>>>> - `value` the value that was computed for this key

Wyświetl plik

@ -138,28 +138,6 @@
"render_maxzoom": {
"description": "Maximum rendering zoom level up to"
},
"skip_mbtiles_index_creation": {
"description": "Skip adding index to mbtiles file",
"anyOf": [
{
"type": "string"
},
{
"type": "boolean"
}
]
},
"optimize_db": {
"description": "Vacuum analyze mbtiles file after writing",
"anyOf": [
{
"type": "string"
},
{
"type": "boolean"
}
]
},
"force": {
"description": "Overwriting output file and ignore warnings",
"anyOf": [
@ -294,17 +272,6 @@
"simplify_tolerance": {
"description": "Default value for the tile pixel tolerance to use when simplifying features below the maximum zoom level"
},
"compact_db": {
"description": "Reduce the DB size by separating and deduping the tile data",
"anyOf": [
{
"type": "string"
},
{
"type": "boolean"
}
]
},
"skip_filled_tiles": {
"description": "Skip writing tiles containing only polygon fills to the output",
"anyOf": [

Wyświetl plik

@ -102,9 +102,10 @@ if [ "$DRY_RUN" == "true" ]; then
fi
function run() {
echo "$ $*"
command="${*//&/\&}"
echo "$ $command"
if [ "$DRY_RUN" != "true" ]; then
eval "$*"
eval "$command"
fi
}