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 lz4 compression to planetiler #1104

Merged
merged 3 commits into from
Nov 23, 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
5 changes: 5 additions & 0 deletions planetiler-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@
<artifactId>parquet-floor</artifactId>
<version>1.48</version>
</dependency>
<dependency>
<groupId>org.lz4</groupId>
<artifactId>lz4-java</artifactId>
<version>1.8.0</version>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.util.function.IntUnaryOperator;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
import net.jpountz.lz4.LZ4Exception;
import net.jpountz.lz4.LZ4Factory;
import net.jpountz.lz4.LZ4FastDecompressor;
import org.locationtech.jts.geom.Envelope;

/**
Expand Down Expand Up @@ -74,8 +77,24 @@ private static byte[] readBlobContent(Fileformat.Blob blob) {
throw new FileFormatException("PBF blob contains incomplete compressed data.");
}
inflater.end();
} else if (blob.hasLz4Data()) {
msbarry marked this conversation as resolved.
Show resolved Hide resolved
final int decompressedLength = blob.getRawSize();
LZ4Factory factory = LZ4Factory.fastestInstance();
LZ4FastDecompressor decompressor = factory.fastDecompressor();
blobData = new byte[decompressedLength];
try {
int compressedBytesRead =
decompressor.decompress(blob.getLz4Data().toByteArray(), 0, blobData, 0, decompressedLength);
int compressedBytesExpected = blob.getLz4Data().size();
if (compressedBytesRead != compressedBytesExpected) {
throw new FileFormatException("Unable to decompress PBF blob. read %d compressed bytes but expected %d"
.formatted(decompressedLength, compressedBytesExpected));
}
} catch (LZ4Exception e) {
throw new FileFormatException("Unable to decompress PBF blob.", e);
}
} else {
throw new FileFormatException("PBF blob uses unsupported compression, only raw or zlib may be used.");
throw new FileFormatException("PBF blob uses unsupported compression, only lz4, zlib, or raw may be used.");
}

return blobData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2088,10 +2088,13 @@ private static TileCompression extractTileCompression(String args) {
"--tile-compression=none",
"--tile-compression=gzip",
"--output-layerstats",
"--max-point-buffer=1"
"--max-point-buffer=1",
"--osm-test-path=monaco-latest.lz4.osm.pbf",
})
void testPlanetilerRunner(String args) throws Exception {
Path originalOsm = TestUtils.pathToResource("monaco-latest.osm.pbf");
var argParsed = Arguments.fromArgs(args.split(" "));
Path originalOsm =
TestUtils.pathToResource(argParsed.getString("osm-test-path", "osm-test-path", "monaco-latest.osm.pbf"));
Path tempOsm = tempDir.resolve("monaco-temp.osm.pbf");
final TileCompression tileCompression = extractTileCompression(args);

Expand Down
Binary file not shown.
Loading