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

uncompressing the pbf files #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions mbutil/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# https://github.com/mapbox/node-mbtiles/blob/master/lib/schema.sql

import sqlite3, sys, logging, time, os, json, zlib, re
import shutil,gzip

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -337,6 +338,7 @@ def mbtiles_to_disk(mbtiles_file, directory_path, **kwargs):
f = open(tile, 'wb')
f.write(t[3])
f.close()
uncompressFile(tile)
done = done + 1
if not silent:
logger.info('%s / %s tiles exported' % (done, count))
Expand Down Expand Up @@ -384,3 +386,20 @@ def mbtiles_to_disk(mbtiles_file, directory_path, **kwargs):
if not silent:
logger.info('%s / %s grids exported' % (done, count))
g = grids.fetchone()

# uncompress the file
def uncompressFile(srcFileName):
#do this if you only find .pbf file
if srcFileName.find(".pbf") != -1 :
#temperoraly copy the contents
srcFileName_tmp = srcFileName.replace(".pbf", "_tmp.pbf")
shutil.copy2(srcFileName, srcFileName_tmp)

with gzip.open(srcFileName_tmp,'rb') as fIn :
with open(srcFileName,'wb') as fOut :
shutil.copyfileobj(fIn,fOut)
logger.info("uncompressed file {0}".format(srcFileName))
# remove the temp file
os.remove(srcFileName_tmp)
else :
logger.info("found some other file {0}".format(srcFileName))