Skip to content

Commit

Permalink
Merge remote-tracking branch 'DoFabien/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
acalcutt committed Apr 18, 2022
2 parents f551a75 + 6b51e36 commit 73451f4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion rio_rgbify/mbtiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ def run(self, processes=4):

# create a connection to the mbtiles file
conn = sqlite3.connect(self.outpath)
# Wall mode : Speedup by 10 the speed of writing in the database
conn.execute('pragma journal_mode=wal')
cur = conn.cursor()

# create the tiles table
Expand All @@ -330,6 +332,11 @@ def run(self, processes=4):
"(zoom_level integer, tile_column integer, "
"tile_row integer, tile_data blob);"
)

# create index on tiles for efficient access to this table
cur.execute(
"CREATE UNIQUE INDEX IF NOT EXISTS tile_index on tiles (zoom_level, tile_column, tile_row);")

# create empty metadata
cur.execute("CREATE TABLE metadata (name text, value text);")

Expand Down Expand Up @@ -371,6 +378,7 @@ def run(self, processes=4):
constrained_bbox = list(mercantile.bounds(self.bounding_tile))
tiles = _make_tiles(constrained_bbox, "EPSG:4326", self.min_z, self.max_z)

tilesCount = 0
for tile, contents in self.pool.imap_unordered(self.run_function, tiles):
x, y, z = tile

Expand All @@ -384,8 +392,13 @@ def run(self, processes=4):
"VALUES (?, ?, ?, ?);",
(z, x, tiley, buffer(contents)),
)
tilesCount = tilesCount + 1
# commit data every 1000 tiles (about 150 Mo)
# Otherwise, the file .mbtiles-wal becomes huge (same size as the final file). The result is the need to have twice the size of the final Mbtiles on the hard drive
if (tilesCount % 1000 == 0):
conn.commit()

conn.commit()
conn.commit()

conn.close()

Expand Down

0 comments on commit 73451f4

Please sign in to comment.