source: src/mapservice/server_impl/controllers/TilesController.py@ 3db3d13

debian/bullseye
Last change on this file since 3db3d13 was 7be94aa, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago
  • Added yapf style config (src/python-style.yapf)
    • Updated all files to the yapf formatted version
  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[5e16955]1'''
2 Copyright (C) 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16'''
17
18import connexion
19import flask
20import os
21
22from ..HttpErrors import MapserviceInternalServerError, MapserviceBadRequest, MapserviceNotFound
23
[7be94aa]24
[5e16955]25def tiles_tile_get(accuracy, resolution, zoom, x_tile, y_tile):
[7be94aa]26 if not 'TILES_CACHE_PATH' in flask.current_app.config or not os.access(
27 flask.current_app.config['TILES_CACHE_PATH'], os.R_OK
28 ):
29 raise MapserviceInternalServerError(
30 detail='TILES_CACHE_PATH not configured or not accessible'
31 )
32 tiles_cache_path = flask.current_app.config['TILES_CACHE_PATH']
33
34 if not 'TILES_DENSITIES' in flask.current_app.config:
35 raise MapserviceInternalServerError(
36 details='TILES_DENSITIES not configured'
37 )
38 tiles_densities = flask.current_app.config['TILES_DENSITIES']
39
40 if not 'TILES_DENSITY_BASEE' in flask.current_app.config:
41 raise MapserviceInternalServerError(
42 details='TILES_DENSITY_BASEE not configured'
43 )
44 tiles_densitiy_base = flask.current_app.config['TILES_DENSITY_BASEE']
45
46 if not 'TILES_SKIP_EMPTY' in flask.current_app.config:
47 raise MapserviceInternalServerError(
48 details='TILES_SKIP_EMPTY not configured'
49 )
50 tiles_skip_empty = flask.current_app.config['TILES_SKIP_EMPTY']
51
52 if accuracy == 'high':
53 accuracy = '{}_{}'.format(max(tiles_densities), tiles_densitiy_base)
54 elif accuracy == 'low':
55 accuracy = '{}_{}'.format(min(tiles_densities), tiles_densitiy_base)
56 else:
57 raise MapserviceBadRequest(
58 details=
59 'No valid accuracy requested. Valid are high, low. Requested was: {}'
60 .format(accuracy)
61 )
62
63 tile__empty_path = os.path.join(
64 tiles_cache_path, '{}/{}/empty_tile.png'.format(accuracy, resolution)
65 )
66 tile_path = os.path.join(
67 tiles_cache_path, '{}/{}/{}/{}/{}.png'.format(
68 accuracy, resolution, zoom, x_tile, y_tile
69 )
70 )
71 if not os.path.isfile(tile_path):
72 if not tiles_skip_empty or not os.path.isfile(tile__empty_path):
73 raise MapserviceNotFound(
74 detail=
75 'Tile ({}, {}) for accuracy {} with resolution {} at zoomlevel {} not found'
76 .format(x_tile, y_tile, accuracy, resolution, zoom)
77 )
78 tile_path = tile__empty_path
79
80 response = flask.send_file(
81 tile_path,
82 mimetype='image/png',
83 as_attachment=True,
84 attachment_filename='{}.png'.format(y_tile)
85 )
86 response.direct_passthrough = False
87 #response.headers['Content-Transfer-Encoding']='base64'
88 return response
Note: See TracBrowser for help on using the repository browser.