#fixtures #raster #gis #command-line-tool #geotiff

bin+lib rasterfakers

A Rust library and CLI tool to generate fake GeoTIFF files for testing and fixtures

3 unstable releases

0.2.0 Oct 28, 2024
0.1.1 Oct 24, 2024
0.1.0 Oct 3, 2024

#214 in Testing

MIT license

51KB
400 lines

RasterFakeRS

A Rust library and CLI tool for generating fake GeoTIFF files. Perfect for testing GIS applications, creating fixtures, and generating sample raster data.

Features

  • Generate GeoTIFF files with customizable dimensions, bands, and data types
  • Support for COG creation
  • Multiple built-in data patterns (gradient, sine wave, noise)
  • Support for custom data generation patterns
  • Configurable parameters (projection, transform)
  • Available as both a library and CLI tool
  • Supports various data types (u8, u16, i16, u32, i32, f32, f64)

Installation

As a Library

Add this to your Cargo.toml:

[dependencies]
rasterfakers = "0.2.0"

As a CLI Tool

cargo install rasterfakers --force

Note: RasterFakers depends on the GDAL library. Please ensure GDAL is installed on your system.

Usage

Library Usage

use rasterfakers::{FakeGeoTiffBuilder, GeoTransform, SineWavePattern};

// Create a Cloud Optimized GeoTIFF with custom settings
let geotiff = FakeGeoTiffBuilder::new()
    .dimensions(256, 256)?
    .bands(3)?
    .projection("EPSG:4326")
    .geotransform(GeoTransform::default())
    .output_path("output_cog.tiff")
    .data_generator(Box::new(SineWavePattern))
    .cloud_optimized(true)
    .build::<f32>()?;

geotiff.write()?;

CLI Usage

# Generate a basic GeoTIFF
rasterfakers -o output.tiff

# Generate a Cloud Optimized GeoTIFF
rasterfakers -o cog_output.tiff --cloud-optimized

# Customize dimensions, data type, and pattern
rasterfakers -o custom_cog.tiff -w 512 -e 512 -t f32 -n sine --cloud-optimized

# Specify projection and resolution
rasterfakers -o projected_cog.tiff -p "EPSG:4326" -r "0.1,0.1" -c "30.0,10.0" --cloud-optimized

CLI Options

Options:
  -o, --output <PATH>                 Output file path
  -w, --width <N>                     Width of the GeoTIFF [default: 256]
  -e, --height <N>                    Height of the GeoTIFF [default: 256]
  -b, --bands <N>                     Number of bands [default: 1]
  -t, --data-type <TYPE>              Data type (u8, u16, i16, u32, i32, f32, f64) [default: f64]
  -p, --projection <PROJ>             Projection (e.g., EPSG:4326) [default: EPSG:4326]
  -r, --pixel-resolution <RES>        Pixel resolution (e.g., "0.25,0.25") [default: "1.0,1.0"]
  -c, --upper-left-corner <COORDS>    Upper-left corner coordinates [default: "0.0,0.0"]
  -n, --pattern <PATTERN>             Data pattern (gradient, sine, noise) [default: gradient]
      --cloud-optimized               Generate a Cloud Optimized GeoTIFF
  -h, --help                          Print help
  -V, --version                       Print version

Examples

Check out the examples directory for more detailed usage examples:

  • examples/basic_usage.rs: Simple library usage
  • examples/custom_pattern.rs: Creating custom data patterns
  • examples/cli_examples.sh: Various CLI usage examples

Custom Data Patterns

You can create custom data patterns by implementing the DataGenerator trait:

use rasterfakers::DataGenerator;

struct CustomPattern;

impl DataGenerator for CustomPattern {
    fn generate(&self, x: usize, y: usize, band: usize) -> f64 {
        // Your custom pattern logic here
        (x * y * band) as f64
    }
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Dependencies

~7–10MB
~245K SLoC