From ea2d118ae77111fa04653e4201d2e486ba9e7842 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 23 Nov 2026 16:46:48 -0300 Subject: [PATCH] feat(data): read GRIB2's complex packing (#2428) Data representation templates 5.2 and 5.3: groups of their own widths, missing values, and spatial differencing of order 1 and 2. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- crates/data/src/raster/grib.rs | 130 ++++++++---- crates/data/src/raster/grib/complex.rs | 223 ++++++++++++++++++++ crates/data/src/raster/grib_tests.rs | 269 ++++++++++++++++++++++++- docs/user-guide/data-formats.md | 2 +- docs/user-guide/data.md | 2 +- 6 files changed, 586 insertions(+), 42 deletions(-) create mode 100644 crates/data/src/raster/grib/complex.rs diff --git a/README.md b/README.md index 11cdf893d4..858bcb1c68 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ Every screenshot is RustGIS itself, rendered offscreen by `cargo run -p rustgis- |---|---| | **Data** | GeoJSON, CSV/TSV with x/y columns in other coordinate systems or WKT geometry, Excel and OpenDocument spreadsheets, GeoRSS, LandXML, encoded polylines, Shapefile (zipped too, in the browser as well), GeoPackage, GeoParquet, FlatGeobuf, KML/KMZ (with styles), GPX, GML, MapInfo MIF/MID, OpenStreetMap PBF, TopoJSON, CityJSON, CityGML 1.0–3.0, AutoCAD DXF, dBASE tables, PDF and GeoPDF pages (desktop), LiDAR point clouds (LAS, LAZ, COPC) and geotagged photos (large GeoPackage, GeoParquet and FlatGeobuf files, and Shapefiles on the desktop, are read in place), files by their web address, every vector format GDAL reads when it is installed (desktop), Esri File Geodatabases without GDAL (desktop), enterprise geodatabases on SQL Server through their `.sde` files (desktop), PostGIS, MySQL, MariaDB and SQL Server tables read live (desktop), and SQL queries and DuckDB databases through DuckDB Spatial when DuckDB is installed (desktop); PMTiles archives (by web address, or a file on the desktop) and MBTiles files; GeoJSON, CSV, GeoPackage (also as a table added to an existing file), GeoParquet, Shapefile, FlatGeobuf, KML/KMZ, GPX and WKT out (GeoPackage and FlatGeobuf not from the web app); standalone tables; reusable connections; Reload Data for linked files (desktop); geocoding (Find Place, address tables); a Data Sources pane (favourites, recent, saved services, a library) and an SQL pane (desktop); supported QGIS and GeoLibre projects and layer styles; layer and map files, styles, templates and packages | | **Open data** | STAC search (Planetary Computer assets), NASA Earthdata imagery and granule search (GeoTIFFs added on the desktop), Hugging Face, Overture Maps, Source Cooperative, OpenStreetMap by area, geoBoundaries, CKAN, Socrata and ArcGIS Hub portals; S3 buckets with signed connections and a bucket browser; a Data Cubes pane with a catalog of cubes for the time slider (added on the desktop) | -| **Rasters** | GeoTIFF and cloud-optimised GeoTIFF (any pixel type, tiled or striped, compressed), ASCII grids, GRIB 1 and 2 (simple packing on latitude/longitude grids), SRTM `.hgt` and DTED elevation, Zarr 2 and 3 stores (a variable at a time step, by web address, or folder on the desktop), and JPEG 2000, NetCDF, HDF, ERDAS Imagine and the other rasters GDAL reads when it is installed (desktop); reprojection by EPSG code; Stretch, RGB, Classify, Unique Values, Colormap and Shaded Relief; DRA, band combinations, brightness/contrast/gamma; raster functions, indices, change detection, classification, georeferencing; cloud-optimised GeoTIFF export (desktop); data cubes, point time-series charts (desktop), temporal summaries and trends (Sen's slope, Mann–Kendall); a spectral profile comparing a multiband raster's bands at points | +| **Rasters** | GeoTIFF and cloud-optimised GeoTIFF (any pixel type, tiled or striped, compressed), ASCII grids, GRIB 1 and 2 (simple packing, and GRIB2's complex packing, on latitude/longitude grids), SRTM `.hgt` and DTED elevation, Zarr 2 and 3 stores (a variable at a time step, by web address, or folder on the desktop), and JPEG 2000, NetCDF, HDF, ERDAS Imagine and the other rasters GDAL reads when it is installed (desktop); reprojection by EPSG code; Stretch, RGB, Classify, Unique Values, Colormap and Shaded Relief; DRA, band combinations, brightness/contrast/gamma; raster functions, indices, change detection, classification, georeferencing; cloud-optimised GeoTIFF export (desktop); data cubes, point time-series charts (desktop), temporal summaries and trends (Sen's slope, Mann–Kendall); a spectral profile comparing a multiband raster's bands at points | | **Maps** | Multiple maps and layouts per project, renamed and duplicated from the Browser pane; a GPU renderer (beta) with smooth zoom and pan; tilt, rotation, terrain and a 3D globe; maps of the Moon, Mars and other celestial bodies; each layer kept and drawn in its own coordinate system, picked from PROJ 9.9's catalog by name, method, area or code, with datum grids downloaded on request; Web Mercator or another projection (Equal Earth, Robinson, Winkel Tripel, polar and regional presets, or a [supported](docs/user-guide/maps.md#projections) projected EPSG or ESRI code); a search box for layers, places and coordinates; UTM and MGRS readouts and an MGRS grid; an on-map right-click menu (copy the coordinate, quick buffer, viewshed and line of sight); identify pop-ups with links and pictures; bookmarks, extent history, coordinate navigation; five offline basemaps, with borders in 32 worldviews (31 downloaded when chosen) | | **Web services** | WMS, WMTS, WFS, WCS, OGC API Features and Tiles, and ArcGIS REST (FeatureServer, MapServer, ImageServer, VectorTileServer) from their capabilities; CSW catalogue search; sign-in to ArcGIS Online and Enterprise, basic-auth and API-key logins; WMS and WMTS time on the time slider, legends and GetFeatureInfo | | **Web tiles** | XYZ/TMS/WMS raster tiles, Mapbox Vector Tiles and MapLibre styles (sprites, patterns, expressions), cached and fetched in the background | diff --git a/crates/data/src/raster/grib.rs b/crates/data/src/raster/grib.rs index ddd92ee1c7..b49d5cf68f 100644 --- a/crates/data/src/raster/grib.rs +++ b/crates/data/src/raster/grib.rs @@ -2,19 +2,24 @@ //! without GDAL. Each field is a band. //! //! Read: editions 1 and 2, simple packing (GRIB1's grid point data with simple packing, GRIB2's -//! data representation template 5.0), on a regular latitude/longitude grid (GRIB1 data -//! representation type 0, GRIB2 grid definition template 3.0), in any scanning order, with or -//! without a bitmap. Following WMO's Manual on Codes (WMO-No. 306), Volume I.2, FM 92 GRIB. +//! data representation template 5.0) and GRIB2's complex packing, with or without spatial +//! differencing (5.2 and 5.3), on a regular latitude/longitude grid (GRIB1 data representation +//! type 0, GRIB2 grid definition template 3.0), in any scanning order, with or without a bitmap. +//! Following WMO's Manual on Codes (WMO-No. 306), Volume I.2, FM 92 GRIB. //! -//! Not read yet, and said: complex, JPEG 2000, PNG and the other packings; other grids (Gaussian, -//! rotated, projected, quasi-regular). A message the reader can't read is left out with a notice -//! naming why; a file with nothing it can read is an error naming why. +//! Not read yet, and said: GRIB1's second-order packing, JPEG 2000, PNG, CCSDS and the other +//! packings; other grids (Gaussian, rotated, projected, quasi-regular). A message the reader can't +//! read is left out with a notice naming why; a file with nothing it can read is an error naming +//! why. //! //! The fields on the grid of the first one read are the raster's bands, in file order; fields on //! another grid are left out with a notice. Values are `(R + X × 2^E) / 10^D`, in the units the //! file stores (kelvin stays kelvin), unpacked in `f64`; those `f32` changes are counted in -//! [`Raster::rounded`]. Points a bitmap masks are NaN. Rows are laid out north up, -//! and a grid round the whole globe runs from −180° (as GDAL lays it out). +//! [`Raster::rounded`]. Points a bitmap masks, or complex packing marks missing, are NaN. +//! Rows are laid out north up, and a grid round the whole globe runs from −180° (as GDAL lays it +//! out). + +mod complex; use super::{Crs, Exact, GeoTransform, Raster, Uncounted, max_samples}; use crate::{DataError, Result}; @@ -694,7 +699,8 @@ fn round6(v: f64) -> f64 { (v * 1e6).round() / 1e6 } -/// One field: its band name, grid and values in scanning order (NaN where a bitmap masks). +/// One field: its band name, grid and values in scanning order (NaN where a bitmap masks, or the +/// packing marks them missing). struct Field { name: String, grid: Grid, @@ -780,6 +786,17 @@ fn signed(b: &[u8], o: usize, n: usize) -> i64 { if v & sign != 0 { -(v & (sign - 1)) } else { v } } +/// The `n` bits (at most 32) of `b` from bit `at`, unsigned, big-endian; 0 past the end. +fn bits(b: &[u8], at: u64, n: u32) -> u64 { + if n == 0 { + return 0; + } + // The 8 octets from the value's first: at most 7 bits before it, and its 32 at most. + let byte = (at / 8) as usize; + let word = (0..8).fold(0u64, |w, i| (w << 8) | u64::from(b.get(byte + i).copied().unwrap_or(0))); + (word << (at % 8)) >> (64 - n) +} + /// An IBM System/360 single-precision number (GRIB1's reference value). fn ibm(v: u32) -> f64 { let sign = if v & 0x8000_0000 != 0 { -1.0 } else { 1.0 }; @@ -789,18 +806,19 @@ fn ibm(v: u32) -> f64 { } /// The `points` values of a field in scanning order, written straight into one vector: the -/// `count` values `next` gives (in `f64`), held as `f32`, over the points a bitmap keeps (NaN at -/// the others), or all of them without one. Also how many of them `f32` rounded, and how many -/// are past its range (about ±3.4 × 10^38, `f64`'s too): those have no value (NaN) rather than -/// an infinity. A sidecar's no-data value isn't counted either way ([`Uncounted`]'s rule), and -/// neither is a point of a repeated first column (`grid`'s, which [`to_raster`] doesn't lay out). +/// `count` values `next` gives (in `f64`; a missing one, `None`, is NaN), held as `f32`, over the +/// points a bitmap keeps (NaN at the others), or all of them without one. Also how many of them +/// `f32` rounded, and how many are past its range (about ±3.4 × 10^38, `f64`'s too): those have no +/// value (NaN) rather than an infinity. A sidecar's no-data value isn't counted either way +/// ([`Uncounted`]'s rule), and neither is a point of a repeated first column (`grid`'s, which +/// [`to_raster`] doesn't lay out). /// The values are never held apart from the field, so it costs 4 bytes a point. fn field_values( (points, grid): (usize, &Grid), mask: Option<&[u8]>, count: usize, uncounted: Uncounted, - mut next: impl FnMut() -> f64, + mut next: impl FnMut() -> Option, ) -> std::result::Result<(Vec, u64, u64), Skip> { match mask { None if count != points => return Err(Skip::Damaged("a field whose values don't fill its grid".to_string())), @@ -817,7 +835,10 @@ fn field_values( let kept = mask.is_none_or(|bits| bits.get(k / 8).is_some_and(|b| b & (0x80 >> (k % 8)) != 0)); if kept && left > 0 { left -= 1; - let wide = next(); + let Some(wide) = next() else { + out.push(f32::NAN); + continue; + }; let v = wide as f32; let laid = u64::from(!repeats || grid.place(k).0 < columns); match uncounted.decides(v, || Some(Exact::Float(wide))) { @@ -863,6 +884,37 @@ fn unpack( return Err(Skip::Damaged("a data section shorter than its values".to_string())); } reference(r)?; + let scale = scaling(r, e, d); + let mut bit = 0u64; + field_values(at, mask, count, uncounted, || { + let x = self::bits(data, bit, bits) as f64; + bit += u64::from(bits); + Some(scale(x)) + }) +} + +/// [`unpack`] for complex packing ([`complex`]): `count` values from `data`, some of which it may +/// mark missing. +fn unpack_complex( + data: &[u8], + (count, packing): (usize, complex::Complex), + (r, e, d): (f64, i64, i64), + mask: Option<&[u8]>, + at: (usize, &Grid), + uncounted: Uncounted, +) -> std::result::Result<(Vec, u64, u64), Skip> { + reference(r)?; + let mut values = packing.values(data, count)?; + let scale = scaling(r, e, d); + let field = field_values(at, mask, count, uncounted, || values.next().map(&scale))?; + if values.too_large { + return Err(Skip::Damaged("differences that add up past any packed value".to_string())); + } + Ok(field) +} + +/// What a packed value X stands for, `(R + X × 2^E) / 10^D`. +fn scaling(r: f64, e: i64, d: i64) -> impl Fn(f64) -> f64 { // 2^E and 10^D, where `f64` holds them. Past that (no producer writes such an E or D, but // they are kept), `R + X × 2^E` is divided by [`scaled_by`] where `f64` holds it (so a sum of // 0 stays 0); where it is past `f64` but the division brings it back, the value is made as @@ -871,13 +923,7 @@ fn unpack( let two = (-1000..=1000).contains(&e).then(|| 2f64.powi(e as i32)); let ten = decimal(d); let (base, step) = (scaled_by(r, 0, d), scaled_by(1.0, e, d)); - let mut bit = 0u64; - field_values(at, mask, count, uncounted, || { - // The 8 octets from the value's first: at most 7 bits before it, and its 32 at most. - let byte = (bit / 8) as usize; - let word = (0..8).fold(0u64, |w, i| (w << 8) | u64::from(data.get(byte + i).copied().unwrap_or(0))); - let x = ((word << (bit % 8)) >> (64 - bits)) as f64; - bit += u64::from(bits); + move |x| { // X = 0 is R whatever E is (never 0 × ∞). let sum = if x == 0.0 { r } else { two.map_or(f64::INFINITY, |s| r + x * s) }; let wide = ten.map_or(f64::INFINITY, |ten| sum / ten); @@ -890,7 +936,7 @@ fn unpack( } else { base + x * step } - }) + } } /// 10^`d`, the decimal scale factor's divisor, where `f64` holds it at full precision. @@ -942,7 +988,7 @@ fn constant( reference(r)?; // As in `unpack`: an `R` that isn't 0 divided down to 0 is counted as rounded. let v = decimal(d).map(|ten| r / ten).filter(|v| *v != 0.0 || r == 0.0).unwrap_or_else(|| scaled_by(r, 0, d)); - field_values(at, mask, count, uncounted, || v) + field_values(at, mask, count, uncounted, || Some(v)) } /// `n` bitmap bits set among the first `points`. @@ -1125,7 +1171,7 @@ fn grib2(b: &[u8], room: usize, mut first: Option, uncounted: Uncounted) - let mut reference = String::from("d=?"); let mut grid: Option> = None; let mut product: Option = None; - let mut packing: Option> = None; + let mut packing: Option> = None; let mut bitmap: Option, Skip>> = None; let mut previous_bitmap: Option<&[u8]> = None; let mut held = 0usize; @@ -1190,7 +1236,7 @@ fn grib2(b: &[u8], room: usize, mut first: Option, uncounted: Uncounted) - let field = (|| { let grid = grid.clone().ok_or_else(|| Skip::Damaged("a field without a grid".to_string()))??; let product = product.ok_or_else(|| Skip::Damaged("a field without its product definition".to_string()))?; - let (count, r, e, d, bits) = packing.ok_or_else(|| Skip::Damaged("a field without its packing".to_string()))??; + let (count, r, e, d, packing) = packing.ok_or_else(|| Skip::Damaged("a field without its packing".to_string()))??; let mask = bitmap.ok_or_else(|| Skip::Damaged("a field without its bitmap section".to_string()))??; if first.is_some_and(|g| !g.same(&grid)) { return Err(Skip::OtherGrid); @@ -1199,10 +1245,11 @@ fn grib2(b: &[u8], room: usize, mut first: Option, uncounted: Uncounted) - if mask.is_some_and(|m| kept(m, points) != count) || (mask.is_none() && count != points) { return Err(Skip::Damaged("a field whose values don't fill its grid".to_string())); } - let (values, rounded, past) = if bits == 0 { - constant((r, d), count, mask, (points, &grid), uncounted)? - } else { - unpack(s.get(5..).unwrap_or_default(), (count, bits), (r, e, d), mask, (points, &grid), uncounted)? + let (data, at) = (s.get(5..).unwrap_or_default(), (points, &grid)); + let (values, rounded, past) = match packing { + Packing::Simple(0) => constant((r, d), count, mask, at, uncounted)?, + Packing::Simple(bits) => unpack(data, (count, bits), (r, e, d), mask, at, uncounted)?, + Packing::Complex(p) => unpack_complex(data, (count, p), (r, e, d), mask, at, uncounted)?, }; held += points; first.get_or_insert(grid); @@ -1337,13 +1384,21 @@ fn scaled(s: &[u8], o: usize, value_signed: bool) -> String { round6(v / 10f64.powi(signed(s, o, 1) as i32)).to_string() } -/// A GRIB2 data representation section: template 5.0 (simple packing) only, as the number of -/// values, R, E, D and the bits a value. -fn grib2_packing(s: &[u8]) -> std::result::Result<(usize, f64, i64, i64, u32), Skip> { +/// How a GRIB2 field's values are packed. +#[derive(Clone, Copy)] +enum Packing { + /// Simple packing (template 5.0), in this many bits a value (0: a constant field). + Simple(u32), + /// Complex packing (templates 5.2 and 5.3). + Complex(complex::Complex), +} + +/// A GRIB2 data representation section (templates 5.0, 5.2 and 5.3): the number of values, R, E, D +/// and the packing. +fn grib2_packing(s: &[u8]) -> std::result::Result<(usize, f64, i64, i64, Packing), Skip> { let template = be(s, 9, 2); - if template != 0 { + if !matches!(template, 0 | 2 | 3) { let kind = match template { - 2 | 3 => "complex packing", 4 => "IEEE floating point", 40 => "JPEG 2000", 41 => "PNG", @@ -1355,8 +1410,9 @@ fn grib2_packing(s: &[u8]) -> std::result::Result<(usize, f64, i64, i64, u32), S if s.len() < 21 { return Err(Skip::Damaged("a damaged data representation section".to_string())); } + let packing = if template == 0 { Packing::Simple(u32::from(s[19])) } else { complex::Complex::of(s, template)? }; let r = f64::from(f32::from_bits(be(s, 11, 4))); - Ok((be(s, 5, 4) as usize, r, signed(s, 15, 2), signed(s, 17, 2), u32::from(s[19]))) + Ok((be(s, 5, 4) as usize, r, signed(s, 15, 2), signed(s, 17, 2), packing)) } #[cfg(test)] diff --git a/crates/data/src/raster/grib/complex.rs b/crates/data/src/raster/grib/complex.rs new file mode 100644 index 0000000000..318e8a0cb7 --- /dev/null +++ b/crates/data/src/raster/grib/complex.rs @@ -0,0 +1,223 @@ +//! GRIB2's complex packing (data representation templates 5.2 and 5.3, data templates 7.2 and +//! 7.3): the values in groups, each with its own reference, width and length, some of whose values +//! may be marked missing; in 5.3, differenced along the scan (once or twice) before they are +//! grouped. + +use super::{MAX_BITS, Packing, Skip, be, bits, signed}; + +/// The largest packed value made from differences: past it `f64` doesn't hold every whole number +/// (packed values have at most 32 bits, so real ones are far below). +const MAX_VALUE: i64 = 1 << 53; + +/// A complex packing, as the data representation section says it. +#[derive(Clone, Copy, Debug)] +pub(super) struct Complex { + ref_bits: u32, + /// Code table 5.5: 0 no missing values, 1 the primary one, 2 the primary and secondary. + missing: u8, + groups: usize, + width_ref: u32, + width_bits: u32, + length_ref: u32, + length_step: u32, + last_length: u32, + length_bits: u32, + /// The order of the spatial differencing; 0 without it (template 5.2). + order: usize, + /// The octets of each of its descriptors (the first values and the least difference). + octets: usize, +} + +impl Complex { + /// The packing a data representation section of template 5.`template` (2 or 3) says. One of no + /// groups is a constant field (NCEP's libraries write one so, and the rest of its template + /// unset), as simple packing in no bits. + pub(super) fn of(s: &[u8], template: u32) -> Result { + if s.len() < if template == 3 { 49 } else { 47 } { + return Err(Skip::Damaged("a damaged data representation section".to_string())); + } + let groups = be(s, 31, 4) as usize; + if groups == 0 { + return Ok(Packing::Simple(0)); + } + let with = |what: String| Skip::Other(format!("GRIB2 complex packing with {what} (template 5.{template})")); + if s[21] != 1 { + return Err(with(format!("group splitting method {}", s[21]))); + } + if s[22] > 2 { + return Err(with(format!("missing value management {}", s[22]))); + } + let (order, octets) = if template == 3 { (usize::from(s[47]), usize::from(s[48])) } else { (0, 0) }; + if template == 3 && !(1..=2).contains(&order) { + return Err(with(format!("spatial differencing of order {order}"))); + } + if octets > 4 { + return Err(with(format!("descriptors of {octets} octets"))); + } + Ok(Packing::Complex(Complex { + ref_bits: u32::from(s[19]), + missing: s[22], + groups, + width_ref: u32::from(s[35]), + width_bits: u32::from(s[36]), + length_ref: be(s, 37, 4), + length_step: u32::from(s[41]), + last_length: be(s, 42, 4), + length_bits: u32::from(s[46]), + order, + octets, + })) + } + + /// The `count` packed values of `data` (the data section's octets after its header), once its + /// groups are found to hold them all. + pub(super) fn values<'a>(&self, data: &'a [u8], count: usize) -> Result, Skip> { + let widest = self.ref_bits.max(self.width_bits).max(self.length_bits); + if widest > MAX_BITS { + return Err(Skip::Other(format!("values of {widest} bits"))); + } + if self.groups > count { + return Err(Skip::Damaged("a field of more groups than values".to_string())); + } + // The descriptors, then each group's reference, width and length, each list starting on + // a whole octet, then the values of every group. + let list = |width: u32| (self.groups as u64 * u64::from(width)).div_ceil(8) * 8; + let descriptors = if self.order == 0 { 0 } else { (self.order + 1) * self.octets }; + let refs_at = descriptors as u64 * 8; + let widths_at = refs_at + list(self.ref_bits); + let lengths_at = widths_at + list(self.width_bits); + let at = lengths_at + list(self.length_bits); + let there = data.len() as u64 * 8; + if at > there { + return Err(Skip::Damaged("a data section shorter than its groups".to_string())); + } + let mut values = Values { + data, + packing: *self, + refs_at, + widths_at, + lengths_at, + at, + group: 0, + left: 0, + reference: 0, + width: 0, + first: [0; 2], + least: 0, + seen: 0, + last: 0, + before: 0, + too_large: false, + }; + let (mut held, mut need) = (0u64, at); + for g in 0..self.groups { + let (width, length) = values.size(g); + if width > u64::from(MAX_BITS) { + return Err(Skip::Other(format!("values of {width} bits"))); + } + held = held.saturating_add(length); + need = need.saturating_add(width.saturating_mul(length)); + } + if held != count as u64 { + return Err(Skip::Damaged("a field whose groups don't hold its values".to_string())); + } + if need > there { + return Err(Skip::Damaged("a data section shorter than its values".to_string())); + } + // The first values, unsigned as every packed value (GDAL reads them so), then the least + // difference, a sign bit and magnitude; of no octets, 0. + if descriptors > 0 { + for (i, v) in values.first.iter_mut().enumerate().take(self.order) { + *v = i64::from(be(data, i * self.octets, self.octets)); + } + values.least = signed(data, self.order * self.octets, self.octets); + } + Ok(values) + } +} + +/// A field's packed values, one at a time, so they are never held apart from the field. +pub(super) struct Values<'a> { + data: &'a [u8], + packing: Complex, + /// Where each list of the groups' starts, and the next value, in bits. + refs_at: u64, + widths_at: u64, + lengths_at: u64, + at: u64, + /// The next group; what is left of the one being read, its reference and its width. + group: usize, + left: u64, + reference: u64, + width: u32, + /// The differencing's first values, its least difference, how many values it has seen (the + /// missing ones aren't differenced) and the last two. + first: [i64; 2], + least: i64, + seen: usize, + last: i64, + before: i64, + /// Whether the differences added up past [`MAX_VALUE`]: the field is damaged. + pub(super) too_large: bool, +} + +impl Values<'_> { + /// Entry `g` of the list at `at`, of `width` bits. + fn entry(&self, at: u64, g: usize, width: u32) -> u64 { + bits(self.data, at + g as u64 * u64::from(width), width) + } + + /// Group `g`'s width in bits, and how many values it holds (the last one's is given apart). + fn size(&self, g: usize) -> (u64, u64) { + let p = &self.packing; + let width = u64::from(p.width_ref) + self.entry(self.widths_at, g, p.width_bits); + let length = if g + 1 == p.groups { + u64::from(p.last_length) + } else { + u64::from(p.length_ref) + u64::from(p.length_step) * self.entry(self.lengths_at, g, p.length_bits) + }; + (width, length) + } + + /// The next value; `None` where it is missing. + pub(super) fn next(&mut self) -> Option { + let p = self.packing; + while self.left == 0 { + if self.group >= p.groups { + return None; + } + let (width, length) = self.size(self.group); + self.reference = self.entry(self.refs_at, self.group, p.ref_bits); + (self.width, self.left) = (width as u32, length); + self.group += 1; + } + self.left -= 1; + let packed = bits(self.data, self.at, self.width); + self.at += u64::from(self.width); + // Missing: every bit set (one less, the secondary missing value) in the value, or in the + // reference of a group of no bits. + if p.missing > 0 { + let (v, width) = if self.width == 0 { (self.reference, p.ref_bits) } else { (packed, self.width) }; + let ones = (1u64 << width) - 1; + if v == ones || (p.missing == 2 && v + 1 == ones) { + return None; + } + } + // At most 33 bits, so the sums below are far from `i64`'s range. + let x = (self.reference + packed) as i64; + if p.order == 0 { + return Some(x as f64); + } + let mut v = match self.first.get(self.seen) { + Some(first) if self.seen < p.order => *first, + _ if p.order == 1 => x + self.least + self.last, + _ => x + self.least + 2 * self.last - self.before, + }; + if v.abs() > MAX_VALUE { + (v, self.too_large) = (0, true); + } + self.seen += 1; + (self.before, self.last) = (self.last, v); + Some(v as f64) + } +} diff --git a/crates/data/src/raster/grib_tests.rs b/crates/data/src/raster/grib_tests.rs index 42c3f935c8..1e030aa615 100644 --- a/crates/data/src/raster/grib_tests.rs +++ b/crates/data/src/raster/grib_tests.rs @@ -395,10 +395,10 @@ fn grib2_fields_south_to_north_with_a_bitmap() { fn grib2_other_packings_are_left_out_and_said() { let a = F2::new(2, 1, vec![1, 2]); let mut b = F2::new(2, 1, vec![1, 2]); - b.template5 = 3; + b.template5 = 42; let r = read_bytes(&grib2_message(&[a, b]), "t").unwrap(); assert_eq!(r.bands.len(), 1); - assert!(r.lost.contains(&"1 field left out: GRIB2 complex packing (template 5.3), not read yet".to_string()), "{:?}", r.lost); + assert!(r.lost.contains(&"1 field left out: GRIB2 CCSDS (template 5.42), not read yet".to_string()), "{:?}", r.lost); // A file with nothing readable is an error naming why. let mut c = F2::new(2, 1, vec![1, 2]); c.template5 = 40; @@ -1278,3 +1278,268 @@ fn fields_of_a_message_too_large_to_read_whole_are_said_so() { assert!(r.lost.contains(&said.to_string()), "{:?}", r.lost); assert!(!r.lost.iter().any(|l| l.contains("the bands read hold the most")), "{:?}", r.lost); } + +/// A field in complex packing: its groups (reference, width in bits and packed values), and the +/// differencing's first values and least difference. +#[derive(Clone)] +struct Cx { + groups: Vec<(u32, u32, Vec)>, + ref_bits: u32, + missing: u8, + /// First values (as many as the order; none: template 5.2) and the least difference. + first: Vec, + least: i64, + octets: usize, + r: f32, + e: i64, + d: i64, + keep: Option>, +} + +impl Cx { + fn new(groups: &[(u32, u32, &[u32])]) -> Cx { + let groups = groups.iter().map(|(r, w, x)| (*r, *w, x.to_vec())).collect(); + Cx { groups, ref_bits: 9, missing: 0, first: vec![], least: 0, octets: 2, r: 0.0, e: 0, d: 0, keep: None } + } + + fn differenced(groups: &[(u32, u32, &[u32])], first: &[i64], least: i64) -> Cx { + Cx { first: first.to_vec(), least, ..Cx::new(groups) } + } + + fn count(&self) -> usize { + self.groups.iter().map(|g| g.2.len()).sum() + } + + /// Sections 5 and 7: widths from 1 less than the least in 5 bits, lengths from 1 by twos in 6 + /// bits (the last group's apart). + fn sections(&self) -> (Vec, Vec) { + let order = self.first.len(); + let least_width = self.groups.iter().map(|g| g.1).min().unwrap().saturating_sub(1); + let last = self.groups.last().unwrap().2.len(); + let mut s5 = u(if order > 0 { 49 } else { 47 }, 4); + s5.push(5); + s5.extend(u(self.count() as u64, 4)); + s5.extend(u(if order > 0 { 3 } else { 2 }, 2)); + s5.extend(u(u64::from(self.r.to_bits()), 4)); + s5.extend(sm(self.e, 2)); + s5.extend(sm(self.d, 2)); + s5.extend([self.ref_bits as u8, 0, 1, self.missing]); + s5.extend(u(u64::from(9999f32.to_bits()), 4)); + s5.extend(u(u64::from(9998f32.to_bits()), 4)); + s5.extend(u(self.groups.len() as u64, 4)); + s5.extend([least_width as u8, 5]); + s5.extend(u(1, 4)); + s5.push(2); + s5.extend(u(last as u64, 4)); + s5.push(6); + if order > 0 { + s5.extend([order as u8, self.octets as u8]); + } + let mut data = Vec::new(); + for v in self.first.iter().chain((order > 0).then_some(&self.least)) { + data.extend(sm(*v, self.octets)); + } + let list = |f: &dyn Fn(&(u32, u32, Vec)) -> u32, bits: u32| pack(&self.groups.iter().map(f).collect::>(), bits); + data.extend(list(&|g| g.0, self.ref_bits)); + data.extend(list(&|g| g.1 - least_width, 5)); + data.extend(list(&|g| (g.2.len() as u32 - 1) / 2, 6)); + // The groups' values one after another, whatever their widths. + let mut bits = Vec::new(); + for (_, w, x) in &self.groups { + bits.extend(x.iter().flat_map(|v| (0..*w).rev().map(move |b| (v >> b) & 1))); + } + data.extend(pack(&bits, 1)); + let mut s7 = u(5 + data.len() as u64, 4); + s7.push(7); + s7.extend(data); + (s5, s7) + } + + /// A message of this field, one row of its points west to east. + fn message(&self) -> Vec { + let (s5, s7) = self.sections(); + self.message_of(&s5, &s7) + } + + fn message_of(&self, s5: &[u8], s7: &[u8]) -> Vec { + let points = self.keep.as_ref().map_or(self.count(), Vec::len); + let mut f = F2::new(points, 1, vec![0; points]); + // 0.05° apart, so thousands fit on a row. + (f.di, f.lon2) = (50_000, f.lon1 + (points as i64 - 1) * 50_000); + f.keep = self.keep.clone(); + let plain = grib2_message(&[f]); + let (five, six, seven) = (section_at(&plain, 5), section_at(&plain, 6), section_at(&plain, 7)); + let s1 = 21; + message_of(&[&plain[16 + s1..five], s5, &plain[six..seven], s7].concat()) + } + + fn values(&self) -> Vec { + let r = read_bytes(&self.message(), "t").unwrap(); + assert!(r.lost.iter().all(|l| l.contains("sphere")), "{:?}", r.lost); + r.bands[0].data.to_vec() + } +} + +/// The values, `None` for NaN. +fn there(v: &[f32]) -> Vec> { + v.iter().map(|v| (!v.is_nan()).then_some(*v)).collect() +} + +/// Fails with the reason a message is left out for. +fn refused(message: &[u8], why: &str) { + let e = read_bytes(message, "t").unwrap_err().to_string(); + assert!(e.contains(why), "{e}"); +} + +#[test] +fn complex_packing_reads_groups_of_their_own_widths() { + // Groups of 1, 5 and 3 values, the second of no bits (its reference), the last 9 bits wide. + let mut c = Cx::new(&[(7, 3, &[5]), (300, 0, &[0; 5]), (2, 9, &[0, 511, 100])]); + assert_eq!(c.values(), vec![12.0, 300.0, 300.0, 300.0, 300.0, 300.0, 2.0, 513.0, 102.0]); + // (R + X × 2^E) / 10^D, as simple packing's. + (c.r, c.e, c.d) = (273.5, -1, 1); + let v = c.values(); + assert!(approx(v[0], (273.5 + 6.0) / 10.0) && approx(v[7], (273.5 + 256.5) / 10.0), "{v:?}"); + // Values f32 rounds are counted, as simple packing's. + let r = read_bytes(&c.message(), "t").unwrap(); + assert!(r.rounded[0] > 0); + // A bitmap masks points, and the values are the others'. + let mut c = Cx::new(&[(1, 2, &[0, 1, 2])]); + c.keep = Some(vec![true, false, true, true, false]); + assert_eq!(there(&c.values()), [Some(1.0), None, Some(2.0), Some(3.0), None]); +} + +#[test] +fn complex_packing_marks_missing_values() { + // Primary: every bit set, in a value or in the reference of a group of no bits. + let mut c = Cx::new(&[(10, 2, &[0, 3, 2]), (511, 0, &[0; 3]), (510, 0, &[0])]); + c.missing = 1; + assert_eq!(there(&c.values()), [Some(10.0), None, Some(12.0), None, None, None, Some(510.0)]); + // The primary and the secondary (one less). In one bit, every value is one or the other. + let mut c = Cx::new(&[(10, 2, &[0, 3, 2, 1, 1]), (510, 0, &[0; 3]), (509, 0, &[0]), (4, 1, &[0, 1])]); + c.missing = 2; + let want = [Some(10.0), None, None, Some(11.0), Some(11.0), None, None, None, Some(509.0), None, None]; + assert_eq!(there(&c.values()), want); + // Without missing value management, the same bits are values. + c.missing = 0; + assert_eq!(c.values(), vec![10.0, 13.0, 12.0, 11.0, 11.0, 510.0, 510.0, 510.0, 509.0, 4.0, 5.0]); + // None of it is said as a value past the range, nor counted as rounded. + c.missing = 1; + let r = read_bytes(&c.message(), "t").unwrap(); + assert!(r.rounded.is_empty() && r.lost.len() == 1, "{:?}", r.lost); +} + +#[test] +fn spatial_differencing_is_undone() { + // 100, 103, 101, 101, 90: differences 3, −2, 0, −11, the least −11. + let c = Cx::differenced(&[(0, 4, &[0, 14, 9]), (11, 0, &[0]), (0, 1, &[0])], &[100], -11); + assert_eq!(c.values(), vec![100.0, 103.0, 101.0, 101.0, 90.0]); + // Twice: 5, 12, 20, 27, 35 differ by 7, 8, 7, 8, which differ by 1, −1, 1. + let c = Cx::differenced(&[(0, 2, &[0, 0, 2]), (0, 2, &[0, 2])], &[5, 12], -1); + assert_eq!(c.values(), vec![5.0, 12.0, 20.0, 27.0, 35.0]); + // The first values are unsigned (the reference value is the least), as GDAL reads them. + let c = Cx::differenced(&[(0, 4, &[0, 3])], &[40_000], -1); + assert_eq!(c.values(), vec![40_000.0, 40_002.0]); + // Missing values aren't differenced: the first value is the first there. + let mut c = Cx::differenced(&[(0, 3, &[7, 0, 5, 7, 3]), (511, 0, &[0]), (0, 3, &[1])], &[100], -4); + c.missing = 1; + assert_eq!(there(&c.values()), [None, Some(100.0), Some(101.0), None, Some(100.0), None, Some(97.0)]); + let mut c = Cx::differenced(&[(0, 3, &[0, 7, 0, 5, 7, 3])], &[100, 90], -4); + c.missing = 1; + assert_eq!(there(&c.values()), [Some(100.0), None, Some(90.0), Some(81.0), None, Some(71.0)]); + // Descriptors of no octets are 0. + let mut c = Cx::differenced(&[(0, 4, &[0, 3, 5])], &[0], 0); + c.octets = 0; + assert_eq!(c.values(), vec![0.0, 3.0, 8.0]); +} + +#[test] +fn a_complex_field_of_no_groups_is_constant() { + let c = Cx::new(&[(0, 0, &[0, 0, 0])]); + let (mut s5, _) = c.sections(); + s5[11..15].copy_from_slice(&4.5f32.to_bits().to_be_bytes()); + // No groups, and nothing else of the template set: NCEP's libraries write one so. + s5[19..].fill(0); + let r = read_bytes(&c.message_of(&s5, &[0, 0, 0, 5, 7]), "t").unwrap(); + assert_eq!(r.bands[0].data, vec![4.5, 4.5, 4.5]); +} + +#[test] +fn complex_packing_this_reader_doesnt_read_is_said() { + let c = Cx::differenced(&[(0, 4, &[0, 3, 5])], &[1], 0); + for (octet, value, why) in [ + (22, 0, "group splitting method 0"), + (23, 3, "missing value management 3"), + (48, 3, "spatial differencing of order 3"), + (48, 0, "spatial differencing of order 0"), + (49, 5, "descriptors of 5 octets"), + ] { + let (mut s5, s7) = c.sections(); + s5[octet - 1] = value; + refused(&c.message_of(&s5, &s7), &format!("1 field left out: GRIB2 complex packing with {why} (template 5.3), not read yet")); + } + // References, widths and lengths past 32 bits, given or added up. + for octet in [20, 36, 37, 47] { + let (mut s5, mut s7) = c.sections(); + s5[octet - 1] = 33; + s7.extend([0; 16]); + s7[3] += 16; + refused(&c.message_of(&s5, &s7), "1 field left out: values of 3"); + } +} + +#[test] +fn damaged_complex_packing_is_said_as_damaged() { + let c = Cx::new(&[(7, 3, &[5]), (300, 0, &[0; 5]), (2, 9, &[0, 511, 100])]); + let damaged = |s5: &[u8], s7: &[u8], why: &str| refused(&c.message_of(s5, s7), &format!("1 field left out: damaged ({why})")); + let (s5, s7) = c.sections(); + // A template cut short. + let mut short = s5[..46].to_vec(); + short[3] = 46; + damaged(&short, &s7, "a damaged data representation section"); + // A group's length changed, the last one's, or more groups than values. + for (octet, value, why) in [ + (41, 2, "a field whose groups don't hold its values"), + (46, 4, "a field whose groups don't hold its values"), + (46, 2, "a field whose groups don't hold its values"), + (35, 10, "a field of more groups than values"), + ] { + let mut bad = s5.clone(); + bad[octet - 1] = value; + damaged(&bad, &s7, why); + } + // Data that end in the values, or in the groups' lists. + for (len, why) in [(s7.len() - 1, "its values"), (9, "its groups"), (5, "its groups")] { + let mut bad = s7[..len].to_vec(); + bad[3] = len as u8; + damaged(&s5, &bad, &format!("a data section shorter than {why}")); + } + // A reference value that isn't a number. + let mut bad = s5.clone(); + bad[11..15].copy_from_slice(&f32::NAN.to_bits().to_be_bytes()); + damaged(&bad, &s7, "a reference value that isn't a number"); + // Differences that add up past what a packed value may be: 2^31 more each step, twice over, + // passes 2^53 within three thousand values. + let x = [0u32; 127]; + let many: Vec<(u32, u32, &[u32])> = (0..30).map(|_| (0, 0, &x[..])).collect(); + let mut c = Cx::differenced(&many, &[0, 0], (1 << 31) - 1); + c.octets = 4; + refused(&c.message(), "1 field left out: damaged (differences that add up past any packed value)"); +} + +#[test] +fn hostile_complex_packing_never_panics() { + let mut c = Cx::differenced(&[(0, 3, &[7, 0, 5, 7, 3]), (511, 0, &[0]), (0, 3, &[1])], &[100, 90], -4); + c.missing = 2; + let file = c.message(); + for n in 0..file.len() { + let _ = read_bytes(&file[..n], "t"); + } + for i in 0..file.len() { + for x in [0x00, 0x01, 0x20, 0x7f, 0x80, 0xff] { + let mut bad = file.clone(); + bad[i] = x; + let _ = read_bytes(&bad, "t"); + } + } +} diff --git a/docs/user-guide/data-formats.md b/docs/user-guide/data-formats.md index 8fb6e945c8..b9f36820ca 100644 --- a/docs/user-guide/data-formats.md +++ b/docs/user-guide/data-formats.md @@ -697,7 +697,7 @@ databases](data.md#sql-queries-and-duckdb-databases). | Scans with no coordinates | an untagged `.tif` or `.png`, or a PDF page without coordinates; any `.tif`, `.png`, `.jpg`/`.jpeg` or `.pdf` with `"as": "scan"` | Add Data, or upload (`layer.addData`, `layer.addDataBytes`) | Grey or RGB(A), 8- or 16-bit pixels. An untagged TIFF or PNG opens as a scan by default; a JPEG needs `"as": "scan"` (otherwise it is a photo). `"as": "scan"` also discards a GeoTIFF's coordinates. A world file beside a TIFF, PNG or JPEG (`.tfw`, `.jgw`, `.pgw`, the four-letter `.tifw`, `.jpgw`, `.pngw`, or `.wld`), with a `.prj` beside it for the coordinate system, places it instead (a JPEG too, which is then not a photo): a turned or skewed one is resampled north up; without a `.prj`, with one RustGIS can't use, or with a world file that can't be read or places the picture nowhere it can be drawn (UTM meters with a longitude/latitude `.prj`), it stays a scan and a notice says why. `"as": "scan"` passes the world file over. World files are read for files added by their path (an upload doesn't bring the files beside it). A project reopens a picture as it was added: one that opened as a scan stays one (add it again once its `.prj` is there), and one a world file placed still opens if its `.prj` or world file is gone, at a stand-in place, with a notice saying it has no coordinates now. A world file is compared with a GeoTIFF's own tags only when both are north up (a turned GeoTIFF is resampled as it is read). A GeoTIFF keeps its own tags, and a notice says when a world file places it differently. The scan initially covers the current view and is marked not georeferenced (`georeferenced: false`) until **Georeference** places it. Export and tools needing ground coordinates refuse it until then. PNG/JPEG decoding is bounded and may reduce the image; large TIFFs can be read at reduced resolution. | | ASCII grid | `.asc` (with an optional `.prj` on desktop) | Add Data, or upload | A single numeric band with square `CELLSIZE` or separate `DX` and `DY` pixel sizes. Desktop files use the neighbouring `.prj`; uploaded and downloaded grids have no sidecar and must have coordinates that fit WGS 84 longitude/latitude. A grid with no `.prj` is read as WGS 84, and a notice says so. | | Zarr | a store's folder (`.zarr`, desktop) or web address (desktop and browser), format 2 (consolidated) or 3 | Home › Add › Add Data › Zarr… (`layer.addZarr`), Add Data on a local folder, or a `?zarr=` link | A variable's latitude/longitude (or y/x) map at the steps picked of its other dimensions (time, level), read chunk by chunk in pure Rust (blosc, zlib, gzip, zstd, LZ4; sharded arrays too). See [Zarr stores](data.md#zarr-stores). | -| GRIB | `.grb`, `.grib`, `.grb2`, `.grib2` | Add Data, or upload | Weather and climate model output, editions 1 and 2, read in pure Rust: each field on the grid of the first one read is a band, named from its message (`d=2026111800:kpds5=61:…` in GRIB1, as wgrib's inventories write it; discipline, category, number and surface in GRIB2). Simple packing on regular latitude/longitude grids, with bitmaps (masked points have no value), in any scanning order, laid out north up and, round the whole globe, from −180° (a last column that repeats the first, 360° on, is left out with a notice). Values are in the file's units (kelvin stays kelvin). Other packings (complex, JPEG 2000, PNG) and grids are left out with a notice naming them; fields on another grid are left out with a count. A sphere's or another earth's latitudes and longitudes are read as WGS 84's, and a notice says so. One record of a large remote file is added by its octets, as its wgrib inventory gives them: `layer.addUrl` with `"bytes": [first, last]` (desktop and command line; at most 64 MB; `"format": "grib"` for an address whose name doesn't say GRIB) asks the server for that range only, and refuses a server that answers the whole file or fewer octets. | +| GRIB | `.grb`, `.grib`, `.grb2`, `.grib2` | Add Data, or upload | Weather and climate model output, editions 1 and 2, read in pure Rust: each field on the grid of the first one read is a band, named from its message (`d=2026111800:kpds5=61:…` in GRIB1, as wgrib's inventories write it; discipline, category, number and surface in GRIB2). Simple packing, and GRIB2's complex packing with or without spatial differencing (as NCEP's GFS and CPTEC's MERGE use), on regular latitude/longitude grids, with bitmaps (points masked, or that complex packing marks missing, have no value), in any scanning order, laid out north up and, round the whole globe, from −180° (a last column that repeats the first, 360° on, is left out with a notice). Values are in the file's units (kelvin stays kelvin). Other packings (GRIB1's second-order, JPEG 2000, PNG, CCSDS) and grids are left out with a notice naming them; fields on another grid are left out with a count. A sphere's or another earth's latitudes and longitudes are read as WGS 84's, and a notice says so. One record of a large remote file is added by its octets, as its wgrib inventory gives them: `layer.addUrl` with `"bytes": [first, last]` (desktop and command line; at most 64 MB; `"format": "grib"` for an address whose name doesn't say GRIB) asks the server for that range only, and refuses a server that answers the whole file or fewer octets. | | SRTM height tile | `.hgt` | Add Data, or upload (desktop and browser) | One 1° tile of 16-bit heights in meters, 1201 × 1201 (3 arc-seconds), 3601 × 3601 (1 arc-second) or 7201 × 7201 (0.5 arc-second), read natively; a tile larger than the memory budget (a 0.5 arc-second tile in the browser) is read at every second sample or fewer, each kept sample still at its cell's center. The file name places it (`N37W122.hgt` is the tile whose south-west corner is 37°N, 122°W; an upload keeps its name), so a file whose name isn't a tile's, or whose size is neither grid's, is refused. Samples sit on the whole-degree lines, so each is a cell centered on its point and the layer reaches half a cell past the tile's edges. WGS 84; voids (−32768) are no data, and a notice counts them. Heights are above the EGM96 geoid (mean sea level), not the ellipsoid, and a notice says so once as the layer is added. SRTM and DTED files hold one band and give their own coordinates (read as WGS 84; a DTED file naming another datum says so), so a `"crs"` or `"layer"` given for one (or kept by a project saved when these files went through GDAL) is ignored, and a notice says so. | | DTED | `.dt0`, `.dt1`, `.dt2` | Add Data, or upload (desktop and browser) | DTED levels 0, 1 and 2, read natively per MIL-PRF-89020B: the UHL header gives the south-west post, the spacing (wider in longitude at high latitudes) and the counts. Posts are cells centered on them, as for SRTM. Voids (−32767) are no data and counted in a notice. In a two's-complement file, a void stored as 0x8001 reads as −1 m and no notice counts it; a height of −1 m stored as 0xFFFF reads as no data. A column whose record lacks its 0xAA sentinel is read as no data, and a notice counts those columns; a whole cell whose longitude counts number its columns from 1 rather than 0 is read by place, and a notice counts those columns; a file with any other longitude count that doesn't match its place (leading columns left out, counts offset, or a stray count), or a record whose latitude count isn't 0, is refused, naming the record, since its heights would land in the wrong place; a column whose checksum doesn't match its heights (some producers write them wrongly) is read as stored, and a notice counts those too. Heights some producers write in two's complement rather than signed magnitude (those that would read below −16000 m) are read as two's complement, and counted in a notice. A complete cell cut short opens with its missing columns as no data, and says so. A partial cell is read in the full-grid layout of CD-ROM files, its missing posts as voids; one in the magnetic-tape layout is refused when its DSI counts only the lines that have heights. A tape cell with a height on every line counts the whole cell too, but its file is shorter than the full grid's, so it's refused as well; a partial cell cut short is refused the same way, since the two can't be told apart. The level is the one the DSI record names (the extension's when it names none, and a notice says when the two differ). A spacing other than the specification's for the level and latitude, a DSI record that disagrees with the UHL, or a horizontal datum other than WGS 84 is said. The vertical datum (EGM96, or mean sea level) is said once, as for SRTM. | | Rasters GDAL reads | `.img`, `.dem`, `.nc`, `.nc4`, `.hdf`, `.hdf5`, `.h5`, `.he5`, `.bil`, `.bsq`, `.bip`, `.envi`, `.grd`, `.rst`, `.sdat`, `.kea`, `.ers`, `.ntf`, `.nitf`, `.ecw`, `.sid`, `.gsb`, `.bt`, `.rsw` | Add Data (desktop, with [GDAL](https://gdal.org): `gdal_translate`, `gdalinfo` and `gdalwarp`; the installed build must include the driver) | Converted once to a cached cloud-optimised GeoTIFF. NetCDF/HDF variables are subdatasets: the first is added, the others named in a notice; `"layer"` picks one. Without a declared coordinate system, longitude/latitude-like coordinates use WGS 84 (0–360° longitudes are moved to −180–180°) and a notice says so, every time the file is read, not only when it is added; otherwise give `"crs"`. JPEG 2000 is listed separately above. | diff --git a/docs/user-guide/data.md b/docs/user-guide/data.md index 5563a51c3e..d7a427c7a0 100644 --- a/docs/user-guide/data.md +++ b/docs/user-guide/data.md @@ -26,7 +26,7 @@ Formats](data-formats.md). | DuckDB databases (`.duckdb`, `.ddb`) and SQL queries | Yes (desktop, when DuckDB is installed) | No | | GeoTIFF and cloud-optimised GeoTIFF (`.tif`, `.tiff`) | Yes | Yes | | ASCII grid (`.asc`, with an optional `.prj`) | Yes | No | -| GRIB editions 1 and 2, simple packing on latitude/longitude grids (`.grb`, `.grib`, `.grb2`, `.grib2`) | Yes | No | +| GRIB editions 1 and 2, simple packing and GRIB2's complex packing on latitude/longitude grids (`.grb`, `.grib`, `.grb2`, `.grib2`) | Yes | No | | SRTM height tiles (`.hgt`) and DTED (`.dt0`–`.dt2`) | Yes | No | | Unreferenced TIFF and PNG scans; JPEG with `"as": "scan"` | Yes | GeoTIFF after georeferencing | | PDF pages: GeoPDFs placed by their coordinates, other pages as scans | Yes (desktop, command line and Python) | GeoTIFF after georeferencing |