Last active
July 23, 2021 00:42
-
-
Save ThomasG77/80f99a186a44e6fa1930f2a08618d498 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
# Look at https://github.com/qgis/QGIS/blob/2d1aa68f0d044f2aced7ebeca8d2fa6b754ac970/src/app/qgsstatusbarcoordinateswidget.cpp#L113 | |
# and https://github.com/qgis/QGIS/tree/master/resources/data | |
iface.newProject() | |
data_base_path = [QgsApplication.pkgDataPath(), 'resources', 'data'] | |
world_map_path = os.path.join(*data_base_path, 'world_map.gpkg') | |
layers_world_map = ['countries', 'states_provinces', 'disputed_borders'] | |
QgsProject.instance().addMapLayers([ | |
QgsVectorLayer( | |
f"{world_map_path}|layername={layer}", | |
layer.replace('_', ' ').capitalize(), | |
"ogr" | |
) for layer in layers_world_map | |
]) | |
json_layers = ['contributors.json', 'qgis-hackfests.json', 'user_groups_data.json'] | |
qgis_vector_layers = [] | |
for layer in json_layers: | |
options = QgsVectorLayer.LayerOptions() | |
options.loadDefaultStyle = False # To avoid using default qml associated style | |
options.transformContext = QgsProject.instance().transformContext() | |
qgis_vector_layers.append( | |
QgsVectorLayer( | |
os.path.join(*data_base_path, layer), | |
layer.replace('_', ' ').replace('-', ' ').capitalize(), | |
"ogr", | |
options | |
) | |
) | |
QgsProject.instance().addMapLayers(qgis_vector_layers) | |
iface.mapCanvas().setProperty("retro", True) | |
iface.mapCanvas().refresh() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment