pub trait LayerAccess: Sized {
Show 21 methods
// Required methods
unsafe fn c_layer(&self) -> OGRLayerH;
fn defn(&self) -> &Defn;
// Provided methods
fn feature(&self, fid: u64) -> Option<Feature<'_>> { ... }
fn features(&mut self) -> FeatureIterator<'_> ⓘ { ... }
fn set_feature(&self, feature: Feature<'_>) -> Result<()> { ... }
fn set_spatial_filter(&mut self, geometry: &Geometry) { ... }
fn set_spatial_filter_rect(
&mut self,
min_x: f64,
min_y: f64,
max_x: f64,
max_y: f64,
) { ... }
fn clear_spatial_filter(&mut self) { ... }
fn name(&self) -> String { ... }
fn has_capability(&self, capability: LayerCaps) -> bool { ... }
fn create_defn_fields(&self, fields_def: &[(&str, Type)]) -> Result<()> { ... }
fn create_feature(&mut self, geometry: Geometry) -> Result<()> { ... }
fn feature_count(&self) -> u64 { ... }
fn try_feature_count(&self) -> Option<u64> { ... }
fn get_extent(&self) -> Result<Envelope> { ... }
fn try_get_extent(&self) -> Result<Option<Envelope>> { ... }
fn spatial_ref(&self) -> Option<SpatialRef> { ... }
fn reset_feature_reading(&mut self) { ... }
fn set_attribute_filter(&mut self, query: &str) -> Result<()> { ... }
fn clear_attribute_filter(&mut self) { ... }
unsafe fn read_arrow_stream(
&mut self,
out_stream: *mut ArrowArrayStream,
options: &CslStringList,
) -> Result<()> { ... }
}Required Methods§
Provided Methods§
Sourcefn feature(&self, fid: u64) -> Option<Feature<'_>>
fn feature(&self, fid: u64) -> Option<Feature<'_>>
Returns the feature with the given feature id fid, or None if not found.
This function is unaffected by the spatial or attribute filters.
Not all drivers support this efficiently; however, the call should always work if the feature exists, as a fallback implementation just scans all the features in the layer looking for the desired feature.
Sourcefn features(&mut self) -> FeatureIterator<'_> ⓘ
fn features(&mut self) -> FeatureIterator<'_> ⓘ
Returns an iterator over the features in this layer.
This method doesn’t reset the layer, but the returned iterator does so when dropped.
The iterator also borrows the layer mutably, preventing other overlapping borrows.
Sourcefn set_feature(&self, feature: Feature<'_>) -> Result<()>
fn set_feature(&self, feature: Feature<'_>) -> Result<()>
Set a feature on this layer layer.
See: SetFeature
Sourcefn set_spatial_filter(&mut self, geometry: &Geometry)
fn set_spatial_filter(&mut self, geometry: &Geometry)
Set a spatial filter on this layer.
Sourcefn set_spatial_filter_rect(
&mut self,
min_x: f64,
min_y: f64,
max_x: f64,
max_y: f64,
)
fn set_spatial_filter_rect( &mut self, min_x: f64, min_y: f64, max_x: f64, max_y: f64, )
Set a spatial rectangle filter on this layer by specifying the bounds of a rectangle.
Sourcefn clear_spatial_filter(&mut self)
fn clear_spatial_filter(&mut self)
Clear spatial filters set on this layer.
fn has_capability(&self, capability: LayerCaps) -> bool
fn create_defn_fields(&self, fields_def: &[(&str, Type)]) -> Result<()>
fn create_feature(&mut self, geometry: Geometry) -> Result<()>
Sourcefn feature_count(&self) -> u64
fn feature_count(&self) -> u64
Returns the number of features in this layer, even if it requires expensive calculation.
Some drivers will actually scan the entire layer once to count objects.
The returned count takes the spatial filter into account. For dynamic databases the count may not be exact.
Sourcefn try_feature_count(&self) -> Option<u64>
fn try_feature_count(&self) -> Option<u64>
Returns the number of features in this layer, if it is possible to compute this efficiently.
For some drivers, it would be expensive to establish the feature count, in which case
None will be returned.
The returned count takes the spatial filter into account. For dynamic databases the count may not be exact.
Sourcefn get_extent(&self) -> Result<Envelope>
fn get_extent(&self) -> Result<Envelope>
Returns the extent of this layer as an axis-aligned bounding box, even if it requires expensive calculation.
Some drivers will actually scan the entire layer once to count objects.
Depending on the driver, the returned extent may or may not take the spatial
filter into account. So it is safer to call get_extent
without setting a spatial filter.
Layers without any geometry may return OGRErr::OGRERR_FAILURE to indicate that no
meaningful extents could be collected.
Sourcefn try_get_extent(&self) -> Result<Option<Envelope>>
fn try_get_extent(&self) -> Result<Option<Envelope>>
Returns the extent of this layer as an axis-aligned bounding box, if it is possible to compute this efficiently.
For some drivers, it would be expensive to calculate the extent, in which case None
will be returned.
Depending on the driver, the returned extent may or may not take the spatial
filter into account. So it is safer to call try_get_extent
without setting a spatial filter.
Sourcefn spatial_ref(&self) -> Option<SpatialRef>
fn spatial_ref(&self) -> Option<SpatialRef>
Get the spatial reference system for this layer.
Returns Some(SpatialRef), or None if one isn’t defined.
See: OGR_L_GetSpatialRef
fn reset_feature_reading(&mut self)
Sourcefn set_attribute_filter(&mut self, query: &str) -> Result<()>
fn set_attribute_filter(&mut self, query: &str) -> Result<()>
Set a new attribute query that restricts features when using the feature iterator.
From the GDAL docs: Note that installing a query string will generally result in resetting the current reading position
Parameters:
queryin restricted SQL WHERE format
Sourcefn clear_attribute_filter(&mut self)
fn clear_attribute_filter(&mut self)
Clear the attribute filter set on this layer
From the GDAL docs: Note that installing a query string will generally result in resetting the current reading position
Sourceunsafe fn read_arrow_stream(
&mut self,
out_stream: *mut ArrowArrayStream,
options: &CslStringList,
) -> Result<()>
Available on major_ge_4, or major_is_3 and minor_ge_6 only.
unsafe fn read_arrow_stream( &mut self, out_stream: *mut ArrowArrayStream, options: &CslStringList, ) -> Result<()>
major_ge_4, or major_is_3 and minor_ge_6 only.Read batches of columnar Arrow data from OGR.
Extended options are available via crate::cpl::CslStringList.
As defined in the OGR documentation for GetArrowStream,
the current options are:
INCLUDE_FID=YES/NO. Whether to include the FID column. Defaults to YES.MAX_FEATURES_IN_BATCH=integer. Maximum number of features to retrieve in a ArrowArray batch. Defaults to 65 536.
Additional driver-specific options may exist.
This API is new as of GDAL 3.6.
§Example
Refer to the example provided in read_ogr_arrow.rs.
§Safety
This uses the Arrow C Data Interface to operate on raw pointers provisioned from Rust. These pointers must be valid and provisioned according to the ArrowArrayStream spec.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.