Skip to content

Commit

Permalink
Merge branch 'master' into feature/csl-extend
Browse files Browse the repository at this point in the history
  • Loading branch information
metasim authored Nov 2, 2023
2 parents 3c803a5 + 552f9dd commit dc5a90e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
20 changes: 12 additions & 8 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@

- <https://github.com/georust/gdal/pull/457>

- **Breaking**: `Dataset::raster_count` now returns an `usize` and `Dataset::rasterband` now takes `usize` instead of `isize`

- <https://github.com/georust/gdal/pull/434>

- **Breaking**: `CslStringListIterator` returns a `CslStringListEntry` instead of `(String, String)` in order to differentiate between `key=value` entries vs `flag` entries.
- **Breaking**: `CslStringList::fetch_name_value` returns `Option<String>` instead of `Result<Option<String>>`, better reflecting the semantics of GDAL C API.
- Added `CslStringList::get_field`, `CslStringList::find_string`, `CslStringList::partial_find_string`, `CslStringList::find_string_case_sensitive`, `CslStringList::into_ptr`, `CslStringList::add_name_value`.

- <https://github.com/georust/gdal/pull/455>

- **Breaking**: `ExtendedDataType` no longer implements `Clone`, `PartialEq` and `Eq`
- **Breaking**: `ExtendedDataType` no longer implements `Clone`, `PartialEq` and `Eq`

- <https://github.com/georust/gdal/pull/451>
- <https://github.com/georust/gdal/pull/451>

- **Breaking**: Moved `LayerIterator`, `LayerOptions` and `Transaction` to `crate::vector`
- **Breaking**: Moved `LayerIterator`, `LayerOptions` and `Transaction` to `crate::vector`

- <https://github.com/georust/gdal/pull/447>
- <https://github.com/georust/gdal/pull/447>

- Accessors `MajorObject::gdal_object_ptr` and `Dataset::c_dataset()` are no longer marked as `unsafe` (only using these is unsafe in idiomatic Rust)
- Accessors `MajorObject::gdal_object_ptr` and `Dataset::c_dataset()` are no longer marked as `unsafe` (only using these is unsafe in idiomatic Rust)

- <https://github.com/georust/gdal/pull/447>

- Fixed build script error with development GDAL versions
- Fixed build script error with development GDAL versions

- <https://github.com/georust/gdal/pull/439>

Expand All @@ -45,7 +49,7 @@

- Added `Geometry::flatten_to_2d`

- <https://github.com/georust/gdal/pull/428/>
- <https://github.com/georust/gdal/pull/428/>

## 0.15

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ semver = "1.0"
[dev-dependencies]
tempfile = "3.8"
# Only used in the example
arrow2 = "0.17"
arrow2 = "0.18"

[workspace]
members = ["gdal-sys"]
Expand Down
2 changes: 1 addition & 1 deletion gdal-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ links="gdal"
libc = "0.2"

[build-dependencies]
bindgen = { version = "0.68", optional = true }
bindgen = { version = "0.69", optional = true }
pkg-config = "0.3"
semver = "1.0"
17 changes: 12 additions & 5 deletions src/raster/rasterband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ use crate::errors::*;
impl Dataset {
/// Fetch a band object for a dataset.
///
/// Applies to raster datasets, and fetches the
/// rasterband at the given _1-based_ index.
pub fn rasterband(&self, band_index: isize) -> Result<RasterBand> {
/// Applies to raster datasets, and fetches the band at the given _1-based_ index.
///
/// # Errors
/// Returns an error if the band cannot be read, including in the case the index is 0.
///
/// # Panics
/// Panics if the band index is greater than `c_int::MAX`.
pub fn rasterband(&self, band_index: usize) -> Result<RasterBand> {
assert!(band_index <= c_int::MAX as usize);

unsafe {
let c_band = gdal_sys::GDALGetRasterBand(self.c_dataset(), band_index as c_int);
if c_band.is_null() {
Expand Down Expand Up @@ -69,8 +76,8 @@ impl Dataset {
}

/// Fetch the number of raster bands on this dataset.
pub fn raster_count(&self) -> isize {
(unsafe { gdal_sys::GDALGetRasterCount(self.c_dataset()) }) as isize
pub fn raster_count(&self) -> usize {
(unsafe { gdal_sys::GDALGetRasterCount(self.c_dataset()) }) as usize
}

/// Returns the raster dimensions: (width, height).
Expand Down
5 changes: 3 additions & 2 deletions src/raster/rasterize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod tests {
/// may be of any GDAL supported datatype.
pub fn rasterize(
dataset: &mut Dataset,
bands: &[isize],
bands: &[usize],
geometries: &[Geometry],
burn_values: &[f64],
options: Option<RasterizeOptions>,
Expand All @@ -178,8 +178,9 @@ pub fn rasterize(
geometries.len()
)));
}
let raster_count = dataset.raster_count();
for band in bands {
let is_good = *band > 0 && *band <= dataset.raster_count();
let is_good = *band > 0 && *band <= raster_count;
if !is_good {
return Err(GdalError::BadArgument(format!(
"Band index {} is out of bounds",
Expand Down

0 comments on commit dc5a90e

Please sign in to comment.