-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathoverture_data.py
More file actions
47 lines (35 loc) · 1.42 KB
/
overture_data.py
File metadata and controls
47 lines (35 loc) · 1.42 KB
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
import requests
from osgeo import ogr
from qgis.core import QgsProject, QgsVectorLayer
url = "https://labs.overturemaps.org/data/releases.json"
response = requests.get(url)
release = response.json().get("latest").split(".")[0]
print(f"Using release: {release}")
# themes = ["addresses", "base", "buildings", "divisions", "transportation"]
themes = ["buildings"]
for theme in themes:
print(f"Adding {theme} data...")
# Define the URL for the theme
url = f"/vsicurl/https://overturemaps-tiles-us-west-2-beta.s3.amazonaws.com/{release}/{theme}.pmtiles"
# Open the OGR datasource
datasource = ogr.Open(url)
if datasource is None:
print(f"Failed to open {theme} data.")
continue
# Get the number of layers in the datasource
layer_count = datasource.GetLayerCount()
# Loop through all the layers and add them to the project
for i in range(layer_count):
layer = datasource.GetLayerByIndex(i)
layer_name = layer.GetName()
# Create a QgsVectorLayer for each OGR layer
vector_layer = QgsVectorLayer(
f"{url}|layername={layer_name}", f"{theme} - {layer_name}", "ogr"
)
if not vector_layer.isValid():
print(f"Layer {layer_name} is invalid.")
continue
# Add the layer to the QGIS project
QgsProject.instance().addMapLayer(vector_layer)
print(f"Added {layer_name} from {theme}.")
print("Done!")