-
Notifications
You must be signed in to change notification settings - Fork 136
/
generate-sqltomvt
executable file
·76 lines (68 loc) · 3.33 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
67
68
69
70
71
72
73
74
75
76
#!/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>] [--postgis-ver <version>]
[--function | --prepared | --query | --psql | --raw]
[--layer=<layer>]... [--exclude-layers] [--key]
[--gzip [<gzlevel>]] [--no-feature-ids]
[--test-geometry] [--extent=<extent>]
generate-sqltomvt --help
generate-sqltomvt --version
<tileset> Tileset definition yaml file
Options:
-v --postgis-ver=<v> Which version of PostGIS to target. [default: 3.0]
This parameter optimizes generated SQL for the specific ver.
--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
-g --test-geometry Validate all geometries produced by ST_AsMvtGeom(), and warn.
--extent=<extent> MVT tile extent [default: 4096].
--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__)
if args['--prepared'] or args['--query']:
zoom, x, y = '$1', '$2', '$3'
elif args['--psql']:
zoom, x, y = ':zoom', ':x', ':y'
elif args['--raw']:
zoom, x, y = None, None, None
else:
zoom, x, y = 'zoom', 'x', 'y'
extent = int(args['--extent']) if args['--extent'] is not None else 4096
mvt = MvtGenerator(
tileset=args['<tileset>'],
postgis_ver=args['--postgis-ver'],
zoom=zoom, x=x, y=y,
layer_ids=args['--layer'],
exclude_layers=args['--exclude-layers'],
key_column=args['--key'],
gzip=args['--gzip'] and (args['<gzlevel>'] or True),
use_feature_id=False if args['--no-feature-ids'] else None,
test_geometry=args['--test-geometry'],
extent=extent,
)
if args['--prepared']:
sql = mvt.generate_sqltomvt_preparer(args['--fname'])
elif args['--query'] or args['--psql'] or args['--raw']:
sql = mvt.generate_sql()
else:
# --function or default
sql = mvt.generate_sqltomvt_func(args['--fname'])
print(sql)