Package: mapchete
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
likeshapelyornumpy. From within your process code you will have access to the geodata
in the form ofNumPyarrays 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 eitherconcurrent.futuresor build task graphs and usedaskto intelligently process either on
the local machine or on a cluster.With the help offionaandrasterioMapchete 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 aWMTS-like tile pyramid.
Details on tiling scheme and available map projections are outlined in thetiling documentation.(standard Web Mercator pyramid used in the web)UsageYou need a.mapchetefile for the process configuration. The configuration is based
on theYAMLsyntax.process:my_python_process.py# or a Python module path: mypythonpackage.myprocesszoom_levels:min:0max:12input:dem:/path/to/dem.tifland_polygons:/path/to/polygon/file.geojsonoutput:format:PNG_hillshadepath:/output/pathpyramid:grid:mercator# process specific parametersresampling:cubic_splineYou also need either a.pyfile or a Python module path where you specify the process
itself.defexecute(mp,resampling="nearest"):# Open elevation model.withmp.open("dem")assrc:# Skip tile if there is no data available or read data into a NumPy array.ifsrc.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.withmp.open("land_polygons")asland_file:returnmp.clip(hillshade,land_file.read())You can then interactively inspect the process output directly on a map in a
browser (first, install dependencies bypip install mapchete[serve]go tolocalhost:5000):$mapcheteservehillshade.mapchete--memoryTheservetool 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--memoryflag to make sure to reprocess each tile and
turn off browser caching).Once you are done with editing, batch process everything using theexecutetool.$mapcheteexecutehillshade.mapcheteDocumentationThere 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 thedocumentation.Mapchete is used in many preprocessing steps for theEOX Mapslayers: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-2cloudless.Installationvia PyPi:$pipinstallmapchetefrom source:$gitclonegit@github.com:ungarj/mapchete.git&&cdmapchete$pipinstall.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:$pipinstall--upgraderasteriofionashapely--no-binary:all:To keep the core dependencies minimal if you install mapchete usingpip, some features
are only available if you manually install additional dependencies:# for contour extraction:$pipinstallmapchete[contours]# for dask processing:$pipinstallmapchete[dask]# for S3 bucket reading and writing:$pipinstallmapchete[s3]# for mapchete serve:$pipinstallmapchete[serve]# for VRT generation:$pipinstallmapchete[vrt]LicenseMIT LicenseCopyright (c) 2015 - 2022EOX IT Services