This is an automated email from the ASF dual-hosted git repository.

bchapuis pushed a commit to branch pmtiles-header
in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git

commit dab1a70eecebf0aaceaa6c1cc15be2e13fb4ed00
Author: Bertil Chapuis <[email protected]>
AuthorDate: Fri Jan 5 15:39:13 2024 +0100

    Fix the header of the pmtiles
---
 .run/basemap-export-pmtiles.run.xml                |  2 +-
 .../apache/baremaps/tilestore/pmtiles/Header.java  | 32 ++++++++++++++++++++++
 .../baremaps/tilestore/pmtiles/PMTilesWriter.java  |  2 +-
 .../baremaps/workflow/tasks/ExportVectorTiles.java |  3 +-
 4 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/.run/basemap-export-pmtiles.run.xml 
b/.run/basemap-export-pmtiles.run.xml
index 840a4774..d6c8830d 100644
--- a/.run/basemap-export-pmtiles.run.xml
+++ b/.run/basemap-export-pmtiles.run.xml
@@ -2,7 +2,7 @@
   <configuration default="false" name="basemap-export-pmtiles" 
type="Application" factoryName="Application">
     <option name="MAIN_CLASS_NAME" value="org.apache.baremaps.cli.Baremaps" />
     <module name="baremaps-cli" />
-    <option name="PROGRAM_PARAMETERS" value="map export --tileset tileset.js 
--repository tiles.mbtiles --format pmtiles" />
+    <option name="PROGRAM_PARAMETERS" value="map export --tileset tileset.js 
--repository tiles.pmtiles --format pmtiles" />
     <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/basemap" />
     <method v="2">
       <option name="Make" enabled="true" />
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/pmtiles/Header.java 
b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/pmtiles/Header.java
index b1e3bddf..81dcc929 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/pmtiles/Header.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/pmtiles/Header.java
@@ -30,8 +30,40 @@ class Header {
   private long leafDirectoryLength;
   private long tileDataOffset;
   private long tileDataLength;
+
+  /**
+   * Number of Addressed Tiles
+   * <p>
+   * The Number of Addressed Tiles is an 8-byte field specifying the total 
number of tiles in the PMTiles archive, before RunLength Encoding.
+   * <p>
+   * A value of 0 indicates that the number is unknown.
+   * <p>
+   * This field is encoded as a little-endian 64-bit unsigned integer.
+   */
   private long numAddressedTiles;
+
+  /**
+   * Number of Tile Entries
+   * <p>
+   * The Number of Tile Entries is an 8-byte field specifying the total number 
of tile entries: entries where RunLength is greater than 0.
+   * <p>
+   * A value of 0 indicates that the number is unknown.
+   * <p>
+   * This field is encoded as a little-endian 64-bit unsigned integer.
+   *
+   * @return the number of tile entries
+   */
   private long numTileEntries;
+
+  /**
+   * Number of tile entries.
+   * <p>
+   * The Number of Tile Contents is an 8-byte field specifying the total 
number of blobs in the tile data section.
+   * <p>
+   * A value of 0 indicates that the number is unknown.
+   * <p>
+   * This field is encoded as a little-endian 64-bit unsigned integer.
+   */
   private long numTileContents;
   private boolean clustered;
   private Compression internalCompression;
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/pmtiles/PMTilesWriter.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/pmtiles/PMTilesWriter.java
index 892a692d..5b50e5d0 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/tilestore/pmtiles/PMTilesWriter.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/tilestore/pmtiles/PMTilesWriter.java
@@ -178,7 +178,7 @@ public class PMTilesWriter {
     var header = new Header();
     header.setNumAddressedTiles(numTiles);
     header.setNumTileEntries(numTiles);
-    header.setNumTileContents(numTiles);
+    header.setNumTileContents(tileHashToOffset.size());
     header.setClustered(true);
 
     header.setInternalCompression(compression);
diff --git 
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ExportVectorTiles.java
 
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ExportVectorTiles.java
index 8e277ef8..7a44864f 100644
--- 
a/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ExportVectorTiles.java
+++ 
b/baremaps-core/src/main/java/org/apache/baremaps/workflow/tasks/ExportVectorTiles.java
@@ -147,8 +147,7 @@ public class ExportVectorTiles implements Task {
         return tilesStore;
       case pmtiles:
         Files.deleteIfExists(repository);
-        var tileStore = new PMTilesStore(repository, source);
-        return tileStore;
+        return new PMTilesStore(repository, source);
       default:
         throw new IllegalArgumentException("Unsupported format");
     }

Reply via email to