Geospatial programming with Rust

Pirmin Kalberer @implgeo

FOSS4G, 1. October 2021

About me

Language history

  • Basic
  • Assembler (6502)
  • (Turbo) Pascal
  • Modula
  • C
  • C++
  • Java
  • Eiffel
  • Perl
  • Ruby
  • Javascript
  • Python
  • Rust (2016)

Sourcepole

  • Geospatial software: QGIS, QGIS Web Client and more
  • Developing in Python, C++, Javascript, Ruby and also Rust:
    • t-rex vector tile server

Rust

Why Rust?

  • Performance
    • no runtime or garbage collector
    • low-level control
  • Reliability
    • Rich type system
    • Ownership model guarantees memory-safety and thread-safety
  • Productivity
    • Great documentation and tooling
    • Friendly compiler

History

  • Originally developed at Mozilla
  • Servo browser engine
  • 2015: Version 1.0
  • 2021: The Rust Foundation

Rust Language

Hello World

Variables

  • Type inference
  • Immutable by default

Mutable variable

Data types

  • u8, u16, u32, u64
  • i8, i16, i32, i64
  • f32, f64
  • usize, isize
  • bool
  • Characters, Tuples, Arrays

Functions

Control Flow

if Expressions

while Expressions

for loop

Structs

Methods

Enums

Enums with data

match control flow operator

if let

Generic data types

Option

Traits

Closures

More

  • Modules
  • Multi-threading
  • async/await
  • Error handling with Result type
  • unsafe
  • Efficient C bindings
  • Macros

Derive-Macros

Standard library

  • Primitive types
  • String, Arc, Mutex, …
  • Container and collections
    • (Vec, HashMap, Iterator, …)
  • I/O: Files, UDP/TCP
  • Multithreading
  • Macros: println, assert, …

Tooling

Testing & Documentation

  • Built-in Testing
  • Benchmark tests
  • Built-in documentation generator

https://docs.rs/

Cargo package manager

  • Manage dependencies
  • Format code
  • Compile code
  • Run application
  • Run tests
  • Create documentation
  • Create packages for publishing
  • Extensible

https://crates.io

Geospatial Rust

Geospatial primitives and algorithms

  • Geo - Geospatial primitives such as Point & LineString, and algorithms such as distance, convex hull, centroidcalculations.
  • spade - Spatial datastructures like r-trees and delaunay triangulations for Rust.
  • geographiclib-rs - A port of geographiclib (geodesic calculations).

Geospatial primitives and algorithms (bindings)

  • GEOS - Bindings for the Geometry Engine - Open Source (GEOS) library.
  • PROJ - Bindings for the PROJ library for coordinate transformation and projections.

Handling GIS data formats

  • GeoZero - Zero-Copy reading and writing of geospatial data.
  • GeoJSON - Work with GeoJSON files.
  • GeoTIFF - Work with GeoTIFF raster files.
  • image-tiff - TIFF decoding and encoding library in pure Rust.
  • FlatGeobuf - A performant binary encoding for geographic data based on flatbuffers.
  • las-rs - Read and write ASPRS las files.

Handling GIS data formats (bindings)

  • GDAL - Bindings for the Geographic Data Abstraction Library (GDAL) for reading and writing raster and vector GIS files.

More crates

More topics:

  • Raster and image processing
  • Routing
  • 3D (Meshes, TINs)
  • Geocoding
  • Map rendering

Applications

  • t-rex - Vector tile server specialized on publishing MVT tiles from your own data
  • Martin - Blazing fast and lightweight PostGIS vector tiles server
  • WhiteboxTools - Geospatial data analysis platform with more than 445 tools for processing various types of geospatial data.
  • A/B Street - A traffic simulation game exploring how small changes to roads affect cyclists, transit users, pedestrians, and drivers.

Awesome Geo Rust

https://github.com/pka/awesome-georust

Community

Learning Rust

Where to start

Thank you!

@implgeo