#瓦片 #栅格 #地图 #地理

map-engine

用于处理瓦片地理(栅格)数据的库

1 个不稳定版本

0.1.0 2022年1月12日

#258可视化


用于 map-engine-server

MIT 协议

7MB
2.5K SLoC

map-engine

Gitlab pipeline status Gitlab code coverage Crates.io Documentation

用于处理瓦片地理(栅格)数据的库。

这是系列crate的基础库。它包含以下方法:

  • 处理XYZ瓦片
  • 读取与瓦片相交的栅格数据
  • 样式数据以生成彩色PNG文件

🚧 这是一个正在进行中的项目,因此API是不稳定的,并可能在相关crate开发过程中发生变化。🚧

示例

use map_engine::{
    errors::MapEngineError,
    cmap::{Composite, viridis},
    raster::{Raster, RawPixels},
    tiles::Tile,
};
use std::path::PathBuf;

fn main() -> Result<(), MapEngineError> {
    let tile = Tile::new(304, 624, 10);
    let raster = Raster::new(PathBuf::from("src/tests/data/chile_optimised.tif"))?;

    // Note that these three things should support the same number of bands (in this case, 1).
    // At the moment we don't enforce this at compile time.
    // https://gitlab.com/spadarian/map_engine/-/issues/36
    let comp = Composite::new_gradient(0.0, 27412.0, &viridis);
    let bands = &[1];
    let na_value = vec![0.0];
    assert!(comp.n_bands() == bands.len());
    assert!(comp.n_bands() == na_value.len());

    let arr: RawPixels<f64> = raster.read_tile(&tile, Some(bands), None)?;
    let styled = arr.style(comp, na_value)?;
    let png = styled.into_png()?;  // PNG as a byte sequence

    // The PNG can then be sent as an HTTP response, written to disk, etc.
    // Also, we have a method to write to disk:
    // styled.write_to_disk(std::path::Path::new("path_to_png"))?;

    Ok(())
}

安装说明

目前,我们仅支持Linux,但该crate可能在macOS和Windows上工作(请告诉我们!)。

我们依赖于GDAL >3.3,您可能需要自行编译

Ubuntu

UbuntuGIS团队有一个GDAL的最新版本(3.3.2),可能适用于您。

依赖项

~11MB
~262K SLoC