Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add omit() feature collector api and --refresh-sources arg #810

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,12 @@ public Feature setNumPointsAttr(String numPointsAttr) {
return this;
}

/** Omit this feature from the output */
public Feature omit() {
output.remove(this);
return this;
}

@Override
public String toString() {
return "Feature{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class Planetiler {
private final Path multipolygonPath;
private final Path featureDbPath;
private final boolean downloadSources;
private final boolean refreshSources;
private final boolean onlyDownloadSources;
private final boolean parseNodeBounds;
private Profile profile = null;
Expand Down Expand Up @@ -117,6 +118,8 @@ private Planetiler(Arguments arguments) {
tmpDir = config.tmpDir();
onlyDownloadSources = arguments.getBoolean("only_download", "download source data then exit", false);
downloadSources = onlyDownloadSources || arguments.getBoolean("download", "download sources", false);
refreshSources =
arguments.getBoolean("refresh_sources", "download new version of source files if they have changed", false);
fetchOsmTileStats =
arguments.getBoolean("download_osm_tile_weights", "download OSM tile weights file", downloadSources);
nodeDbPath = arguments.file("temp_nodes", "temp node db location", tmpDir.resolve("node.db"));
Expand Down Expand Up @@ -891,11 +894,13 @@ private RunnableThatThrows ifSourceUsed(String name, RunnableThatThrows task) {

private Path getPath(String name, String type, Path defaultPath, String defaultUrl) {
Path path = arguments.file(name + "_path", name + " " + type + " path", defaultPath);
boolean refresh =
arguments.getBoolean("refresh_" + name, "Download new version of " + name + " if changed", refreshSources);
boolean freeAfterReading = arguments.getBoolean("free_" + name + "_after_read",
"delete " + name + " input file after reading to make space for output (reduces peak disk usage)", false);
if (downloadSources) {
if (downloadSources || refresh) {
String url = arguments.getString(name + "_url", name + " " + type + " url", defaultUrl);
if (!Files.exists(path) && url != null) {
if ((!Files.exists(path) || refresh) && url != null) {
toDownload.add(new ToDownload(name, url, path));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ void testPoint() {

}

@Test
void testOmit() {
var collector = factory.get(newReaderFeature(newPoint(0, 0), Map.of(
"key", "val"
)));
var point = collector.point("layername");
assertFeatures(14, List.of(Map.of("_layer", "layername")), collector);
point.omit();
assertFeatures(14, List.of(), collector);
}

@Test
void testAttrWithMinzoom() {
var collector = factory.get(newReaderFeature(newPoint(0, 0), Map.of(
Expand Down
Loading