Crate libisg

Source
Expand description

Library that reading/writing ISG-format.

use std::fs;

use libisg;
use libisg::{Data, DataBounds, ISG};


let s = fs::read_to_string("Example 1.isg").unwrap();

let isg = libisg::from_str(&s).unwrap();

// use data
let (a_max, b_max, delta_a, delta_b) = match isg.header.data_bounds {
    DataBounds::GridGeodetic { lat_max, lon_max, delta_lat, delta_lon, .. } => {
        (lat_max, lon_max, delta_lat, delta_lon)
    },
    _ => unimplemented!("`Example 1.isg` is grid geodetic"),
};

match &isg.data {
    Data::Grid(data) => {
        for (nrow, row) in data.iter().enumerate() {
            for (ncol, value) in row.iter().enumerate() {
                let a = a_max - delta_a * nrow;
                let b = b_max + delta_b * ncol;
                // do something
            }
        }
    }
    Data::Sparse(data) => {
        for row in data {
            let (a, b, value) = row;
            // do something
        }
    }
}

§Serialize/Deserialize

§ISG format

Use from_str and to_string fns.

use std::fs;
use libisg;


let s = fs::read_to_string("Example 1.isg").unwrap();

// deserialize
let isg = libisg::from_str(&s).unwrap();

// serialize
assert_eq!(s, libisg::to_string(&isg));

§serde

ISG supports serde protocol.

use std::fs;
use serde_json;
use libisg;


let s = fs::read_to_string("Example 1.isg").unwrap();
let isg = libisg::from_str(&s).unwrap();

// serialize
let json = serde_json::to_string(&isg).unwrap();

// deserialize
assert_eq!(isg, serde_json::from_str(&json).unwrap());

§Notes

  • libisg’s support of arithmetic on Coord is very minimal/basic, consider to use other crates

Structs§

CreationDate
Value of creation date
Header
Header section of ISG.
ISG
ISG format.
ParseError
Error on parsing ISG format
ParseValueError
Error on parsing header value of ISG format
ValidationError
Error on validation

Enums§

Coord
Represents Coordinate
CoordType
Value of coord type
CoordUnits
Value of coord units
Data
Data section of ISG.
DataBounds
Bounds and delta (lat min etc.)
DataFormat
Value of data format
DataOrdering
Value of data ordering
DataType
Value of data type
DataUnits
Value of data units
ModelType
Value of model type
TideSystem
Value of tide system

Functions§

from_str
Deserialize ISG-format.
to_string
Serialize ISG to String.