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]
impl Dataset
[src]pub unsafe fn c_dataset(&self) -> GDALDatasetH
[src]
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]
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]
&mut self,
resampling: &str,
overviews: &[i32],
bands: &[i32]
) -> Result<()>
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]
Notable traits for LayerIterator<'a>
impl<'a> Iterator for LayerIterator<'a> type Item = Layer<'a>;
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]
&mut self,
name: &str,
srs: Option<&SpatialRef>,
ty: Type
) -> Result<Layer<'_>>
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]
&self,
query: S,
spatial_filter: Option<&Geometry>,
dialect: Dialect
) -> Result<Option<ResultSet<'_>>>
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
impl Metadata for Dataset
[src]
impl Metadata for Dataset
[src]fn description(&self) -> Result<String>
[src]
fn metadata_domains(&self) -> Vec<String>
[src]
fn metadata_domain(&self, domain: &str) -> Option<Vec<String>>
[src]
fn metadata_item(&self, key: &str, domain: &str) -> Option<String>
[src]
fn set_metadata_item(
&mut self,
key: &str,
value: &str,
domain: &str
) -> Result<()>
[src]
&mut self,
key: &str,
value: &str,
domain: &str
) -> Result<()>
Auto Trait Implementations
impl RefUnwindSafe for Dataset
impl RefUnwindSafe for Dataset
impl UnwindSafe for Dataset
impl UnwindSafe for Dataset