This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
configure.py
65 lines (55 loc) · 2.08 KB
/
configure.py
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
"""
Configures this MapBox project to work with your local PostGIS server.
"""
#
# You need to fill out this part to match your local postgres connection!
#
# PostGIS connection setup
dbname = "osm_california"
host = "localhost"
port = "5432"
user = "postgres"
password = "postgres"
# For postgres layers mapnik by default will query postgis for the
# extent to know whether to process the layer during rendering
# Increase performance if you are only rendering a particular area by
# specifying a bounding box in the format of "XMIN,YMIN,XMAX,YMAX" in the
# same units as the database (probably spherical mercator meters). The
# whole world is "-20037508.34,-20037508.34,20037508.34,20037508.34".
extent = "-13849828.38,3833234.22,-12705175.77,5162381.7"
# osm2pgsql table prefix - only change this is you explicitly imported
# with a custom prefix (--prefix)
prefix = 'planet_osm'
# if you have > 2GB mem, turn this on for slightly faster rendering
feat_caching = True
#
# Don't touch this part down here, just run it.
#
import os
import json
from sys import path
from os.path import join
this_dir = os.path.dirname(__file__)
source_mml = os.path.join(this_dir, 'quiet-la/project.mml.template')
target_mml = os.path.join(this_dir, 'quiet-la/project.mml')
with open(source_mml, 'r') as f:
newf = json.loads(f.read())
f.closed
with open(target_mml, 'w') as f:
for layer in newf["Layer"]:
layer["properties"] = {}
if feat_caching:
layer["properties"]["cache-features"] = "true"
ds_type = layer["Datasource"].get("type")
if ds_type and ds_type == "postgis":
layer["Datasource"]["host"] = host
layer["Datasource"]["port"] = port
layer["Datasource"]["dbname"] = dbname
layer["Datasource"]["user"] = user
layer["Datasource"]["password"] = password
layer["Datasource"]["extent"] = extent
layer["Datasource"]["srid"] = 900913
if prefix != 'planet_osm':
layer["Datasource"]["table"] = layer["Datasource"]["table"].replace('planet_osm',prefix)
f.write(json.dumps(newf, sort_keys=True, indent=2))
f.closed