Skip to content

Commit

Permalink
handle blank pngs
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Perry committed Jun 12, 2012
1 parent adefc6a commit 7b70053
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Binary file added blank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 11 additions & 4 deletions mbtiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import zlib
import json
import os
import shutil


class MbtileSet:
Expand Down Expand Up @@ -37,6 +38,7 @@ def __init__(self, z, x, y, conn, origin):
self.row = y
self.conn = conn
self.origin = origin
self.blank_png_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'blank.png')

@property
def output_row(self):
Expand Down Expand Up @@ -104,11 +106,16 @@ def write_png(self, outdir):
pngdir = os.path.join(outdir, z, x)
try:
os.makedirs(pngdir)
except OSError:
except OSError as e:
pass
fh = open(os.path.join(pngdir, y + ".png"), 'wb')
fh.write(self.get_png())
fh.close()
png = self.get_png()
path = os.path.join(pngdir, y + ".png")
if png:
fh = open(path, 'wb')
fh.write(png)
fh.close()
else:
shutil.copyfile(self.blank_png_path, path)

def write_json(self, outdir):
z, x, y = [str(i) for i in [self.zoom, self.col, self.output_row]]
Expand Down

0 comments on commit 7b70053

Please sign in to comment.