forked from openmaptiles/openmaptiles-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postserve
executable file
·101 lines (94 loc) · 4.71 KB
/
postserve
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
"""
This is a simple vector tile server that returns a PBF tile for /tiles/{z}/{x}/{y}.pbf requests
Usage:
postserve <tileset> [--serve=<host>] [--port=<port>] [--key] [--gzip [<gzlevel>]]
[--no-feature-ids] [--no-tile-envelope] [--file=<sql-file>]
[--layer=<layer>]... [--exclude-layers]
[--pghost=<host>] [--pgport=<port>] [--dbname=<db>]
[--user=<user>] [--password=<password>]
[--test-geometry] [--verbose]
postserve --help
postserve --version
<tileset> Tileset definition yaml file
Options:
-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)
-s --serve=<port> Return this hostname as tileserver URL in metadata [default: localhost]
-p --port=<port> Serve on this port [default: 8090]
--key If set, print md5 of the data to console (generated by Postgres)
--gzip If set, compress MVT with gzip, with optional level=0..9.
--no-feature-ids Disable feature ID generation, e.g. from osm_id.
Feature IDS are automatically disabled with PostGIS before v3
--no-tile-envelope Disable PostGIS 3.0+ ST_TileEnvelope() function.
ST_TileEnvelope() is auto-disabled with PostGIS before v3.
-g --test-geometry Validate all geometries produced by ST_AsMvtGeom(), and warn.
-v --verbose Print additional debugging information
--help Show this screen.
--version Show version.
POSTGRES options:
-h --pghost=<host> Postgres hostname. By default uses POSTGRES_HOST env or "localhost" if not set.
-P --pgport=<port> Postgres port. By default uses POSTGRES_PORT env or "5432" if not set.
-d --dbname=<db> Postgres db name. By default uses POSTGRES_DB env or "openmaptiles" if not set.
-U --user=<user> Postgres user. By default uses POSTGRES_USER env or "openmaptiles" if not set.
--password=<password> Postgres password. By default uses POSTGRES_PASSWORD env or "openmaptiles" if not set.
--file=<sql-file> Override SQL file generated by generate-sqltomvt script with the --query flag
Additional ENV variables:
BBOX, CENTER_ZOOM, MIN_ZOOM, MAX_ZOOM,
METADATA_NAME, METADATA_ID, METADATA_VERSION,
METADATA_ATTRIBUTION, METADATA_DESCRIPTION, METADATA_TYPE
"""
from docopt import docopt
import os.path
import openmaptiles
from openmaptiles.postserve import Postserve
from openmaptiles.utils import Bbox, coalesce
from openmaptiles.consts import *
if __name__ == '__main__':
args = docopt(__doc__, version=openmaptiles.__version__)
bbox = Bbox(bbox=os.environ.get('BBOX'),
center_zoom=os.environ.get('CENTER_ZOOM', CENTER_ZOOM))
metadata = dict(
format="pbf",
name=os.environ.get('METADATA_NAME', METADATA_NAME),
id=os.environ.get('METADATA_ID', METADATA_ID),
bounds=bbox.bounds(),
center=bbox.center(),
maxzoom=int(os.environ.get('MAX_ZOOM', MAX_ZOOM)),
minzoom=int(os.environ.get('MIN_ZOOM', MIN_ZOOM)),
version=os.environ.get('METADATA_VERSION', METADATA_VERSION),
attribution=os.environ.get('METADATA_ATTRIBUTION', METADATA_ATTRIBUTION),
description=os.environ.get('METADATA_DESCRIPTION', METADATA_DESCRIPTION),
pixel_scale=PIXEL_SCALE,
tilejson="2.0.0",
)
Postserve(
host=args['--serve'],
port=int(args['--port']),
pghost=coalesce(
args.get("--pghost"), os.getenv('POSTGRES_HOST'), os.getenv('PGHOST'),
'localhost'),
pgport=coalesce(
args.get("--pgport"), os.getenv('POSTGRES_PORT'), os.getenv('PGPORT'),
'5432'),
dbname=coalesce(
args.get("--dbname"), os.getenv('POSTGRES_DB'), os.getenv('PGDATABASE'),
'openmaptiles'),
user=coalesce(
args.get("--user"), os.getenv('POSTGRES_USER'), os.getenv('PGUSER'),
'openmaptiles'),
password=coalesce(
args.get("--password"), os.getenv('POSTGRES_PASSWORD'),
os.getenv('PGPASSWORD'), 'openmaptiles'),
metadata=metadata,
layers=args['--layer'],
exclude_layers=args['--exclude-layers'],
tileset_path=args['<tileset>'],
sql_file=args.get('--file'),
key_column=args['--key'],
gzip=args['--gzip'] and (args['<gzlevel>'] or True),
disable_feature_ids=args['--no-feature-ids'],
disable_tile_envelope=args['--no-tile-envelope'],
test_geometry=args['--test-geometry'],
verbose=args.get('--verbose'),
).serve()