forked from openmaptiles/openmaptiles-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-sqltomvt
executable file
·66 lines (60 loc) · 2.97 KB
/
generate-sqltomvt
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
"""
This script generates a single SQL statement (either as an SQL function or as a prepared statement),
to generate a vector tile (MVT) for the given zoom and bounding box.
Usage:
generate-sqltomvt <tileset> [--fname <name>]
[--function | --prepared | --query | --psql | --raw]
[--layer=<layer>]... [--exclude-layers] [--key]
[--gzip [<gzlevel>]] [--no-feature-ids] [--no-tile-envelope]
[--test-geometry]
generate-sqltomvt --help
generate-sqltomvt --version
<tileset> Tileset definition yaml file
Options:
--fname=<name> Name of the generated function [default: gettile]
-f --function Generate function generation SQL [default]
-p --prepared Generate prepared statement SQL
-q --query Generate a query SQL with $1,$2,$3 meaning zoom,x,y
-d --psql Generate a query SQL with :zoom,:x,:y vars to simplify PSQL debugging with \set zoom 5
-r --raw Generate raw query without any wrappers (good for debugging SQL)
-l --layer=<layer> If set, limit tile generation to just this layer (could be multiple)
-x --exclude-layers If set, uses all layers except the ones listed with -l (-l is required)
--key If set, the result will also have a `key` column (md5 of the mvt data)
--gzip If set, compress MVT with gzip, with optional level=0..9.
`gzip()` is available from https://github.com/pramsey/pgsql-gzip
--no-feature-ids Disable feature ID generation, e.g. from osm_id.
You must use this flag when generating SQL for PostGIS before v3
--no-tile-envelope Disable PostGIS 3.0+ ST_TileEnvelope() function.
You must use this flag when generating SQL for PostGIS before v3
-g --test-geometry Validate all geometries produced by ST_AsMvtGeom(), and warn.
--help Show this screen.
--version Show version.
"""
from docopt import docopt
import openmaptiles
from openmaptiles.sqltomvt import MvtGenerator
if __name__ == '__main__':
args = docopt(__doc__, version=openmaptiles.__version__)
mvt = MvtGenerator(
tileset=args['<tileset>'],
layer_ids=args['--layer'],
exclude_layers=args['--exclude-layers'],
key_column=args['--key'],
gzip=args['--gzip'] and (args['<gzlevel>'] or True),
use_feature_id=not args['--no-feature-ids'],
use_tile_envelope=not args['--no-tile-envelope'],
test_geometry=args['--test-geometry'],
)
if args['--prepared']:
sql = mvt.generate_sqltomvt_preparer(args['--fname'])
elif args['--query']:
sql = mvt.generate_sqltomvt_query()
elif args['--psql']:
sql = mvt.generate_sqltomvt_psql()
elif args['--raw']:
sql = mvt.generate_sqltomvt_raw()
else:
# --function or default
sql = mvt.generate_sqltomvt_func(args['--fname'])
print(sql)