From ca44bdc2e53c721a44e4c35eb14c8e9e6d875b64 Mon Sep 17 00:00:00 2001 From: anilkunchalaece Date: Sat, 20 Apr 2019 15:11:23 +0530 Subject: [PATCH 1/3] uncompressing the pbf files --- mbutil/util.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mbutil/util.py b/mbutil/util.py index 50f581c..76253ca 100755 --- a/mbutil/util.py +++ b/mbutil/util.py @@ -337,6 +337,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)) @@ -384,3 +385,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) + print("uncompressed file {0}".format(srcFileName)) + # remove the temp file + os.remove(srcFileName_tmp) + else : + print("found some other file {0}".format(srcFileName)) \ No newline at end of file From 2b6723ccd7dd183c03839c31ea5088a476568243 Mon Sep 17 00:00:00 2001 From: anilkunchalaece Date: Sat, 20 Apr 2019 15:18:08 +0530 Subject: [PATCH 2/3] added imports --- mbutil/util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mbutil/util.py b/mbutil/util.py index 76253ca..549f68d 100755 --- a/mbutil/util.py +++ b/mbutil/util.py @@ -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__) From 4094ac949e0e7566a183ef669f620a95e2e546fd Mon Sep 17 00:00:00 2001 From: anilkunchalaece Date: Sat, 20 Apr 2019 18:52:34 +0530 Subject: [PATCH 3/3] replaced logging with print --- mbutil/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mbutil/util.py b/mbutil/util.py index 549f68d..e37994d 100755 --- a/mbutil/util.py +++ b/mbutil/util.py @@ -398,8 +398,8 @@ def uncompressFile(srcFileName): with gzip.open(srcFileName_tmp,'rb') as fIn : with open(srcFileName,'wb') as fOut : shutil.copyfileobj(fIn,fOut) - print("uncompressed file {0}".format(srcFileName)) + logger.info("uncompressed file {0}".format(srcFileName)) # remove the temp file os.remove(srcFileName_tmp) else : - print("found some other file {0}".format(srcFileName)) \ No newline at end of file + logger.info("found some other file {0}".format(srcFileName)) \ No newline at end of file