pub struct Raster { /* private fields */ }
Expand description
A Raster image.
Implementations§
Source§impl Raster
impl Raster
Sourcepub fn new(path: PathBuf) -> Result<Self, MapEngineError>
pub fn new(path: PathBuf) -> Result<Self, MapEngineError>
Crete a new Raster
.
This will open a Dataset
and store some metadata into the Raster
struct. This serves
as a cache to avoid constantly reading from the file.
Sourcepub fn from_src(path: PathBuf, src: &Dataset) -> Result<Self, MapEngineError>
pub fn from_src(path: PathBuf, src: &Dataset) -> Result<Self, MapEngineError>
Create a new Raster
from an open Dataset
.
Usually, you would want to use Raster::new
but this method is available in case you
already opened a Dataset
.
Sourcepub fn read_tile<P>(
&self,
tile: &Tile,
bands: Option<&[isize]>,
e_resample_alg: Option<ResampleAlg>,
) -> Result<RawPixels<P>, MapEngineError>
pub fn read_tile<P>( &self, tile: &Tile, bands: Option<&[isize]>, e_resample_alg: Option<ResampleAlg>, ) -> Result<RawPixels<P>, MapEngineError>
Read a tile from raster file.
§Arguments
tile
- Tile to read.bands
- Bands to read (1-indexed).e_resample_alg
- Resample algorith to use in case interpolations are needed.
§Examples
use gdal::raster::ResampleAlg;
use map_engine::{errors::MapEngineError, raster::{Raster, RawPixels}, tiles::Tile};
use std::path::PathBuf;
fn main() -> Result<(), MapEngineError> {
let path = PathBuf::from("src/tests/data/chile_optimised.tif");
let raster = Raster::new(path)?;
let tile = Tile::new(304, 624, 10);
let arr: RawPixels<f64> = raster.read_tile(&tile, Some(&[1]), Some(ResampleAlg::Average))?;
assert_eq!(arr.as_array().shape(), &[1, 256, 256]);
Ok(())
}
pub fn geo(&self) -> &GeoTransform
pub fn spatial_ref(&self) -> Result<SpatialRef, MapEngineError>
pub fn driver_name(&self) -> &str
Sourcepub fn raster_count(&self) -> isize
pub fn raster_count(&self) -> isize
Get number of bands available in the file.
pub fn raster_size(&self) -> (usize, usize)
pub fn intersects(&self, tile: &Tile) -> Result<bool, MapEngineError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Raster
impl RefUnwindSafe for Raster
impl Send for Raster
impl Sync for Raster
impl Unpin for Raster
impl UnwindSafe for Raster
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
Convert the source color to the destination color using the specified
method
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Convert the source color to the destination color using the bradford
method by default
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Convert into T with values clamped to the color defined bounds Read more
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Convert into T. The resulting color might be invalid in its color space Read more
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
Convert into T, returning ok if the color is inside of its defined
range, otherwise an
OutOfBounds
error is returned which contains
the unclamped color. Read more