Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Sep 20, 2023
1 parent 67ba2a2 commit ec9c05c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 26 deletions.
1 change: 1 addition & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The `planetiler-core` module includes the following software:
- mil.nga.geopackage:geopackage (MIT license)
- org.snakeyaml:snakeyaml-engine (Apache license)
- org.commonmark:commonmark (BSD 2-clause license)
- org.tukaani:xz (public domain)
- Adapted code:
- `DouglasPeuckerSimplifier` from [JTS](https://github.com/locationtech/jts) (EDL)
- `OsmMultipolygon` from [imposm3](https://github.com/omniscale/imposm3) (Apache license)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public class Planetiler {
private FeatureGroup featureGroup;
private OsmInputFile osmInputFile;
private TileArchiveConfig output;
private Path layerStatsPath;
private boolean overwrite = false;
private boolean ran = false;
// most common OSM languages
Expand Down Expand Up @@ -672,7 +671,7 @@ public void run() throws Exception {
output.uri() + " already exists, use the --force argument to overwrite or --append.");
}

layerStatsPath = arguments.file("layer_stats", "layer stats output path",
Path layerStatsPath = arguments.file("layer_stats", "layer stats output path",
// default to <output file>.layerstats.tsv.gz
TileSizeStats.getOutputPath(Optional.ofNullable(output.getLocalPath()).orElse(Path.of("output"))));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import com.onthegomap.planetiler.geo.TileCoord;
import java.util.Arrays;
import java.util.Objects;

/** A tile stored in an archive with coordinate {@code coord} and archived {@code bytes}. */
public record Tile(TileCoord coord, byte[] bytes) implements Comparable<Tile> {

@Override
public boolean equals(Object o) {
return (this == o) || (o instanceof Tile other && coord.equals(other.coord) && Arrays.equals(bytes, other.bytes));
return (this == o) ||
(o instanceof Tile other && Objects.equals(coord, other.coord) && Arrays.equals(bytes, other.bytes));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ public static void writeOutput(FeatureGroup features, WriteableTileArchive outpu
loggers.addPipelineStats(layerStatsBranch);
}
loggers.newLine()
.newLine()
.add(writer::getLastTileLogDetails);

var doneFuture = joinFutures(
Expand Down Expand Up @@ -309,22 +308,21 @@ private void tileEncoderSink(Iterable<TileBatch> prev) throws IOException {
}
lastTileDataHash = tileDataHash;
}
if ((skipFilled && lastIsFill) || bytes == null) {
continue;
if ((!skipFilled || !lastIsFill) && bytes != null) {
tileStatsUpdater.recordTile(tileFeatures.tileCoord(), bytes.length, layerStats);
List<String> layerStatsRows = config.outputLayerStats() ?
TileSizeStats.formatOutputRows(tileFeatures.tileCoord(), bytes.length, layerStats) :
List.of();
result.add(
new TileEncodingResult(
tileFeatures.tileCoord(),
bytes,
encoded.length,
tileDataHash == null ? OptionalLong.empty() : OptionalLong.of(tileDataHash),
layerStatsRows
)
);
}
tileStatsUpdater.recordTile(tileFeatures.tileCoord(), bytes.length, layerStats);
List<String> layerStatsRows = config.outputLayerStats() ?
TileSizeStats.formatOutputRows(tileFeatures.tileCoord(), bytes.length, layerStats) :
List.of();
result.add(
new TileEncodingResult(
tileFeatures.tileCoord(),
bytes,
encoded.length,
tileDataHash == null ? OptionalLong.empty() : OptionalLong.of(tileDataHash),
layerStatsRows
)
);
}
// hand result off to writer
batch.out.complete(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public record TileEncodingResult(
TileCoord coord,
@Nonnull byte[] tileData,
int rawTileSize,
/** will always be empty in non-compact mode and might also be empty in compact mode */
/* will always be empty in non-compact mode and might also be empty in compact mode */
OptionalLong tileDataHash,
List<String> layerStats
) {
Expand All @@ -20,7 +20,7 @@ public TileEncodingResult(
byte[] tileData,
OptionalLong tileDataHash
) {
this(coord, tileData, 0, tileDataHash, List.of());
this(coord, tileData, tileData.length, tileDataHash, List.of());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ private static class CsvTileWriter implements TileWriter {

CsvTileWriter(Writer writer, String columnSeparator, String lineSeparator,
Function<byte[], String> tileDataEncoder) {

this.writer = writer;
this.columnSeparator = columnSeparator;
this.lineSeparator = lineSeparator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import org.slf4j.LoggerFactory;
import vector_tile.VectorTileProto;

/**
*
*/
public class TileSizeStats {

private static final int BATCH_SIZE = 1_000;
Expand All @@ -47,10 +50,6 @@ public class TileSizeStats {
.withLineSeparator("\n");
public static final ObjectWriter WRITER = MAPPER.writer(SCHEMA);

public TileSizeStats() {
// TODO load OSM tile weights
}

public static Path getOutputPath(Path output) {
return output.resolveSibling(output.getFileName() + ".layerstats.tsv.gz");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.locationtech.jts.geom.Envelope;


class TileCoordTest {
Expand Down Expand Up @@ -130,4 +131,16 @@ void testTileProgressOnLevelHilbert(int x, int y, int z, double p) {
void testDebugUrl(int x, int y, int z, String expected) {
assertEquals(expected, TileCoord.ofXYZ(x, y, z).getDebugUrl("{z}/{lat}/{lon}"));
}

@Test
void testEnvelope() {
assertEquals(new Envelope(
-180, 180,
-85.0511287798066, 85.0511287798066
), TileCoord.ofXYZ(0, 0, 0).getEnvelope());
assertEquals(new Envelope(
0, 180,
-85.0511287798066, 0
), TileCoord.ofXYZ(1, 1, 1).getEnvelope());
}
}

0 comments on commit ec9c05c

Please sign in to comment.