Skip to content

Commit

Permalink
Merge pull request #7 from jamesprayner/downscaling
Browse files Browse the repository at this point in the history
PR review merge
  • Loading branch information
jamesprayner authored May 21, 2019
2 parents 3b502b5 + 272b7df commit e64a70f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
5 changes: 2 additions & 3 deletions plotting/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,8 @@ def plot(projection, x, y, z, args):
xpx = x * 256
ypx = y * 256

if z > 7:
pass
else:
# Mask out any topography if we're below the vector-tile threshold
if z < 8:
with Dataset(current_app.config['ETOPO_FILE'] % (projection, z), 'r') as dataset:
bathymetry = dataset["z"][ypx:(ypx + 256), xpx:(xpx + 256)]

Expand Down
21 changes: 9 additions & 12 deletions routes/routes_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,17 +633,16 @@ def mbt_impl(projection: str, tiletype: str, zoom: int, x: int, y: int):
"""
cache_dir = current_app.config['CACHE_DIR']
shape_file_dir = current_app.config['SHAPE_FILE_DIR']
directory = str(os.path.join(cache_dir, request.path[1:]))
# This is a funky way of splitting the string to only include characters up to the 10th instance of '/'
basedir = "/".join(directory.split("/", 10)[:10])
requestf = str(os.path.join(cache_dir, request.path[1:]))
basedir = requestf.rsplit("/", 1)[0]

# Send blank tile if conditions aren't met
if (zoom < 7) or (projection != "EPSG:3857"):
return send_file(shape_file_dir + "/blank.mbt")

# Send file if cached or select data in SQLite file
if os.path.isfile(directory):
return send_file(directory)
if os.path.isfile(requestf):
return send_file(requestf)
else:
y = (2**zoom-1) - y
connection = sqlite3.connect(shape_file_dir + "/{}.mbtiles".format(tiletype))
Expand All @@ -655,16 +654,14 @@ def mbt_impl(projection: str, tiletype: str, zoom: int, x: int, y: int):
return send_file(shape_file_dir + "/blank.mbt")

# Write tile to cache and send file
if os.path.isdir(basedir):
pass
else:
if not os.path.isdir(basedir):
os.makedirs(basedir)
with open(directory + ".pbf", 'wb') as f:
with open(requestf + ".pbf", 'wb') as f:
f.write(tile[0])
with gzip.open(directory + ".pbf", 'rb') as gzipped:
with open(directory, 'wb') as tileout:
with gzip.open(requestf + ".pbf", 'rb') as gzipped:
with open(requestf, 'wb') as tileout:
shutil.copyfileobj(gzipped, tileout)
return send_file(directory)
return send_file(requestf)


def drifter_query_impl(q: str, drifter_id: str):
Expand Down

0 comments on commit e64a70f

Please sign in to comment.