Struct gdal::Dataset[][src]

pub struct Dataset { /* fields omitted */ }

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

impl Dataset[src]

pub unsafe fn c_dataset(&self) -> GDALDatasetH[src]

Returns the wrapped C pointer

Safety

This method returns a raw C pointer

pub fn open(path: &Path) -> Result<Dataset>[src]

Open a dataset at the given path with default options.

pub fn open_ex(path: &Path, options: DatasetOptions<'_>) -> Result<Dataset>[src]

Open a dataset with extended options. See GDALOpenEx.

pub unsafe fn from_c_dataset(c_dataset: GDALDatasetH) -> Dataset[src]

Creates a new Dataset by wrapping a C pointer

Safety

This method operates on a raw C pointer

pub fn projection(&self) -> String[src]

Fetch the projection definition string for this dataset.

pub fn set_projection(&mut self, projection: &str) -> Result<()>[src]

Set the projection reference string for this dataset.

pub fn spatial_ref(&self) -> Result<SpatialRef>[src]

Get the spatial reference system for this dataset.

pub fn set_spatial_ref(&mut self, spatial_ref: &SpatialRef) -> Result<()>[src]

Set the spatial reference system for this dataset.

pub fn create_copy(&self, driver: &Driver, filename: &str) -> Result<Dataset>[src]

pub fn driver(&self) -> Driver[src]

Fetch the driver to which this dataset relates.

pub fn rasterband(&self, band_index: isize) -> Result<RasterBand<'_>>[src]

Fetch a band object for a dataset.

Applies to raster datasets, and fetches the rasterband at the given 1-based index.

pub fn build_overviews(
    &mut self,
    resampling: &str,
    overviews: &[i32],
    bands: &[i32]
) -> Result<()>
[src]

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

pub fn layer_count(&self) -> isize[src]

Get the number of layers in this dataset.

pub fn layer(&self, idx: isize) -> Result<Layer<'_>>[src]

Fetch a layer by index.

Applies to vector datasets, and fetches by the given 0-based index.

pub fn layer_by_name(&self, name: &str) -> Result<Layer<'_>>[src]

Fetch a layer by name.

pub fn layers(&self) -> LayerIterator<'_>

Notable traits for LayerIterator<'a>

impl<'a> Iterator for LayerIterator<'a> type Item = Layer<'a>;
[src]

Returns an iterator over the layers of the dataset.

pub fn raster_count(&self) -> isize[src]

Fetch the number of raster bands on this dataset.

pub fn raster_size(&self) -> (usize, usize)[src]

Returns the raster dimensions: (width, height).

pub fn create_layer_blank(&mut self) -> Result<Layer<'_>>[src]

Create a new layer with a blank name, no SpatialRef, and without (wkbUnknown) geometry type.

pub fn create_layer(
    &mut self,
    name: &str,
    srs: Option<&SpatialRef>,
    ty: Type
) -> Result<Layer<'_>>
[src]

Create a new layer with a name, an optional SpatialRef, and a geometry type.

pub fn set_geo_transform(&mut self, transformation: &GeoTransform) -> Result<()>[src]

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)

pub fn geo_transform(&self) -> Result<GeoTransform>[src]

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)

pub fn start_transaction(&mut self) -> Result<Transaction<'_>>[src]

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("grid", None, gdal_sys::OGRwkbGeometryType::wkbPoint)?;
    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(())
}

pub fn execute_sql<S: AsRef<str>>(
    &self,
    query: S,
    spatial_filter: Option<&Geometry>,
    dialect: Dialect
) -> Result<Option<ResultSet<'_>>>
[src]

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

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

impl Debug for Dataset[src]

impl Drop for Dataset[src]

impl Metadata for Dataset[src]

impl Send for Dataset[src]

Auto Trait Implementations

impl RefUnwindSafe for Dataset

impl !Sync for Dataset

impl Unpin for Dataset

impl UnwindSafe for Dataset

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.