swisstopopy
swisstopo geospatial Python utilities.
Features
STAC API utilities
Easily filter swisstopo STAC collections based on geospatial extents, dates, file extensions or data resolutions:
import contextily as cx
import swisstopopy
region = "EPFL"
client = swisstopopy.SwissTopoClient(region)
alti3d_gdf = client.get_collection_gdf(
swisstopopy.SWISSALTI3D_COLLECTION_ID,
)
ax = alti3d_gdf.plot(alpha=0.1)
cx.add_basemap(ax, crs=alti3d_gdf.crs)
Filter to get the latest data for each tile:
latest_alti3d_gdf = swisstopopy.get_latest(alti3d_gdf)
latest_alti3d_gdf.head()
| id | collection | ... | geometry | |
|---|---|---|---|---|
| 0 | swissalti3d_2021_2532-1151 | ch.swisstopo.swissalti3d | ... | POLYGON ((6.56572 46.50684, 6.56572 46.51594, ... |
| 1 | swissalti3d_2021_2532-1151 | ch.swisstopo.swissalti3d | ... | POLYGON ((6.56572 46.50684, 6.56572 46.51594, ... |
| 2 | swissalti3d_2021_2532-1151 | ch.swisstopo.swissalti3d | ... | POLYGON ((6.56572 46.50684, 6.56572 46.51594, ... |
| 3 | swissalti3d_2021_2532-1151 | ch.swisstopo.swissalti3d | ... | POLYGON ((6.56572 46.50684, 6.56572 46.51594, ... |
| 4 | swissalti3d_2021_2532-1152 | ch.swisstopo.swissalti3d | ... | POLYGON ((6.56558 46.51584, 6.56558 46.52493, ... |
or filter by other metadata attributes such as ground resolution and/or file extensions:
alti3d_gdf[
(alti3d_gdf["assets.eo:gsd"] == 0.5)
& alti3d_gdf["assets.href"].str.endswith(".tif")
]
| id | collection | ... | geometry | |
|---|---|---|---|---|
| 0 | swissalti3d_2019_2532-1151 | ch.swisstopo.swissalti3d | ... | POLYGON ((6.56572 46.50684, 6.56572 46.51594, ... |
| 4 | swissalti3d_2019_2532-1152 | ch.swisstopo.swissalti3d | ... | POLYGON ((6.56558 46.51584, 6.56558 46.52493, ... |
| 8 | swissalti3d_2019_2533-1152 | ch.swisstopo.swissalti3d | ... | POLYGON ((6.57861 46.51594, 6.57861 46.52503, ... |
| 12 | swissalti3d_2021_2532-1151 | ch.swisstopo.swissalti3d | ... | POLYGON ((6.56572 46.50684, 6.56572 46.51594, ... |
| 16 | swissalti3d_2021_2532-1152 | ch.swisstopo.swissalti3d | ... | POLYGON ((6.56558 46.51584, 6.56558 46.52493, ... |
| 20 | swissalti3d_2021_2533-1152 | ch.swisstopo.swissalti3d | ... | POLYGON ((6.57861 46.51594, 6.57861 46.52503, ... |
STAC data processing
Automated generation of geospatial datasets: building footprints with estimated heights, DEM and tree canopy. For example, a tree canopy raster for any given part of Switzerland can be obtained as in:
import rasterio as rio
from rasterio import plot
dst_filepath = "tree-canopy.tif"
swisstopopy.get_tree_canopy_raster(region, dst_filepath)
with rio.open(dst_filepath) as src:
plot.show(src)
See the overview notebook and the API documentation for more details on the geospatial dataset generation functions.
Installation
Like many other geospatial Python packages, swisstopopy requires many base C libraries that cannot be installed with pip. Accordingly, the best way to install swisstopopy is to use conda/mamba, i.e., in a given conda environment, run:
# or mamba install -c conda-forge geopandas
conda install -c conda-forge geopandas
Within the same conda environment, you can then install swisstopopy using pip:
pip install swisstopopy
Note that the get_tree_canopy_raster requires PDAL and its Python bindings, which are not installed by default with swisstopopy. Like with geopandas, the easiest way to install such requirements is using conda/mamba, e.g.: conda install -c conda-forge python-pdal.
Notes
The SwissTopoClient class can be used to process any collection of the swisstopo STAC API, and basic features succh as geospatial and datetime filtering should work out of the box. However, filtering based on further metadata such as the resolution is only fully supported for the following collections:
- "ch.swisstopo.swissalti3d", namely swissALTI3D
- "ch.swisstopo.swissimage-dop10", namely SWISSIMAGE 10 cm
- "ch.swisstopo.swisssurface3d", namely swissSURFACE3D
- "ch.swisstopo.swisssurface3d-raster", namely swissSURFACE3D Raster.
Acknowledgements
- This package was created with the martibosch/cookiecutter-geopy-package project template.
Metadata
Release files for swisstopopy 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swisstopopy-0.4.0.tar.gz | 25.6 kB | Without provenance | Details for swisstopopy-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swisstopopy-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for swisstopopy-0.4.0-py3-none-any.whl |
Total release size: 53.1 kB
Release files / swisstopopy-0.4.0.tar.gz
| Download URL | swisstopopy-0.4.0.tar.gz |
|---|---|
| Size | 25.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
946b38c63f2de278105ad95bcdab4498b8a83819479d37f4f700d403ea6cdb3d
|
|
BLAKE2b-256 checksum How to use checksums |
023dadfe47994238847830c417c08c471ec990df380f456fdbac73bc962b9ca5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / swisstopopy-0.4.0-py3-none-any.whl
| Download URL | swisstopopy-0.4.0-py3-none-any.whl |
|---|---|
| Size | 27.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9acfb45497d1fd418403226364f582b85f5bb4ebe0ef92d9b9cc97731d10a68a
|
|
BLAKE2b-256 checksum How to use checksums |
59b266955254a2984b450b93e1abf3b46b160acdc5072d73f799200a2208d139
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for swisstopopy 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.