基于分块的栅格和fiona大地数据处理
mapchete的Python项目详细描述
基于平铺的地理数据处理。
mapchete以可消化的块处理栅格和矢量地理数据。
处理大量数据需要将输入数据分块到较小的分块中 并逐一处理。python提供了许多有用的包来处理geodata 比如shapely或者numpy。在您的过程代码中,您可以访问geodata 以NumPy数组的形式存储光栅数据或类似geojson的功能字典 矢量数据。
在fiona和rasterio的帮助下,mapchete负责重采样和 重新投影geodata,将python代码应用于tiles并编写输出 放入单个文件或按WMTS类平铺金字塔组织的文件目录中。 有关平铺方案和可用地图投影的详细信息,请参见 tiling documentation。
用法
进程配置需要一个.mapchete文件。配置基于 关于YAML语法。
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_spline
您还需要.py文件或指定进程的python模块路径 本身。
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())
然后,可以在 浏览器(首先,通过pip install mapchete[serve]安装依赖项转到 localhost:5000):
$ mapchete serve hillshade.mapchete --memory
serve工具可以识别进程配置或 处理文件。如果您编辑其中一个,只需刷新浏览器并检查 更改(注意:使用--memory标志确保重新处理每个磁贴和 关闭浏览器缓存)。
完成编辑后,使用^{tt9}批处理所有内容$ 工具。
$ mapchete execute hillshade.mapchete
文档
还有许多其他选项,如缩放相关的过程参数、元平铺、平铺 缓冲器或从更高缩放级别的现有输出中插入。为了更深入 见解,请转到documentation。
mapchete用于EOX Maps层的许多预处理步骤:
- 将多个DEM合并为一个全局DEM。
- 为地形层创建自定义的浮雕阴影。
- 从OSM将陆地和海岸线概括为多个缩放级别。
- 为sentinel-2cloudless提取无云像素。
安装
通过PYPI:
$ pip install mapchete
来源:
$ git clone git@github.com:ungarj/mapchete.git &&cd mapchete $ pip install .
为了确保rasterio和fiona是针对本地gdal安装正确构建的, 不要安装二进制文件,而是在系统上构建它们:
$ pip install --upgrade rasterio fiona --no-binary :all:
如果使用pip安装mapchete,为了使核心依赖性保持最小,需要一些特性 仅当手动安装其他依赖项时才可用:
# for contour extraction: $ pip install mapchete[contours]# for S3 bucket reading and writing: $ pip install mapchete[s3]# for mapchete serve: $ pip install mapchete[serve]# for VRT generation: $ pip install mapchete[vrt]