Expand description
§ridge-core
The terrain pipeline behind ridge_redux: a Rust port of the Python package ridge_map (“3D maps with 1D lines”), without matplotlib.

It turns a bounding box into ridgeline artwork:
- Fetch SRTM elevation tiles from a mirror, cached on disk
(
srtm). - Sample a grid of lines over the box
(
grid). The sampling is bit-for-bit identical to ridge_map’s, checked against its test fixture. - Rotate to a viewpoint angle, like
scipy.ndimage.rotate(rotate). - Mask water and lakes, and exaggerate the relief
(
preprocess). - Lay out the ridge rows as a matplotlib-style figure
(
geometry) and write SVG (svg).
§Command line
cargo install ridge-core installs render, which draws one map to SVG:
render --bbox "11.098251,47.264786,11.695633,47.453630" \
--num-lines 150 --vertical-ratio 240 --lake-flatness 2 \
--label "Karwendelgebirge" --label-x 0.55 --label-y 0.1 --label-size 40 \
--out karwendel.svgrender --help lists every option. For an interactive editor (pick the area
on a map, rotate and restyle live), use cargo install ridge_redux.
§Library
use ridge_core::colormap::{hex, LineColor};
use ridge_core::geometry::{build_scene, ColorKind};
use ridge_core::srtm::RemoteSource;
use ridge_core::svg::{render_svg, LineColorSpec, PlotStyle};
use ridge_core::Bbox;
fn main() -> ridge_core::Result<()> {
// Downloads tiles on first use and caches them in srtm::default_cache_dir().
let source = RemoteSource::default_paths()?;
let white_mountains = Bbox::new(-71.928864, 43.758201, -70.957947, 44.465151);
let scene = build_scene(
&source,
&white_mountains,
80, 300, // lines, points per line
0.0, false, 0, false, // viewpoint angle, crop, interpolation, lock resolution
10.0, 3, 40.0, // water percentile, lake flatness, vertical ratio
20.0, // figure width in inches
)?;
let style = PlotStyle {
line: LineColorSpec::from(&LineColor::parse("black").unwrap()),
kind: ColorKind::Gradient,
background: hex("#ece8ec"),
linewidth_pt: 2.0,
size_scale: 20.0,
label: None,
annotation: None,
};
std::fs::write("white_mountains.svg", render_svg(&scene, &style))?;
Ok(())
}srtm::DirSource reads .hgt tiles from a directory instead, for offline
use. SRTM covers latitudes between 60°S and 60°N.
§License
MIT. ridge-core is a port of ridge_map, also MIT, whose copyright notice is kept in LICENSE-upstream.
Elevation data: NASA Shuttle Radar Topography Mission.
§Implementation notes
A port of the Python ridge_map package (with the parts of SRTM.py,
numpy and scipy.ndimage it relies on) to Rust, minus matplotlib:
rendering is delegated to svg (server-side export) or to the web
frontend, which consumes geometry::RidgeScene JSON.
Re-exports§
pub use geometry::RidgeRow;pub use geometry::RidgeScene;pub use srtm::Tile;pub use srtm::TileSource;
Modules§
- colormap
- Colors: named RGB values, matplotlib-style colormaps.
- geometry
- Turn a processed elevation grid into drawable ridge lines.
- grid
- Sample a bounding box into an elevation grid — the Rust twin of
SRTM.py’sget_image(..., mode='array')as used by ridge_map. - preprocess
- Replicates
RidgeMap.preprocess: water/lake masking + vertical scaling. - rotate
- 2D array rotation: the frozen scipy port plus our interactive mode.
- srtm
- SRTM elevation tiles: parsing, downloading, caching.
- svg
- Server-side SVG rendering of a
RidgeScene— the matplotlib-free replacement forRidgeMap.plot_map/plot_annotation. - upstream
- Frozen ports of the reference implementations (scipy/numpy/skimage). Do not edit; see the module docs. Frozen ports of the reference implementations ridge-core has to match.
Structs§
- Bbox
- Geographic bounding box,
(long, lat, long, lat)of the bottom-left and top-right corners, exactly like upstreamRidgeMap.__init__.
Enums§
Constants§
- DEFAULT_
BBOX - Default bounding box from upstream ridge_map: The White Mountains, NH.