-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_keplergl.py
executable file
·48 lines (39 loc) · 1.34 KB
/
create_keplergl.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
#!/usr/bin/env python3
import sys
import json
from keplergl import KeplerGl
from in_place import InPlace
from jinja2 import Template
def read_configuration(file_name, **kwargs):
with open(file_name) as file:
text = file.read()
template = Template(text)
text = template.render(**kwargs)
return json.loads(text)
def main():
column_short = sys.argv[1]
column_long = sys.argv[2]
config_file = "keplergl_config.json"
data_id = "buildings"
config = read_configuration(
config_file, label="Buildings", data_id=data_id, color_column=column_long
)
print("Using configuration (JSON syntax):")
print(json.dumps(config, indent=2))
kepler = KeplerGl(config=config)
kepler.add_data(data=open("buildings.geojson").read(), name=data_id)
output = f"keplergl_{column_short}.html"
kepler.save_to_html(file_name=output)
name = column_long.replace("_", " ")
# Add map title and creator
with InPlace(output) as file:
for line in file:
line = line.replace(
"<title>Kepler.gl</title>",
f"<title>{name} – Campus Research Reopening Map"
" by NCSU CGA</title>",
)
line = line.replace("Kepler.gl Jupyter", "Kepler.gl Map by NCSU CGA")
file.write(line)
if __name__ == "__main__":
main()