3bag viewer city json files van alle tiles in één keer downloaden, zoals het gpkg zip bestand

De 3d bag viewer geeft een mogelijkheid om in één keer een gpkg zip bestand te downloaden van alle tiles. Ik zou dit graag willen doen met alle city json files van de tiles. Of is er een handige manier om deze geautomatiseerd te downloaden in plaats van één voor één de tiles in de viewer te selecteren.

Dankjewel alvast!

Hi there, I did this just recently.

You need to export the Tiles layer from the WFS server, then you can setup a Python script which downloads the whole thing.

Here’s a script that will do that for you:

import os
import requests
import pandas as pd
import geopandas as gpd
from tqdm import tqdm
from concurrent.futures import ThreadPoolExecutor

OUTPUT_FOLDER = '3dbag_tiles_download'

def download_file(url):
    # Get the file name from the URL
    file_name = url.split("/")[-1]
    file_path = os.path.join(OUTPUT_FOLDER, file_name)

    # Check if the file already exists
    if os.path.exists(file_path):
        print(f"File already exists, skipping: {file_path}")
        return

    try:
        # Download the file
        response = requests.get(url)

        # Check if the request was successful
        if response.status_code != 200:
            print(f"Failed to download {url}. HTTP status code: {response.status_code}")
            return

        # Save the file to a directory
        with open(file_path, 'wb') as file:
            file.write(response.content)
    except Exception as e:
        print(f"Failed to download or save {url}. Error: {str(e)}")

# Load the GeoPackage file
tiles = gpd.read_file("tiles_exported.gpkg", layer='tiles_exported')

# Get the download URLs
urls = pd.concat([tiles['cj_download']]) # Add alt. formats if needed: tiles['obj_download'], tiles['gpkg_download']

# Number of workers in the pool (change to the number of cores on your machine)
num_workers = 16

# Create a ThreadPoolExecutor
with ThreadPoolExecutor(max_workers=num_workers) as executor:
    # Use the executor to map the download_file function to the URLs
    list(tqdm(executor.map(download_file, urls), total=len(urls), desc="Overall progress", unit="file"))

I’m too new of a user to upload my tiles_exported.gpkg-file, but you simply export it using the WFS server and the Tiles layer.

2 likes

Hi, thanks for your answer. I’m also struggling with exporting the Tiles layer from the WFS server. I’ve never done this before in Python. Do you have a solution for this as well?

That part is easy to do in QGIS.

  • Add the WFS to qgis. (layer / add layer / add wfs, url: https://data.3dbag.nl/api/BAG3D/wfs?request=getcapabilities)
  • Add the WFS layer to your project from the browser.
  • Right click it in the layer view
  • Select export / save layer as
  • Select geopackage