-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-qgis.py
executable file
·63 lines (52 loc) · 1.99 KB
/
start-qgis.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
#!/usr/bin/qgis --code
# Exploratory script to work out QGIS automation.
import itertools
from pathlib import Path
from qgis.core import *
project = QgsProject.instance()
# Sort our sources to order properly.
# I'm being a bit cheeky by doing sections within a geometry type in reverse
# alphabetical order, as that is just to get cyleways over highways over
# railways. And then we want water polygons over park polygons...
# But we definitely want polygons at the bottom, lines above, and points above
# those.
data = Path("./data")
sources = set(data.glob("*_*.qml"))
sorted_sources = []
for filename in (
"amenities_polygons.qml",
"parks_polygons.qml",
"water_lines.qml",
"water_polygons.qml",
"rail_polygons.qml",
"rail_lines.qml",
"rail_points.qml",
"highways_lines.qml",
"highways_points.qml",
"cycleroutes_lines.qml",
):
try:
sources.remove(data / filename)
sorted_sources.append(data / filename)
except KeyError:
pass
sorted_sources.extend(sources)
# Load only the source/geometry data for which we have automatic styling files
for style_file in sorted_sources:
json_file = style_file.with_suffix(".geojson")
vlayer = QgsVectorLayer(str(json_file), json_file.stem, "ogr")
vlayer.loadNamedStyle(str(style_file))
project.addMapLayer(vlayer)
QgsApplication.processEvents() # Kick the GUI to catch up so we can set the projection
web_mercator = QgsCoordinateReferenceSystem.fromEpsgId(3857)
# wgs84 = QgsCoordinateReferenceSystem.fromEpsgId(4326)
project.setCrs(web_mercator, True)
# Try to grab the font we use for street names
fontmgr = QgsApplication.fontManager()
fontmgr.addUserFontDirectory(str(Path("./fonts").absolute()))
fontmgr.tryToDownloadFontFamily("IBM Plex Sans Condensed")
if not all(QgsFontUtils.fontFamilyMatchOnSystem("IBM Plex Sans Condensed")):
QgsMessageLog.logMessage(
"Please install the IBM Plex Sans Condensed font from https://github.com/IBM/plex/releases",
level=Qgis.Critical,
)