### Get Fractional Grid Indices with DTEDData::get_indices Source: https://context7.com/arpadav/dted2/llms.txt Use `get_indices` to find the fractional grid position for a given latitude and longitude. Returns `None` if the coordinates are out of bounds. This is useful for custom interpolation or direct access to raw data. ```rust use dted2::DTEDData; fn main() { let data = DTEDData::read("tests/test_data.dt2").unwrap(); // In-bounds query if let Some((lat_idx, lon_idx)) = data.get_indices(42.52_f64, 15.75_f64) { println!("Grid index: lat={:.4}, lon={:.4}", lat_idx, lon_idx); // Access the raw elevation record at the integer index let lon_int = lon_idx as usize; let lat_int = lat_idx as usize; println!("Raw elevation sample: {} m", data.data[lon_int].elevations[lat_int]); } // Out-of-bounds returns None assert!(data.get_indices(0.0_f64, 0.0_f64).is_none()); } ``` -------------------------------- ### Use Nom Tag with Recognition Sentinel Source: https://context7.com/arpadav/dted2/llms.txt Shows how to use the `nom::bytes::complete::tag` function with `RecognitionSentinel` values to detect specific record boundaries in byte slices. ```rust fn is_uhl(input: &[u8]) -> nom::IResult<&[u8], ()> { let (input, _) = tag(RecognitionSentinel::UHL.value())(input)?; Ok((input, ())); } assert!(is_uhl(b"DSIUsomething").is_err()); assert!(is_uhl(b"UHL1rest").is_ok()); ``` -------------------------------- ### Read DTED File and Metadata in Rust Source: https://github.com/arpadav/dted2/blob/main/README.md Demonstrates how to read a DTED file and its metadata using the DTEDData struct. It also shows how to read only the header information. Ensure the file path is correct and the file exists. ```rust use dted2::{ DTEDData, DTEDMetadata }; let data = DTEDData::read("dted_file.dt2").unwrap(); let metadata: DTEDMetadata = data.metadata; // or can read just the header without the rest of the data let metadata: DTEDMetadata = DTEDData::read_header("dted_file.dt2").unwrap(); ``` -------------------------------- ### Parser Utilities Source: https://context7.com/arpadav/dted2/llms.txt Provides low-level nom-based binary parsers for DTED data. These functions are useful for custom parsing pipelines or extending the library's capabilities. ```APIDOC ## Parser utilities — Low-level nom-based binary parsers Public parser functions built with `nom` for byte-level DTED binary parsing. Useful for custom parsing pipelines or extending the library. ```rust use dted2::parsers::{ to_uint, uint_parser, uint_parser_with_default, to_angle, angle_parser, to_nan, nan_parser, to_i16, signed_mag_parser, dted_uhl_parser, }; use dted2::primitives::Angle; fn main() { // Parse ASCII byte slice to unsigned integer assert_eq!(to_uint::(b"4321"), Some(4321_u32)); // nom parser: consume exactly N bytes as unsigned integer let (rest, val) = uint_parser::(3)(b"12345").unwrap(); assert_eq!(val, 123_u16); assert_eq!(rest, b"45"); // nom parser with default: return default when count == 0 let (_, val) = uint_parser_with_default::(0, 99)(b"ignored").unwrap(); assert_eq!(val, 99); // Parse DMS angle bytes with optional N/S/E/W suffix let (_, angle) = to_angle(b"12345W", 3, 1, 1).unwrap(); assert_eq!(angle, Angle::new(123, 4, 5.0, true)); // West => negative // Parse DTED NAN ("NA") sentinel or return numeric value let (_, maybe_val) = nan_parser::(4)(b"NA$$").unwrap(); assert_eq!(maybe_val, None); // NaN sentinel detected let (_, maybe_val) = nan_parser::(4)(b"1234extra").unwrap(); assert_eq!(maybe_val, Some(1234_u32)); // Signed magnitude i16 (DTED elevation format) assert_eq!(to_i16(0x0003), 3); assert_eq!(to_i16(0x8003), -3); // sign bit set => negative assert_eq!(to_i16(0xFFFF), -32767); let (_, elev) = signed_mag_parser(&[0x80, 0x03]).unwrap(); assert_eq!(elev, -3_i16); // Parse a full UHL header from raw bytes let raw = b"UHL11234556E8901234W123456789012UUUXXXXXXXXXXXX123445670XXXXXXXXXXXXXXXXXXXXXXXX"; let (_, header) = dted_uhl_parser(raw).unwrap(); assert_eq!(header.count.lat, 4567); assert_eq!(header.count.lon, 1234); } ``` ``` -------------------------------- ### Nom Parser for Unsigned Integers with Default Source: https://context7.com/arpadav/dted2/llms.txt A nom parser that parses unsigned integers. If the byte count is 0, it returns a default value instead of failing. ```rust let (_, val) = uint_parser_with_default::(0, 99)(b"ignored").unwrap(); assert_eq!(val, 99); ``` -------------------------------- ### Read Only DTED Header for Metadata Source: https://context7.com/arpadav/dted2/llms.txt Parses only the User Header Label (UHL) record to retrieve metadata without loading elevation data. Ideal for quickly cataloging or validating multiple files. ```rust use dted2::{DTEDData, DTEDMetadata}; fn print_file_info(path: &str) { match DTEDData::read_header(path) { Ok(meta) => { println!("File: {}", meta.filename); println!("Origin: lat={:.4}°, lon={:.4}°", f64::from(meta.origin_angle.lat), f64::from(meta.origin_angle.lon)); println!("Grid: {}×{}", meta.count.lat, meta.count.lon); println!("Interval: {} arcsec", meta.interval_secs.lat); } Err(e) => eprintln!("Failed to read header for {path}: {e:?}"), } } fn main() { // Quickly scan multiple DTED files without loading elevation data for path in ["region_a.dt2", "region_b.dt1", "region_c.dt0"] { print_file_info(path); } } ``` -------------------------------- ### Access DTED Record Sentinel Values Source: https://context7.com/arpadav/dted2/llms.txt Demonstrates accessing the byte values for various DTED record recognition sentinels using the `RecognitionSentinel` enum. ```rust assert_eq!(RecognitionSentinel::UHL.value(), b"UHL1"); assert_eq!(RecognitionSentinel::DSI.value(), b"DSIU"); assert_eq!(RecognitionSentinel::ACC.value(), b"ACC"); assert_eq!(RecognitionSentinel::DATA.value(), &[0xAA]); assert_eq!(RecognitionSentinel::NA.value(), b"NA"); ``` -------------------------------- ### Query Elevation at Specific Lat/Lon Source: https://context7.com/arpadav/dted2/llms.txt Retrieves bilinearly interpolated elevation in meters for a given latitude and longitude. Returns None if the point is outside the file's bounds. Supports any type convertible to f64 for coordinates. ```rust use dted2::DTEDData; fn main() { let data = DTEDData::read("tests/test_data.dt2").unwrap(); // Query an in-bounds point if let Some(elev) = data.get_elevation(42.52_f64, 15.75_f64) { println!("Elevation at (42.52°N, 15.75°E): {:.1} m", elev); } // Query returns None when out of bounds assert!(data.get_elevation(0.0_f64, 0.0_f64).is_none()); // Batch elevation profile along a transect let lats: Vec = (0..=10).map(|i| 42.0 + i as f64 * 0.1).collect(); let lon = 15.5_f64; for lat in &lats { match data.get_elevation(*lat, lon) { Some(e) => println!(" ({:.1}, {:.1}) => {:.1} m", lat, lon, e), None => println!(" ({:.1}, {:.1}) => out of bounds", lat, lon), } } } ``` -------------------------------- ### Nom Parser for Signed Magnitude i16 Source: https://context7.com/arpadav/dted2/llms.txt A nom parser for the signed magnitude i16 format used in DTED elevation data. It parses a byte slice and returns the remaining input and the i16 value. ```rust let (_, elev) = signed_mag_parser(&[0x80, 0x03]).unwrap(); assert_eq!(elev, -3_i16); ``` -------------------------------- ### Read Complete DTED File and Inspect Metadata Source: https://context7.com/arpadav/dted2/llms.txt Reads the entire DTED file, including elevation data, into a DTEDData struct. Useful for full data access and analysis. Includes error handling for IO and parse failures. ```rust use dted2::{DTEDData, DTEDMetadata}; fn main() { // Read the full DTED file including all elevation data let data: DTEDData = DTEDData::read("path/to/terrain.dt2").unwrap(); // Inspect metadata let meta: &DTEDMetadata = &data.metadata; println!("File: {}", meta.filename); println!("Origin lat: {}°", f64::from(meta.origin_angle.lat)); println!("Origin lon: {}°", f64::from(meta.origin_angle.lon)); println!("Interval lat: {} arcsec", meta.interval_secs.lat); println!("Interval lon: {} arcsec", meta.interval_secs.lon); println!("Grid size: {} x {} points", meta.count.lat, meta.count.lon); println!("Accuracy: {:?} m", meta.accuracy); // Bounding box println!("Min lat/lon: {:.6}, {:.6}", data.min.lat, data.min.lon); println!("Max lat/lon: {:.6}, {:.6}", data.max.lat, data.max.lon); // Error handling example match DTEDData::read("nonexistent.dt2") { Ok(_) => println!("Unexpected success"), Err(dted2::Error::Io(e)) => eprintln!("IO error: {e}"), Err(dted2::Error::ParseError(msg)) => eprintln!("Parse error: {msg}"), } } ``` -------------------------------- ### Nom Parser for Unsigned Integers Source: https://context7.com/arpadav/dted2/llms.txt A nom parser that consumes a specified number of bytes and parses them as an unsigned integer. It returns the remaining input and the parsed value. ```rust let (rest, val) = uint_parser::(3)(b"12345").unwrap(); assert_eq!(val, 123_u16); assert_eq!(rest, b"45"); ``` -------------------------------- ### Parse Full DTED UHL Header Source: https://context7.com/arpadav/dted2/llms.txt Parses a complete DTED UHL (User Header) record from raw bytes using the `dted_uhl_parser`. Asserts specific fields from the parsed header. ```rust let raw = b"UHL11234556E8901234W123456789012UUUXXXXXXXXXXXX123445670XXXXXXXXXXXXXXXXXXXXXXXX"; let (_, header) = dted_uhl_parser(raw).unwrap(); assert_eq!(header.count.lat, 4567); assert_eq!(header.count.lon, 1234); ``` -------------------------------- ### Recognition Sentinel Constants Source: https://context7.com/arpadav/dted2/llms.txt Provides compile-time enum constants for DTED record sentinel byte sequences, useful for identifying record boundaries. ```APIDOC ## `RecognitionSentinel` — DTED record sentinel constants A compile-time enum providing the binary sentinel byte sequences used to identify DTED record boundaries (`UHL1`, `DSIU`, `ACC`, `0xAA` data sentinel). ```rust use nom::bytes::complete::tag; use dted2::dted::RecognitionSentinel; fn main() { // Access sentinel byte values assert_eq!(RecognitionSentinel::UHL.value(), b"UHL1"); assert_eq!(RecognitionSentinel::DSI.value(), b"DSIU"); assert_eq!(RecognitionSentinel::ACC.value(), b"ACC"); assert_eq!(RecognitionSentinel::DATA.value(), &[0xAA]); assert_eq!(RecognitionSentinel::NA.value(), b"NA"); // Use with nom to detect UHL record start fn is_uhl(input: &[u8]) -> nom::IResult<&[u8], ()> { let (input, _) = tag(RecognitionSentinel::UHL.value())(input)?; Ok((input, ())) } assert!(is_uhl(b"DSIUsomething").is_err()); assert!(is_uhl(b"UHL1rest").is_ok()); } ``` ``` -------------------------------- ### Angle: Geographic Angle in Degrees/Minutes/Seconds Source: https://context7.com/arpadav/dted2/llms.txt The `Angle` type represents geographic angles precisely in DMS format. It supports construction from seconds, arithmetic operations, and conversions to various numeric types. Note that negative zero is considered equal to positive zero. ```rust use dted2::primitives::Angle; fn main() { // Construct from DMS components let pos = Angle::new(42, 30, 15.0, false); // 42°30'15"N let neg = Angle::new(15, 45, 0.0, true); // 15°45'00"W println!("Positive: {}° {}' {}\"", pos.deg(), pos.min(), pos.sec()); println!("Negative: {} (is_negative={})", pos.total_secs(), neg.is_negative()); // Convert total arc-seconds to Angle and back let from_secs = Angle::from_secs(445543.8); assert_eq!(from_secs.total_secs(), 445543.8); // Convert to decimal degrees (f64) let decimal: f64 = pos.into(); println!("Decimal degrees: {:.6}", decimal); // 42.504167 // Arithmetic (all ops work in arc-second space) let a = Angle::new(0, 1, 0.0, false); // 60 arcsec let b = Angle::new(0, 0, 30.0, false); // 30 arcsec let sum = a + b; // 90 arcsec = 0°1'30" assert_eq!(sum.total_secs(), 90.0); // Negative zero is equal to positive zero assert_eq!(Angle::new(0, 0, 0.0, false), Angle::new(0, 0, 0.0, true)); } ``` -------------------------------- ### Load Elevation Data with Error Handling Source: https://context7.com/arpadav/dted2/llms.txt A function that loads DTED elevation data and handles potential `dted2::Error` variants, including `Io` and `ParseError`. It returns a `Result` to propagate errors. ```rust use dted2::{DTEDData, Error}; fn load_elevation(path: &str, lat: f64, lon: f64) -> Result { let data = DTEDData::read(path)?; data.get_elevation(lat, lon).ok_or_else(|| Error::ParseError( format!("Coordinates ({lat}, {lon}) are outside the file bounds") )) } ``` ```rust match load_elevation("terrain.dt2", 42.5, 15.7) { Ok(elev) => println!("Elevation: {{:.1}} m", elev), Err(Error::Io(e)) => eprintln!("IO error: {{e}}"), Err(Error::ParseError(msg)) => eprintln!("Error: {{msg}}"), } ``` -------------------------------- ### Query Elevation from DTED Data in Rust Source: https://github.com/arpadav/dted2/blob/main/README.md Shows how to retrieve elevation data for a specific geographic coordinate from a loaded DTEDData object. Returns None if the coordinates are out of bounds. Requires a valid DTEDData instance. ```rust // query elevation, returns None if out of bounds let elevation: f64 = data.get_elevation(50.0, 10.0).unwrap(); ``` -------------------------------- ### Parse ASCII Bytes to Unsigned Integer Source: https://context7.com/arpadav/dted2/llms.txt Converts an ASCII byte slice to an unsigned integer. This is a utility function for direct conversion. ```rust assert_eq!(to_uint::(b"4321"), Some(4321_u32)); ``` -------------------------------- ### Convert Signed Magnitude i16 Source: https://context7.com/arpadav/dted2/llms.txt Converts a two-byte signed magnitude representation to an i16 integer. The most significant bit indicates the sign. ```rust assert_eq!(to_i16(0x0003), 3); ``` ```rust assert_eq!(to_i16(0x8003), -3); // sign bit set => negative ``` ```rust assert_eq!(to_i16(0xFFFF), -32767); ``` -------------------------------- ### Angle Source: https://context7.com/arpadav/dted2/llms.txt Represents a geographic angle in Degrees, Minutes, Seconds (DMS) format. This type is used for precise coordinate representation within the library and supports various conversions and arithmetic operations. ```APIDOC ## `Angle` — Geographic angle in degrees/minutes/seconds A precise DMS (degrees, minutes, seconds) angle type used throughout the library for DTED origin coordinates. Supports construction from seconds, arithmetic operators, and conversion to `f64`/`f32`/`i16`/`i32`/`i64` via `From`. ### Methods - `new(degrees: u16, minutes: u8, seconds: f32, is_negative: bool) -> Angle` Constructs an `Angle` from degrees, minutes, seconds, and a boolean indicating if the angle is negative. - `deg(&self) -> u16` Returns the degrees component of the angle. - `min(&self) -> u8` Returns the minutes component of the angle. - `sec(&self) -> f32` Returns the seconds component of the angle. - `is_negative(&self) -> bool` Returns `true` if the angle is negative, `false` otherwise. - `total_secs(&self) -> f64` Returns the total angle in arc-seconds. ### Static Methods - `from_secs(secs: f64) -> Angle` Constructs an `Angle` from a total number of arc-seconds. ### Conversions - `Into` - `Into` - `Into` - `Into` - `Into` Converts the `Angle` to various numeric types representing decimal degrees. ### Arithmetic Operators Supports standard arithmetic operators (`+`, `-`, `*`, `/`) which operate on the total arc-seconds. ### Example ```rust use dted2::primitives::Angle; // Construct from DMS components let pos = Angle::new(42, 30, 15.0, false); // 42°30'15"N let neg = Angle::new(15, 45, 0.0, true); // 15°45'00"W // Convert to decimal degrees (f64) let decimal: f64 = pos.into(); println!("Decimal degrees: {:.6}", decimal); // 42.504167 // Arithmetic let a = Angle::new(0, 1, 0.0, false); // 60 arcsec let b = Angle::new(0, 0, 30.0, false); // 30 arcsec let sum = a + b; // 90 arcsec = 0°1'30" assert_eq!(sum.total_secs(), 90.0); ``` ``` -------------------------------- ### DTEDData::read_header Source: https://context7.com/arpadav/dted2/llms.txt Parses only the User Header Label (UHL) record of a DTED file, returning DTEDMetadata without loading elevation data. Useful for quick file inspection. ```APIDOC ## DTEDData::read_header ### Description Parses only the 80-byte User Header Label (UHL) record, returning `DTEDMetadata` without loading the full elevation matrix into memory. Ideal for cataloguing or bounds-checking many files. ### Method `DTEDData::read_header(path: &str)` ### Parameters #### Path Parameters - **path** (string) - Required - The file path to the DTED file. ### Request Example ```rust use dted2::DTEDMetadata; let meta: DTEDMetadata = DTEDData::read_header("path/to/terrain.dt2").unwrap(); ``` ### Response #### Success Response - **DTEDMetadata** - A struct containing metadata about the DTED file, such as origin, grid size, and interval. #### Error Response - **dted2::Error** - If an IO error occurs or if the header cannot be parsed. ### Response Example (Success) ```rust fn print_file_info(path: &str) { match DTEDData::read_header(path) { Ok(meta) => { println!("File: {}", meta.filename); println!("Origin: lat={:.4}°, lon={:.4}°", f64::from(meta.origin_angle.lat), f64::from(meta.origin_angle.lon)); println!("Grid: {}×{}", meta.count.lat, meta.count.lon); println!("Interval: {} arcsec", meta.interval_secs.lat); } Err(e) => eprintln!("Failed to read header for {path}: {e:?}"), } } ``` ``` -------------------------------- ### Parse DMS Angle Bytes Source: https://context7.com/arpadav/dted2/llms.txt Parses Direction, Speed, and Magnitude (DMS) angle bytes, handling optional N/S/E/W suffixes. West is treated as negative. ```rust let (_, angle) = to_angle(b"12345W", 3, 1, 1).unwrap(); assert_eq!(angle, Angle::new(123, 4, 5.0, true)); // West => negative ``` -------------------------------- ### DTEDData::read Source: https://context7.com/arpadav/dted2/llms.txt Reads and parses an entire DTED file, including header and all elevation records, into a DTEDData struct. Handles IO and parsing errors. ```APIDOC ## DTEDData::read ### Description Reads and parses an entire DTED file (header + all elevation records) into a `DTEDData` struct. Returns `Err(dted2::Error)` on IO failure or parse error. ### Method `DTEDData::read(path: &str)` ### Parameters #### Path Parameters - **path** (string) - Required - The file path to the DTED file. ### Request Example ```rust use dted2::DTEDData; let data: DTEDData = DTEDData::read("path/to/terrain.dt2").unwrap(); ``` ### Response #### Success Response - **DTEDData** - A struct containing the parsed DTED file data, including metadata and elevation records. #### Error Response - **dted2::Error::Io** - If an IO error occurs during file reading. - **dted2::Error::ParseError** - If the file content cannot be parsed according to DTED format. ### Response Example (Success) ```rust // Accessing metadata from the parsed data let meta = &data.metadata; println!("File: {}", meta.filename); println!("Origin lat: {}°", f64::from(meta.origin_angle.lat)); // Accessing bounding box information println!("Min lat/lon: {:.6}, {:.6}", data.min.lat, data.min.lon); println!("Max lat/lon: {:.6}, {:.6}", data.max.lat, data.max.lon); ``` ### Response Example (Error Handling) ```rust match DTEDData::read("nonexistent.dt2") { Ok(_) => println!("Unexpected success"), Err(dted2::Error::Io(e)) => eprintln!("IO error: {e}"), Err(dted2::Error::ParseError(msg)) => eprintln!("Parse error: {msg}"), } ``` ``` -------------------------------- ### Error Handling Source: https://context7.com/arpadav/dted2/llms.txt Details the `dted2::Error` enum used for handling I/O and parsing errors in fallible public APIs. ```APIDOC ## Error handling — `dted2::Error` All fallible public APIs return `Result`. The error enum has two variants: `Io` (wrapping `std::io::Error`) and `ParseError` (a descriptive string from nom). ```rust use dted2::{DTEDData, Error}; fn load_elevation(path: &str, lat: f64, lon: f64) -> Result { let data = DTEDData::read(path)?; data.get_elevation(lat, lon).ok_or_else(|| Error::ParseError( format!("Coordinates ({lat}, {lon}) are outside the file bounds") )) } fn main() { match load_elevation("terrain.dt2", 42.5, 15.7) { Ok(elev) => println!("Elevation: {:.1} m", elev), Err(Error::Io(e)) => eprintln!("IO error: {e}"), Err(Error::ParseError(msg)) => eprintln!("Error: {msg}"), } } ``` ``` -------------------------------- ### Parse DTED NAN Sentinel Source: https://context7.com/arpadav/dted2/llms.txt Parses a byte sequence, detecting the DTED NAN ('NA') sentinel or returning a numeric value if present. Requires specifying the number of bytes to consider. ```rust let (_, maybe_val) = nan_parser::(4)(b"NA$$").unwrap(); assert_eq!(maybe_val, None); // NaN sentinel detected ``` ```rust let (_, maybe_val) = nan_parser::(4)(b"1234extra").unwrap(); assert_eq!(maybe_val, Some(1234_u32)); ``` -------------------------------- ### AxisElement: Paired Latitude/Longitude Container Source: https://context7.com/arpadav/dted2/llms.txt The generic `AxisElement` holds paired latitude and longitude values of type `T`. It supports arithmetic operations with scalars and other `AxisElement` instances. This type is used for origins, intervals, counts, and bounding boxes. ```rust use dted2::primitives::{AxisElement, Angle}; fn main() { // Numeric AxisElement let origin = AxisElement::new(-10.0_f64, 20.0_f64); let offset = AxisElement::new(5.0_f64, 3.0_f64); let shifted = origin + offset; assert_eq!(shifted, AxisElement::new(-5.0, 23.0)); // Scalar arithmetic let scaled = AxisElement::new(2.0_f64, 4.0_f64) * 3.0_f64; // scaled: AxisElement { lat: 6.0, lon: 12.0 } // Angle-based AxisElement (used in DTEDMetadata.origin_angle) let a = AxisElement::new(Angle::new(3, 2, 59.0, false), Angle::new(0, 0, 0.0, false)); let b = AxisElement::new(Angle::new(0, 1, 1.0, true), Angle::new(0, 2, 0.0, true)); let c = a + b; assert_eq!(c, AxisElement::new( Angle::new(3, 1, 58.0, false), Angle::new(0, 2, 0.0, true) )); // Convert AxisElement to AxisElement let angle_pair = AxisElement::new(Angle::new(42, 0, 0.0, false), Angle::new(15, 0, 0.0, false)); let float_pair: AxisElement = angle_pair.into(); println!("lat={:.4}, lon={:.4}", float_pair.lat, float_pair.lon); // 42.0000, 15.0000 } ``` -------------------------------- ### AxisElement Source: https://context7.com/arpadav/dted2/llms.txt A generic container for paired latitude and longitude values of the same type `T`. It is used for various fields like origin, interval, count, and bounding boxes, and supports arithmetic operations. ```APIDOC ## `AxisElement` — Paired lat/lon value container A generic container holding paired `lat` and `lon` values of the same type `T`. Used throughout the library for origin, interval, count, and bounding box fields. Supports full arithmetic with scalars and other `AxisElement` instances. ### Methods - `new(lat: T, lon: T) -> AxisElement` Constructs a new `AxisElement` with the given latitude and longitude values. ### Arithmetic Operators Supports standard arithmetic operators (`+`, `-`, `*`, `/`) for both scalar values and other `AxisElement` instances of the same type `T`. ### Conversions - `Into>` (when `T` is `Angle`) Converts an `AxisElement` containing `Angle` types to an `AxisElement` containing `f64` (decimal degrees). ### Example ```rust use dted2::primitives::{AxisElement, Angle}; // Numeric AxisElement let origin = AxisElement::new(-10.0_f64, 20.0_f64); let offset = AxisElement::new(5.0_f64, 3.0_f64); let shifted = origin + offset; assert_eq!(shifted, AxisElement::new(-5.0, 23.0)); // Scalar arithmetic let scaled = AxisElement::new(2.0_f64, 4.0_f64) * 3.0_f64; // scaled: AxisElement { lat: 6.0, lon: 12.0 } // Angle-based AxisElement let angle_pair = AxisElement::new(Angle::new(42, 0, 0.0, false), Angle::new(15, 0, 0.0, false)); let float_pair: AxisElement = angle_pair.into(); println!("lat={:.4}, lon={:.4}", float_pair.lat, float_pair.lon); // 42.0000, 15.0000 ``` ``` -------------------------------- ### DTEDData::get_indices Source: https://context7.com/arpadav/dted2/llms.txt Retrieves the fractional grid indices (latitude and longitude) for a given geographic coordinate. This is useful for custom interpolation or direct access to the raw elevation data. Returns `None` if the coordinate is outside the bounds of the elevation grid. ```APIDOC ## `DTEDData::get_indices` — Get fractional grid indices for a coordinate Returns the `(lat_index, lon_index)` fractional position within the elevation grid for a given lat/lon pair, or `None` if out of bounds. Useful for custom interpolation or when directly accessing the raw `data` field. ### Method Signature `fn get_indices(&self, latitude: f64, longitude: f64) -> Option<(f64, f64)>` ### Parameters - **latitude** (f64) - The latitude coordinate. - **longitude** (f64) - The longitude coordinate. ### Returns - `Some((f64, f64))` - A tuple containing the fractional latitude and longitude indices if the coordinate is within bounds. - `None` - If the coordinate is out of bounds. ### Example ```rust use dted2::DTEDData; let data = DTEDData::read("tests/test_data.dt2").unwrap(); // In-bounds query if let Some((lat_idx, lon_idx)) = data.get_indices(42.52_f64, 15.75_f64) { println!("Grid index: lat={:.4}, lon={:.4}", lat_idx, lon_idx); } // Out-of-bounds returns None assert!(data.get_indices(0.0_f64, 0.0_f64).is_none()); ``` ``` -------------------------------- ### DTEDData::get_elevation Source: https://context7.com/arpadav/dted2/llms.txt Queries the bilinearly interpolated elevation at a specific latitude and longitude. Returns None if the point is outside the file's bounds. ```APIDOC ## DTEDData::get_elevation ### Description Returns the bilinearly interpolated terrain elevation (in meters) at the given latitude and longitude, or `None` if the point is outside the file's bounding box. Accepts any type that implements `Into`. ### Method `DTEDData::get_elevation(lat: impl Into, lon: impl Into) -> Option` ### Parameters #### Path Parameters - **lat** (any type implementing `Into`) - Required - The latitude of the query point. - **lon** (any type implementing `Into`) - Required - The longitude of the query point. ### Request Example ```rust let data = DTEDData::read("tests/test_data.dt2").unwrap(); // Query an in-bounds point if let Some(elev) = data.get_elevation(42.52_f64, 15.75_f64) { println!("Elevation at (42.52°N, 15.75°E): {:.1} m", elev); } ``` ### Response #### Success Response - **Option** - Returns `Some(elevation)` in meters if the point is within the file's bounds, otherwise returns `None`. ### Response Example (Out of Bounds) ```rust assert!(data.get_elevation(0.0_f64, 0.0_f64).is_none()); ``` ### Response Example (Elevation Profile) ```rust let lats: Vec = (0..=10).map(|i| 42.0 + i as f64 * 0.1).collect(); let lon = 15.5_f64; for lat in &lats { match data.get_elevation(*lat, lon) { Some(e) => println!(" ({:.1}, {:.1}) => {:.1} m", lat, lon, e), None => println!(" ({:.1}, {:.1}) => out of bounds", lat, lon), } } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.