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 support for PMTiles #794

Merged
merged 13 commits into from
Nov 26, 2023
Merged

Add support for PMTiles #794

merged 13 commits into from
Nov 26, 2023

Conversation

bchapuis
Copy link
Member

No description provided.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

public List<Entry> getDirectory(long offset, int length) {
var header = getHeader();
try (var input = Files.newInputStream(path)) {
input.skip(offset);

Check notice

Code scanning / CodeQL

Ignored error status of call Note

Method getDirectory ignores exceptional return value of InputStream.skip.
// Write the tile
var tileId = PMTiles.zxyToTileId(z, x, y);
var tileLength = bytes.length;
Long tileHash = Hashing.farmHashFingerprint64().hashBytes(bytes).asLong();

Check warning

Code scanning / CodeQL

Boxed variable is never null Warning

The variable 'tileHash' is only assigned values of primitive type and is never 'null', but it is declared with the boxed type 'Long'.

@Test
void encodeHeader() throws IOException {
var etag = "1";

Check notice

Code scanning / CodeQL

Unread local variable Note test

Variable 'String etag' is never read.
void decodeHeader() throws IOException {
var file = TestFiles.resolve("pmtiles/test_fixture_1.pmtiles");
try (var channel = FileChannel.open(file)) {
var input = new LittleEndianDataInputStream(Channels.newInputStream(channel));

Check warning

Code scanning / CodeQL

Potential input resource leak Warning test

This LittleEndianDataInputStream is not always closed on method exit.
long numEntries = readVarInt(buffer);
List<Entry> entries = new ArrayList<>((int) numEntries);
long lastId = 0;
for (int i = 0; i < numEntries; i++) {

Check failure

Code scanning / CodeQL

Comparison of narrow type with wide type in loop condition High

Comparison between
expression
of type int and
expression
of wider type long.
entry.setTileId(lastId);
entries.add(entry);
}
for (int i = 0; i < numEntries; i++) {

Check failure

Code scanning / CodeQL

Comparison of narrow type with wide type in loop condition High

Comparison between
expression
of type int and
expression
of wider type long.
long value = readVarInt(buffer);
entries.get(i).setRunLength(value);
}
for (int i = 0; i < numEntries; i++) {

Check failure

Code scanning / CodeQL

Comparison of narrow type with wide type in loop condition High

Comparison between
expression
of type int and
expression
of wider type long.
long value = readVarInt(buffer);
entries.get(i).setLength(value);
}
for (int i = 0; i < numEntries; i++) {

Check failure

Code scanning / CodeQL

Comparison of narrow type with wide type in loop condition High

Comparison between
expression
of type int and
expression
of wider type long.
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug B 1 Bug
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 85 Code Smells

No Coverage information No Coverage information
2.6% 2.6% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@bchapuis bchapuis marked this pull request as ready for review November 26, 2023 12:43
@bchapuis bchapuis merged commit 1764a6a into main Nov 26, 2023
8 of 10 checks passed
@bchapuis bchapuis deleted the pmtiles branch November 26, 2023 12:51
bchapuis added a commit that referenced this pull request Nov 28, 2023
Enable the export of vector tiles in the PMTiles format. Most of the necessary functions have been ported from [go-pmtiles](https://github.com/protomaps/go-pmtiles) to Java.
bchapuis added a commit that referenced this pull request Nov 28, 2023
Enable the export of vector tiles in the PMTiles format. Most of the necessary functions have been ported from [go-pmtiles](https://github.com/protomaps/go-pmtiles) to Java.
bchapuis added a commit that referenced this pull request Nov 28, 2023
Enable the export of vector tiles in the PMTiles format. Most of the necessary functions have been ported from [go-pmtiles](https://github.com/protomaps/go-pmtiles) to Java.
@jiayuasu
Copy link
Member

jiayuasu commented Jan 2, 2024

@bchapuis Thanks for the great work! Really looking forward to this feature. When will this be released?

@jiayuasu
Copy link
Member

jiayuasu commented Jan 2, 2024

In addition, is it possible that I use it directly with JTS geometries instead of always converting from existing vector tiles?

@bchapuis
Copy link
Member Author

bchapuis commented Jan 3, 2024

@bchapuis Thanks for the great work! Really looking forward to this feature. When will this be released?

I'd like to start the release process soon, so I hope to have a release by the end of january. Note that, while the demonstration works fine, some small issues remain. For instance, the number of tiles in the metadata does not match the number of actual tiles. If you have experience with this format, any help, like spotting or fixing issues in the codec is welcome (I have no prior experience with this format) 😅

@bchapuis
Copy link
Member Author

bchapuis commented Jan 3, 2024

In addition, is it possible that I use it directly with JTS geometries instead of always converting from existing vector tiles?

I'm not sure to fully understand this question. We do have an efficient reader for planet osm based on the Stream API that supports the xml, pbf, and osc formats. Optionnally, this reader can produce JTS geometries. We use it to import the data in postgresql, which is then used to produce the vector tiles. Are you thinking about accessing this Stream of geometries?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants