forked from openmaptiles/openmaptiles-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-sqlquery
executable file
·33 lines (28 loc) · 1.08 KB
/
generate-sqlquery
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
"""
Usage:
generate-sqlquery <layer-definition> <zoom-level>
generate-sqlquery --help
generate-sqlquery --version
Options:
--help Show this screen.
--version Show version.
"""
from docopt import docopt
import re
import openmaptiles
from openmaptiles.tileset import Layer
from openmaptiles.language import languages_to_sql
if __name__ == '__main__':
# print('-------------------- Dev--------------------')
args = docopt(__doc__, version=openmaptiles.__version__)
layer = Layer.parse(args['<layer-definition>'])
bbox="ST_SetSRID('BOX3D(-20037508.34 -20037508.34, 20037508.34 20037508.34)'::box3d, 3857 )"
zoomlevel=args['<zoom-level>']
datasource = layer['layer']['datasource']
query=datasource['query']
name_languages = languages_to_sql([])
sql=query.replace('!bbox!',bbox).replace('z(!scale_denominator!)', zoomlevel ).replace('!pixel_width!','1').replace('{name_languages}',name_languages)
extract_query = re.compile(r'\((.*)\) AS *')
match = extract_query.search(sql)
print(match.group(1))