nitf-rs

Minimal NITF interface

13 releases

0.3.1 Apr 20, 2024
0.3.0 Feb 7, 2024
0.2.4 Feb 2, 2024
0.2.3 Dec 5, 2023
0.1.8 Jul 7, 2023

42 downloads per month
Used in 2 crates

MIT license

115KB
2.5K SLoC

nitf-rs

A minimal rust NITF file interface

For basic examples of reading and writing, see the examples

If you have questions, would like to contribute, or would like something added, please open an issue.

Note:

Formerly, there was Sicd functionality built into this crate. That has been moved into a separate crate sicd-rs


lib.rs:

Minimal Crate for reading and manipulating NITF files Interface for NITF version 2.1

Constructing a [Nitf] object parses the file header and segment metadata. Each segment in contains a header field which stores the respective metadata defined in the file standard. The primary function for constructing a [Nitf] is [Nitf::from_reader()]

// Read a nitf file and dump metadata to stdout
let mut nitf_file = std::fs::File::open("example.nitf").unwrap();
let nitf = nitf_rs::Nitf::from_reader(&mut nitf_file).unwrap();
println!("{nitf}");

Aside from the nitf_header, all other segments use a generic [NitfSegment] to provide metadata and access to the segment data.

// Get the bytes from the first image segment
let mut nitf_file = std::fs::File::open("example.nitf").unwrap();
let nitf = nitf_rs::Nitf::from_reader(&mut nitf_file).unwrap();
let im_seg = &nitf.image_segments[0];
let im_seg_hdr = &im_seg.header;
let im_seg_data = &im_seg.get_data_map(&mut nitf_file).unwrap();

Most metadata elements are stored in a NitfField structure. This structure has a val which holds on to native value of the field (i.e., the bytes parsed into a u8, u16, String, enum, etc.), as well as the length (in bytes) and name of the field.

let mut nitf_file = std::fs::File::open("example.nitf").unwrap();
let nitf = nitf_rs::Nitf::from_reader(&mut nitf_file).unwrap();
let file_title = nitf.nitf_header.ftitle.val;
let n_img_segments = nitf.nitf_header.numi.val;
let n_rows = nitf.image_segments[0].header.nrows.val;

If there is user-defined tagged-record-extension (TRE) data within a segment, it is stored in an [ExtendedSubheader] for the user to parse accordingly.

Dependencies

~0.4–1MB
~22K SLoC