Skip to content
11 changes: 10 additions & 1 deletion geoengine/datatypes/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
collections::FeatureCollectionError,
primitives::{BoundingBox2D, Coordinate2D, PrimitivesError, TimeInstance, TimeInterval},
raster::RasterDataType,
raster::{RasterDataType, TileOverlap},
spatial_reference::SpatialReference,
};
use snafu::{AsErrorSource, ErrorCompat, IntoError, prelude::*};
Expand Down Expand Up @@ -381,6 +381,15 @@ pub enum Error {
srs_out: SpatialReference,
bounds: BoundingBox2D,
},
#[snafu(display(
"Not enough tile overlap available: requested {}, but only {} is present",
requested,
available
))]
NotEnoughTileOverlap {
requested: TileOverlap,
available: TileOverlap,
},
}

impl From<arrow::error::ArrowError> for Error {
Expand Down
23 changes: 20 additions & 3 deletions geoengine/datatypes/src/raster/arrow_conversion.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::{Grid2D, GridOrEmpty, GridOrEmpty2D, GridSize, Pixel, RasterTile2D, TypedGrid2D};
use super::{
GeoTransform, Grid2D, GridOrEmpty, GridOrEmpty2D, GridSize, Pixel, RasterTile2D, TypedGrid2D,
};
use crate::{raster::RasterDataType, spatial_reference::SpatialReferenceOption, util::Result};
use arrow::{
array::{Array, ArrayRef, PrimitiveBuilder},
Expand Down Expand Up @@ -40,10 +42,22 @@ fn raster_tile_2d_to_arrow_record_batch<P: Pixel>(
tile: RasterTile2D<P>,
spatial_ref: SpatialReferenceOption,
) -> Result<RecordBatch> {
// The serialized worldfile describes the array's geographic extent, which
// includes the overlap halo; its origin is therefore the data corner (the
// core anchor shifted by the overlap), not the canonical core-anchored
// transform of the tile.
let data_origin = tile
.global_geo_transform
.grid_idx_to_pixel_upper_left_coordinate_2d(tile.global_data_upper_left_pixel_idx());
let data_geo_transform = GeoTransform::new(
data_origin,
tile.global_geo_transform.x_pixel_size(),
tile.global_geo_transform.y_pixel_size(),
);
let metadata: HashMap<String, String> = [
(
GEO_TRANSFORM_KEY.to_string(),
serde_json::to_string(&tile.tile_geo_transform()).unwrap_or_default(),
serde_json::to_string(&data_geo_transform).unwrap_or_default(),
),
(
X_SIZE_KEY.to_string(),
Expand Down Expand Up @@ -169,7 +183,8 @@ mod tests {
use crate::{
primitives::{CacheHint, TimeInterval},
raster::{
EmptyGrid2D, GridIndexAccessMut, MaskedGrid2D, TileIdx, TileInformation, TileSize,
EmptyGrid2D, GridIndexAccessMut, MaskedGrid2D, TileIdx, TileInformation, TileOverlap,
TileSize,
},
spatial_reference::SpatialReference,
util::test::TestDefault,
Expand Down Expand Up @@ -238,6 +253,7 @@ mod tests {
let raster_tile = RasterTile2D::new_with_tile_info(
TimeInterval::default(),
TileInformation {
overlap: TileOverlap::zero(),
global_geo_transform: TestDefault::test_default(),
tile_position: TileIdx::new_y_x(0, 0),
tile_size: TileSize::new_y_x(3, 2),
Expand Down Expand Up @@ -289,6 +305,7 @@ mod tests {
let raster_tile = RasterTile2D::new_with_tile_info(
TimeInterval::default(),
TileInformation {
overlap: TileOverlap::zero(),
global_geo_transform: TestDefault::test_default(),
tile_position: TileIdx::new_y_x(0, 0),
tile_size: TileSize::new_y_x(3, 2),
Expand Down
4 changes: 2 additions & 2 deletions geoengine/datatypes/src/raster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub use self::raster_tile::{
RasterTile, RasterTile2D, RasterTile3D, TilesEqualIgnoringCacheHint, display_raster_tile_2d,
};
pub use self::tiling::{
TileIdx, TileIdx2DIter, TileInformation, TileInformationIter, TileSize, TilingGrid,
TilingSpecification, TilingStrategy,
TileIdx, TileIdx2DIter, TileInformation, TileInformationIter, TileOverlap, TileSize,
TilingGrid, TilingSpecification, TilingStrategy,
};
pub use self::typed_raster_conversion::TypedRasterConversion;
pub use self::typed_raster_tile::{TypedRasterTile2D, TypedRasterTile3D};
Expand Down
2 changes: 2 additions & 0 deletions geoengine/datatypes/src/raster/operations/checked_scaling.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::raster::{
EmptyGrid, GridOrEmpty, GridOrEmpty2D, GridSize, MapElements, MaskedGrid, RasterTile2D,
TileOverlap,
};
use num_traits::{CheckedAdd, CheckedDiv, CheckedMul, CheckedSub};
use std::ops::{Add, Div, Mul, Sub};
Expand Down Expand Up @@ -184,6 +185,7 @@ where
tile_position: self.tile_position,
time: self.time,
cache_hint: self.cache_hint.clone_with_current_datetime(),
overlap: TileOverlap::zero(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::raster::{BaseTile, EmptyGrid, Grid, GridOrEmpty, GridSize, masked_grid::MaskedGrid};
use crate::raster::{
BaseTile, EmptyGrid, Grid, GridOrEmpty, GridSize, TileOverlap, masked_grid::MaskedGrid,
};
use num_traits::AsPrimitive;
use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator};

Expand Down Expand Up @@ -57,6 +59,7 @@ where
properties: self.properties,
tile_position: self.tile_position,
cache_hint: self.cache_hint.clone_with_current_datetime(),
overlap: TileOverlap::zero(),
}
}
}
Expand Down Expand Up @@ -129,6 +132,7 @@ where
properties: self.properties,
tile_position: self.tile_position,
cache_hint: self.cache_hint.clone_with_current_datetime(),
overlap: TileOverlap::zero(),
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions geoengine/datatypes/src/raster/operations/interpolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ mod tests {
primitives::CacheHint,
raster::{
GeoTransform, GeoTransformAccess, Grid2D, GridOrEmpty, MaskedGrid, RasterTile2D,
TileIdx, TileInformation, TileSize,
TileIdx, TileInformation, TileOverlap, TileSize,
},
};

Expand All @@ -181,6 +181,7 @@ mod tests {
let input = RasterTile2D::new_with_tile_info(
Default::default(),
TileInformation {
overlap: TileOverlap::zero(),
tile_position: TileIdx::new_y_x(0, 0),
tile_size: TileSize::new_y_x(3, 3),
global_geo_transform: GeoTransform::new((0.0, 2.0).into(), 1.0, -1.0),
Expand All @@ -196,13 +197,14 @@ mod tests {
let input_grid = input.into_inner_positioned_grid();

let output_info = TileInformation {
overlap: TileOverlap::zero(),
tile_position: TileIdx::new_y_x(0, 0),
tile_size: TileSize::new_y_x(3, 3),
global_geo_transform: GeoTransform::new((0.0, 2.0).into(), 0.5, -0.5),
};

let output_geo_transform = output_info.global_geo_transform;
let output_bounds = output_info.global_pixel_bounds();
let output_bounds = output_info.core_pixel_bounds();

let pool = ThreadPoolBuilder::new().num_threads(0).build().unwrap();

Expand Down Expand Up @@ -266,6 +268,7 @@ mod tests {
let input = RasterTile2D::new_with_tile_info(
Default::default(),
TileInformation {
overlap: TileOverlap::zero(),
tile_position: TileIdx::new_y_x(0, 0),
tile_size: TileSize::new_y_x(3, 3),
global_geo_transform: GeoTransform::new((0.0, 2.0).into(), 1.0, -1.0),
Expand All @@ -281,13 +284,14 @@ mod tests {
let input_grid = input.into_inner_positioned_grid();

let output_info = TileInformation {
overlap: TileOverlap::zero(),
tile_position: TileIdx::new_y_x(0, 0),
tile_size: TileSize::new_y_x(4, 4),
global_geo_transform: GeoTransform::new((0.0, 2.0).into(), 0.5, -0.5),
};

let output_geo_transform = output_info.global_geo_transform;
let output_bounds = output_info.global_pixel_bounds();
let output_bounds = output_info.core_pixel_bounds();

let pool = ThreadPoolBuilder::new().num_threads(0).build().unwrap();

Expand Down
6 changes: 5 additions & 1 deletion geoengine/datatypes/src/raster/operations/map_elements.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::raster::{Grid, GridOrEmpty, GridOrEmpty2D, GridSize, MaskedGrid, RasterTile2D};
use crate::raster::{
Grid, GridOrEmpty, GridOrEmpty2D, GridSize, MaskedGrid, RasterTile2D, TileOverlap,
};
use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator};

const MIN_ELEMENTS_PER_THREAD: usize = 16 * 512;
Expand Down Expand Up @@ -174,6 +176,7 @@ where
global_geo_transform: self.global_geo_transform,
properties: self.properties,
cache_hint: self.cache_hint.clone_with_current_datetime(),
overlap: TileOverlap::zero(),
}
}
}
Expand Down Expand Up @@ -351,6 +354,7 @@ where
global_geo_transform: self.global_geo_transform,
properties: self.properties,
cache_hint: self.cache_hint.clone_with_current_datetime(),
overlap: TileOverlap::zero(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::raster::{
EmptyGrid, Grid, GridIdx, GridIndexAccess, GridOrEmpty, GridOrEmpty2D, GridSize,
GridSpaceToLinearSpace, MaskedGrid, MaskedGrid2D, RasterTile2D,
GridSpaceToLinearSpace, MaskedGrid, MaskedGrid2D, RasterTile2D, TileOverlap,
};
use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator};

Expand Down Expand Up @@ -318,6 +318,7 @@ where
global_geo_transform: self.global_geo_transform,
properties: self.properties,
cache_hint: self.cache_hint.clone_with_current_datetime(),
overlap: TileOverlap::zero(),
}
}
}
Expand Down Expand Up @@ -641,6 +642,7 @@ where
global_geo_transform: self.global_geo_transform,
properties: self.properties,
cache_hint: self.cache_hint.clone_with_current_datetime(),
overlap: TileOverlap::zero(),
}
}
}
Expand Down
Loading
Loading