geojson-tile-renderer

Crates.iogeojson-tile-renderer
lib.rsgeojson-tile-renderer
version0.1.0
created_at2025-10-27 22:44:50.840144+00
updated_at2025-10-27 22:44:50.840144+00
descriptionConvert GeoJSON features to PNG tile images with Web Mercator projection
homepagehttps://github.com/rrainn/geojson-to-tile-images-rust
repositoryhttps://github.com/rrainn/geojson-to-tile-images-rust
max_upload_size
id1903839
size130,195
Charlie Fish (fishcharlie)

documentation

https://docs.rs/geojson-tile-renderer

README

geojson-tile-renderer

A high-performance Rust library for converting GeoJSON features to PNG tile images with Web Mercator projection (EPSG:3857).

This is a Rust port of the geojson-to-tile-images TypeScript library, providing ~50x faster performance for batch tile rendering.

Features

  • ✅ Render Polygon, LineString, Point, and Multi* geometries
  • ✅ Web Mercator projection (EPSG:3857)
  • ✅ Configurable tile sizes and styling
  • ✅ Parallel tile rendering with Rayon
  • ✅ Complete feature parity with TypeScript version

Performance

  • ~50x faster for batch rendering (100 tiles)
  • Single tile: <1ms vs 3ms (TypeScript)
  • 100 tiles: 4ms vs 193ms (TypeScript)
  • Memory: ~10-20MB vs 130MB+ (Node.js)

Usage

Add this to your Cargo.toml:

[dependencies]
geojson-tile-renderer = "0.1.0"

Basic Example

use geojson_tile_renderer::{TileRenderer, TileCoordinate, Settings, BackgroundColor};

fn main() -> Result<(), Box<dyn std::error::Error>> {
	// Create renderer
	let renderer = TileRenderer::builder()
		.settings(
			Settings::builder()
				.size(512)
				.background_color(BackgroundColor::white())
				.build()?
		)
		.build()?;

	// Load GeoJSON
	let geojson: geojson::FeatureCollection =
		std::fs::read_to_string("data.geojson")?.parse()?;

	// Render single tile
	let tile = TileCoordinate::new(10, 163, 395)?;
	let png_data = renderer.render(&geojson, tile)?;
	std::fs::write("tile.png", png_data)?;

	Ok(())
}

Batch Rendering (Parallel)

// Render multiple tiles in parallel
let tiles = vec![
	TileCoordinate::new(10, 163, 395)?,
	TileCoordinate::new(10, 164, 395)?,
	TileCoordinate::new(10, 163, 396)?,
];
let results = renderer.render_many(&geojson, &tiles)?;

for (tile, png_data) in tiles.iter().zip(results.iter()) {
	let filename = format!("tile_{}_{}.png", tile.x(), tile.y());
	std::fs::write(filename, png_data)?;
}

Styling Options

use geojson_tile_renderer::{
	Settings, BackgroundColor, FillColor, StrokeColor, StrokeWidth
};

let settings = Settings::builder()
	.size(512)
	.background_color(BackgroundColor::transparent())
	.fill_color(FillColor::rgb(0, 123, 255))
	.stroke_color(StrokeColor::rgb(255, 0, 0))
	.stroke_width(StrokeWidth::new(2.0))
	.build()?;

CLI Tool

For command-line usage, install the CLI tool separately:

cargo install geojson-tile-cli

License

MIT - See LICENSE file for details

Credits

Rust port based on the original geojson-to-tile-images by Charlie Fish.

Commit count: 0

cargo fmt