Tile-based geodata processing using rasterio & Fiona
Project description
Tile-based geodata processing.
Mapchete processes raster and vector geodata in digestable chunks.
Processing larger amounts of data requires chunking the input data into smaller tiles and process them one by one. Python provides a lot of useful packages to process geodata like shapely or numpy. From within your process code you will have access to the geodata in the form of NumPy arrays for raster data or GeoJSON-like feature dictionaries for vector data.
Internally the processing job is split into tasks which can processed in parallel using either concurrent.futures or build task graphs and use dask to intelligently process either on the local machine or on a cluster.
With the help of fiona and rasterio Mapchete takes care about resampling and reprojecting geodata, applying your Python code to the tiles and writing the output either into a single file or into a directory of files organized in a WMTS-like tile pyramid. Details on tiling scheme and available map projections are outlined in the tiling documentation.
Usage
You need a .mapchete file for the process configuration. The configuration is based on the YAML syntax.
process: my_python_process.py # or a Python module path: mypythonpackage.myprocess
zoom_levels:
min: 0
max: 12
input:
dem: /path/to/dem.tif
land_polygons: /path/to/polygon/file.geojson
output:
format: PNG_hillshade
path: /output/path
pyramid:
grid: mercator
# process specific parameters
resampling: cubic_spline
You also need either a .py file or a Python module path where you specify the process itself.
def execute(mp, resampling="nearest"):
# Open elevation model.
with mp.open("dem") as src:
# Skip tile if there is no data available or read data into a NumPy array.
if src.is_empty(1):
return "empty"
else:
dem = src.read(1, resampling=resampling)
# Create hillshade using a built-in hillshade function.
hillshade = mp.hillshade(dem)
# Clip with polygons from vector file and return result.
with mp.open("land_polygons") as land_file:
return mp.clip(hillshade, land_file.read())
You can then interactively inspect the process output directly on a map in a browser (first, install dependencies by pip install mapchete[serve] go to localhost:5000):
$ mapchete serve hillshade.mapchete --memory
The serve tool recognizes changes in your process configuration or in the process file. If you edit one of these, just refresh the browser and inspect the changes (note: use the --memory flag to make sure to reprocess each tile and turn off browser caching).
Once you are done with editing, batch process everything using the execute tool.
$ mapchete execute hillshade.mapchete
Documentation
There are many more options such as zoom-dependent process parameters, metatiling, tile buffers or interpolating from an existing output of a higher zoom level. For deeper insights, please go to the documentation.
Mapchete is used in many preprocessing steps for the EOX Maps layers:
Merge multiple DEMs into one global DEM.
Create a customized relief shade for the Terrain Layer.
Generalize landmasks & coastline from OSM for multiple zoom levels.
Extract cloudless pixel for Sentinel-2 cloudless.
Installation
via PyPi:
$ pip install mapchete
from source:
$ git clone git@github.com:ungarj/mapchete.git && cd mapchete
$ pip install .
To make sure Rasterio, Fiona and Shapely are properly built against your local GDAL and GEOS installations, don’t install the binaries but build them on your system:
$ pip install --upgrade rasterio fiona shapely --no-binary :all:
To keep the core dependencies minimal if you install mapchete using pip, some features are only available if you manually install additional dependencies:
# for contour extraction:
$ pip install mapchete[contours]
# for dask processing:
$ pip install mapchete[dask]
# for S3 bucket reading and writing:
$ pip install mapchete[s3]
# for mapchete serve:
$ pip install mapchete[serve]
# for VRT generation:
$ pip install mapchete[vrt]
License
MIT License
Copyright (c) 2015 - 2022 EOX IT Services
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mapchete-2024.11.0.tar.gz
.
File metadata
- Download URL: mapchete-2024.11.0.tar.gz
- Upload date:
- Size: 151.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a8fe426361dfe8d25a943cde77a0355161f9dd623d30359dd3111def4a6244e |
|
MD5 | 3d9f80c65a3da5f279cc6c41e6cb0a49 |
|
BLAKE2b-256 | 979f5f79b0959ccc2ac721dedc6a7834ec299f3b2465884148135c060abcc32b |
File details
Details for the file mapchete-2024.11.0-py2.py3-none-any.whl
.
File metadata
- Download URL: mapchete-2024.11.0-py2.py3-none-any.whl
- Upload date:
- Size: 215.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 514a2468bdb5290df049cd54833c5de9ad0a053c5da7952ec084644eb2d153ba |
|
MD5 | 5cd919516ef09d687281c4364bc2a419 |
|
BLAKE2b-256 | f5f4119d363568f80b9ed77f296fc99c663a9b3160bcdb879203068fe004d648 |