Skip to content

Commit

Permalink
omit() feature collector api and --refresh-sources arg
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Jan 30, 2024
1 parent 4d52507 commit aa28d25
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
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

0 comments on commit aa28d25

Please sign in to comment.