pub struct Dataset { /* private fields */ }
Expand description
Wrapper around a GDALDataset
object.
Represents both a vector dataset containing a collection of layers; and a raster dataset containing a collection of rasterbands.
Implementations§
Source§impl Dataset
impl Dataset
Sourcepub fn open<P>(path: P) -> Result<Dataset, GdalError>
pub fn open<P>(path: P) -> Result<Dataset, GdalError>
Open a dataset at the given path
with default
options.
Sourcepub fn open_ex<P>(
path: P,
options: DatasetOptions<'_>,
) -> Result<Dataset, GdalError>
pub fn open_ex<P>( path: P, options: DatasetOptions<'_>, ) -> Result<Dataset, GdalError>
Open a dataset with extended options. See
GDALOpenEx
.
Sourcepub unsafe fn from_c_dataset(c_dataset: *mut c_void) -> Dataset
pub unsafe fn from_c_dataset(c_dataset: *mut c_void) -> Dataset
Sourcepub fn projection(&self) -> String
pub fn projection(&self) -> String
Fetch the projection definition string for this dataset.
Sourcepub fn set_projection(&mut self, projection: &str) -> Result<(), GdalError>
pub fn set_projection(&mut self, projection: &str) -> Result<(), GdalError>
Set the projection reference string for this dataset.
Sourcepub fn spatial_ref(&self) -> Result<SpatialRef, GdalError>
pub fn spatial_ref(&self) -> Result<SpatialRef, GdalError>
Get the spatial reference system for this dataset.
Sourcepub fn set_spatial_ref(
&mut self,
spatial_ref: &SpatialRef,
) -> Result<(), GdalError>
pub fn set_spatial_ref( &mut self, spatial_ref: &SpatialRef, ) -> Result<(), GdalError>
Set the spatial reference system for this dataset.
pub fn create_copy<P>( &self, driver: &Driver, filename: P, options: &[RasterCreationOption<'_>], ) -> Result<Dataset, GdalError>
Sourcepub fn rasterband(&self, band_index: isize) -> Result<RasterBand<'_>, GdalError>
pub fn rasterband(&self, band_index: isize) -> Result<RasterBand<'_>, GdalError>
Fetch a band object for a dataset.
Applies to raster datasets, and fetches the rasterband at the given 1-based index.
Sourcepub fn build_overviews(
&mut self,
resampling: &str,
overviews: &[i32],
bands: &[i32],
) -> Result<(), GdalError>
pub fn build_overviews( &mut self, resampling: &str, overviews: &[i32], bands: &[i32], ) -> Result<(), GdalError>
Builds overviews for the current Dataset
. See GDALBuildOverviews
.
§Arguments
resampling
- resampling method, as accepted by GDAL, e.g."CUBIC"
overviews
- list of overview decimation factors, e.g.&[2, 4, 8, 16, 32]
bands
- list of bands to build the overviews for, or empty for all bands
Sourcepub fn layer_count(&self) -> isize
pub fn layer_count(&self) -> isize
Get the number of layers in this dataset.
Sourcepub fn layer(&self, idx: isize) -> Result<Layer<'_>, GdalError>
pub fn layer(&self, idx: isize) -> Result<Layer<'_>, GdalError>
Fetch a layer by index.
Applies to vector datasets, and fetches by the given 0-based index.
Sourcepub fn layers(&self) -> LayerIterator<'_>
pub fn layers(&self) -> LayerIterator<'_>
Returns an iterator over the layers of the dataset.
Sourcepub fn raster_count(&self) -> isize
pub fn raster_count(&self) -> isize
Fetch the number of raster bands on this dataset.
Sourcepub fn raster_size(&self) -> (usize, usize)
pub fn raster_size(&self) -> (usize, usize)
Returns the raster dimensions: (width, height).
Sourcepub fn create_layer<'a>(
&mut self,
options: LayerOptions<'a>,
) -> Result<Layer<'_>, GdalError>
pub fn create_layer<'a>( &mut self, options: LayerOptions<'a>, ) -> Result<Layer<'_>, GdalError>
Creates a new layer. The LayerOptions
struct implements Default
, so you only need to
specify those options that deviate from the default.
§Examples
Create a new layer with an empty name, no spatial reference, and unknown geometry type:
let blank_layer = dataset.create_layer(Default::default()).unwrap();
Create a new named line string layer using WGS84:
let roads = dataset.create_layer(LayerOptions {
name: "roads",
srs: Some(&SpatialRef::from_epsg(4326).unwrap()),
ty: gdal_sys::OGRwkbGeometryType::wkbLineString,
..Default::default()
}).unwrap();
Sourcepub fn set_geo_transform(
&mut self,
transformation: &[f64; 6],
) -> Result<(), GdalError>
pub fn set_geo_transform( &mut self, transformation: &[f64; 6], ) -> Result<(), GdalError>
Affine transformation called geotransformation.
This is like a linear transformation preserves points, straight lines and planes. Also, sets of parallel lines remain parallel after an affine transformation.
§Arguments
- transformation - coeficients of transformations
x-coordinate of the top-left corner pixel (x-offset) width of a pixel (x-resolution) row rotation (typically zero) y-coordinate of the top-left corner pixel column rotation (typically zero) height of a pixel (y-resolution, typically negative)
Sourcepub fn geo_transform(&self) -> Result<[f64; 6], GdalError>
pub fn geo_transform(&self) -> Result<[f64; 6], GdalError>
Get affine transformation coefficients.
x-coordinate of the top-left corner pixel (x-offset) width of a pixel (x-resolution) row rotation (typically zero) y-coordinate of the top-left corner pixel column rotation (typically zero) height of a pixel (y-resolution, typically negative)
Sourcepub fn start_transaction(&mut self) -> Result<Transaction<'_>, GdalError>
pub fn start_transaction(&mut self) -> Result<Transaction<'_>, GdalError>
For datasources which support transactions, this creates a transaction.
During the transaction, the dataset can be mutably borrowed using
Transaction::dataset_mut
to make changes. All changes done after the start of the
transaction are applied to the datasource when commit
is called.
They may be canceled by calling rollback
instead, or by dropping
the Transaction
without calling commit
.
Depending on the driver, using a transaction can give a huge performance improvement when creating a lot of geometry at once. This is because the driver doesn’t need to commit every feature to disk individually.
If starting the transaction fails, this function will return OGRErr::OGRERR_FAILURE
.
For datasources that do not support transactions, this function will always return
OGRErr::OGRERR_UNSUPPORTED_OPERATION
.
Limitations:
-
Datasources which do not support efficient transactions natively may use less efficient emulation of transactions instead; as of GDAL 3.1, this only applies to the closed-source FileGDB driver, which (unlike OpenFileGDB) is not available in a GDAL build by default.
-
At the time of writing, transactions only apply on vector layers.
-
Nested transactions are not supported.
-
If an error occurs after a successful
start_transaction
, the whole transaction may or may not be implicitly canceled, depending on the driver. For example, the PG driver will cancel it, but the SQLite and GPKG drivers will not.
Example:
fn create_point_grid(dataset: &mut Dataset) -> gdal::errors::Result<()> {
use gdal::vector::Geometry;
// Start the transaction.
let mut txn = dataset.start_transaction()?;
let mut layer = txn.dataset_mut().create_layer(LayerOptions {
name: "grid",
ty: gdal_sys::OGRwkbGeometryType::wkbPoint,
..Default::default()
})?;
for y in 0..100 {
for x in 0..100 {
let wkt = format!("POINT ({} {})", x, y);
layer.create_feature(Geometry::from_wkt(&wkt)?)?;
}
}
// We got through without errors. Commit the transaction and return.
txn.commit()?;
Ok(())
}
Sourcepub fn execute_sql<S>(
&self,
query: S,
spatial_filter: Option<&Geometry>,
dialect: Dialect,
) -> Result<Option<ResultSet<'_>>, GdalError>
pub fn execute_sql<S>( &self, query: S, spatial_filter: Option<&Geometry>, dialect: Dialect, ) -> Result<Option<ResultSet<'_>>, GdalError>
Execute a SQL query against the Dataset. It is equivalent to calling
GDALDatasetExecuteSQL
.
Returns a sql::ResultSet
, which can be treated just as any other Layer
.
Queries such as ALTER TABLE
, CREATE INDEX
, etc. have no sql::ResultSet
, and return
None
, which is distinct from an empty sql::ResultSet
.
§Arguments
query
: The SQL queryspatial_filter
: Limit results of the query to features that intersect the givenGeometry
dialect
: The dialect of SQL to use. See https://gdal.org/user/ogr_sql_sqlite_dialect.html
§Example
use gdal::vector::sql;
let ds = Dataset::open(Path::new("fixtures/roads.geojson")).unwrap();
let query = "SELECT kind, is_bridge, highway FROM roads WHERE highway = 'pedestrian'";
let mut result_set = ds.execute_sql(query, None, sql::Dialect::DEFAULT).unwrap().unwrap();
assert_eq!(10, result_set.feature_count());
for feature in result_set.features() {
let highway = feature
.field("highway")
.unwrap()
.unwrap()
.into_string()
.unwrap();
assert_eq!("pedestrian", highway);
}
Trait Implementations§
Source§impl Metadata for Dataset
impl Metadata for Dataset
fn description(&self) -> Result<String, GdalError>
fn metadata_domains(&self) -> Vec<String>
fn metadata_domain(&self, domain: &str) -> Option<Vec<String>>
fn metadata_item(&self, key: &str, domain: &str) -> Option<String>
fn set_metadata_item( &mut self, key: &str, value: &str, domain: &str, ) -> Result<(), GdalError>
fn set_description(&mut self, description: &str) -> Result<(), GdalError>
impl Send for Dataset
Auto Trait Implementations§
impl Freeze for Dataset
impl RefUnwindSafe for Dataset
impl !Sync for Dataset
impl Unpin for Dataset
impl UnwindSafe for Dataset
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>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
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
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
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
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>>
OutOfBounds
error is returned which contains
the unclamped color. Read more