Skip to content

Commit

Permalink
Merge pull request #182 from georust/pr/rmanoka/161
Browse files Browse the repository at this point in the history
make #161 compatible with main
  • Loading branch information
jdroenner authored Apr 25, 2021
2 parents 9bd2b3d + 52951a1 commit dba29c9
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 172 deletions.
256 changes: 143 additions & 113 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,67 @@
# Changes

## Unreleased
* **Breaking**: Upgrade to `ndarray 0.15`
* <https://github.com/georust/gdal/pull/175>
* Implement wrapper for `OGR_L_TestCapability`
* <https://github.com/georust/gdal/pull/160>
* **Breaking**: Use `DatasetOptions` to pass as `Dataset::open_ex` parameters and
add support for extended open flags.

```rust
use gdal::{ Dataset, DatasetOptions }

let dataset = Dataset::open_ex(
"roads.geojson",
DatasetOptions {
open_flags: GdalOpenFlags::GDAL_OF_UPDATE|GdalOpenFlags::GDAL_OF_VECTOR,
..DatasetOptions::default()
}
)
.unwrap();
```

`GDALAccess` values are supported usinf [`From`] implementation

```rust
Dataset::open_ex(
"roads.geojson",
DatasetOptions {
open_flags: GDALAccess::GA_Update.into(),
..DatasetOptions::default()
},
)
.unwrap();
```

* Add more functions to SpatialRef implementation
* <https://github.com/georust/gdal/pull/145>
* **Breaking**: Change `Feature::field` return type from

- **Breaking**: Make `Layer::features` iterator reset to
beginning, and borrow mutably.

- closes <https://github.com/georust/gdal/issues/159>

- **Breaking**: [Enforce borrow
semantics](https://github.com/georust/gdal/pull/161) on
methods of `Dataset`, `RasterBand`, and `Layer`.

1. Methods that do not modify the underlying structure take `&self`.
1. Methods that modify the underlying structure take `&mut self`.

```rust
let ds = Dataset::open(...);

// ds need not be mutable to open layer
let mut band = ds.rasterband(1)?;

// band needs to be mutable to set no-data value
band.set_no_data_value(0.0)?;
```

- **Breaking**: Upgrade to `ndarray 0.15`
- <https://github.com/georust/gdal/pull/175>
- Implement wrapper for `OGR_L_TestCapability`

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

- **Breaking**: Use `DatasetOptions` to pass as `Dataset::open_ex` parameters and
add support for extended open flags.

```rust
use gdal::{ Dataset, DatasetOptions }

let dataset = Dataset::open_ex(
"roads.geojson",
DatasetOptions {
open_flags: GdalOpenFlags::GDAL_OF_UPDATE|GdalOpenFlags::GDAL_OF_VECTOR,
..DatasetOptions::default()
}
)
.unwrap();
```

`GDALAccess` values are supported using [`From`] implementation

```rust
Dataset::open_ex(
"roads.geojson",
DatasetOptions {
open_flags: GDALAccess::GA_Update.into(),
..DatasetOptions::default()
},
)
.unwrap();
```

- Add more functions to SpatialRef implementation
- <https://github.com/georust/gdal/pull/145>
- **Breaking**: Change `Feature::field` return type from
`Result<FieldValue>` to `Result<Option<FieldValue>>`. Fields
can be null. Before this change, if a field was null, the value
returned was the default value for the underlying type.
Expand Down Expand Up @@ -66,96 +91,101 @@
.into_string()
.unwrap();
```
* <https://github.com/georust/gdal/pull/134>
* Fixed potential race condition wrt. GDAL driver initialization
* <https://github.com/georust/gdal/pull/166>
* Add basic support to read overviews
* Added a `Dataset::build_overviews` method
* <https://github.com/georust/gdal/pull/164>
* BREAKING: update geo-types to 0.7.0. geo-types Coordinate<T> now implement `Debug`
* <https://github.com/georust/gdal/pull/146>
* Deprecated `SpatialRef::get_axis_mapping_strategy` - migrate to

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

- Fixed potential race condition wrt. GDAL driver initialization
- <https://github.com/georust/gdal/pull/166>
- Add basic support to read overviews
- Added a `Dataset::build_overviews` method
- <https://github.com/georust/gdal/pull/164>
- BREAKING: update geo-types to 0.7.0. geo-types Coordinate<T> now implement `Debug`
- <https://github.com/georust/gdal/pull/146>
- Deprecated `SpatialRef::get_axis_mapping_strategy` - migrate to
`SpatialRef::axis_mapping_strategy` instead.
* Add support for reading and setting rasterband colour interpretations
* <https://github.com/georust/gdal/pull/144>
* Fixed memory leak in `Geometry::from_wkt`
* <https://github.com/georust/gdal/pull/172>
- Add support for reading and setting rasterband colour interpretations
- <https://github.com/georust/gdal/pull/144>
- Fixed memory leak in `Geometry::from_wkt`
- <https://github.com/georust/gdal/pull/172>

## 0.7.1
* fix docs.rs build for gdal-sys
* <https://github.com/georust/gdal/pull/128>

- fix docs.rs build for gdal-sys
- <https://github.com/georust/gdal/pull/128>

## 0.6.0 - 0.7.0
* Dataset layer iteration and FieldValue types
* https://github.com/georust/gdal/pull/126
* Fix i8 ptr instead of c_char ptr passed to OSRImportFromESRI()
* <https://github.com/georust/gdal/pull/123>
* Rename spatial_reference to spatial_ref
* <https://github.com/georust/gdal/pull/114>
* Replace get_extent force flag by get_extent and try_get_extent
* <https://github.com/georust/gdal/pull/113>
* Add support for transactions on datasets
* <https://github.com/georust/gdal/pull/109>
* Add feature_count{,_force} and implement Iterator::size_hint
* <https://github.com/georust/gdal/pull/108>
* Replace failure with thiserror
* <https://github.com/georust/gdal/pull/103>
* Ability to read into preallocated slice for rasterband
* <https://github.com/georust/gdal/pull/100>
* Datasets are Send (requires GDAL >= 2.3)
* <https://github.com/georust/gdal/pull/99>
* User GDALOpenEx
* <https://github.com/georust/gdal/pull/97>
* GDAL 2.0 conform structure / drop GDAL 1.x
* <https://github.com/georust/gdal/pull/96>
* Inplace functions use mutable refs
* <https://github.com/georust/gdal/pull/93>
* Detect GDAL version at build time / remove version features
* <https://github.com/georust/gdal/pull/92>
* Add support for delaunay_triangulation and simplify functions
* <https://github.com/georust/gdal/pull/91>
* Add support for 3d points
* <https://github.com/georust/gdal/pull/90>
* Additional metadata retrieval options
* <https://github.com/georust/gdal/pull/88>
* Support for GDAL 3 in CI
* <https://github.com/georust/gdal/pull/86>
* Support for Integer64
* <https://github.com/georust/gdal/pull/80>
* Geometry Intersection trait
* <https://github.com/georust/gdal/pull/78>
* Rust 2018
* <https://github.com/georust/gdal/pull/75>
* support for date and time fields
* <https://github.com/georust/gdal/pull/72>
* Prebuild bindings
* <https://github.com/georust/gdal/pull/69>
* Support for ndarray
* <https://github.com/georust/gdal/pull/68>

- Dataset layer iteration and FieldValue types
- https://github.com/georust/gdal/pull/126
- Fix i8 ptr instead of c_char ptr passed to OSRImportFromESRI()
- <https://github.com/georust/gdal/pull/123>
- Rename spatial_reference to spatial_ref
- <https://github.com/georust/gdal/pull/114>
- Replace get_extent force flag by get_extent and try_get_extent
- <https://github.com/georust/gdal/pull/113>
- Add support for transactions on datasets
- <https://github.com/georust/gdal/pull/109>
- Add feature_count{,\_force} and implement Iterator::size_hint
- <https://github.com/georust/gdal/pull/108>
- Replace failure with thiserror
- <https://github.com/georust/gdal/pull/103>
- Ability to read into preallocated slice for rasterband
- <https://github.com/georust/gdal/pull/100>
- Datasets are Send (requires GDAL >= 2.3)
- <https://github.com/georust/gdal/pull/99>
- User GDALOpenEx
- <https://github.com/georust/gdal/pull/97>
- GDAL 2.0 conform structure / drop GDAL 1.x
- <https://github.com/georust/gdal/pull/96>
- Inplace functions use mutable refs
- <https://github.com/georust/gdal/pull/93>
- Detect GDAL version at build time / remove version features
- <https://github.com/georust/gdal/pull/92>
- Add support for delaunay_triangulation and simplify functions
- <https://github.com/georust/gdal/pull/91>
- Add support for 3d points
- <https://github.com/georust/gdal/pull/90>
- Additional metadata retrieval options
- <https://github.com/georust/gdal/pull/88>
- Support for GDAL 3 in CI
- <https://github.com/georust/gdal/pull/86>
- Support for Integer64
- <https://github.com/georust/gdal/pull/80>
- Geometry Intersection trait
- <https://github.com/georust/gdal/pull/78>
- Rust 2018
- <https://github.com/georust/gdal/pull/75>
- support for date and time fields
- <https://github.com/georust/gdal/pull/72>
- Prebuild bindings
- <https://github.com/georust/gdal/pull/69>
- Support for ndarray
- <https://github.com/georust/gdal/pull/68>

## 0.5.0

* [Bump geo-types from 0.3 -> 0.4](https://github.com/georust/gdal/pull/71)
* [Allow reading block-size of Rasters](https://github.com/georust/gdal/pull/67)
* [Add prebuilt-bindings GDAL 2.3 and GDAL 2.4](https://github.com/georust/gdal/pull/69)
* [Make GdalType trait public](https://github.com/georust/gdal/pull/66)
* [RasterBand to Ndarray, with failure](https://github.com/georust/gdal/pull/68)
- [Bump geo-types from 0.3 -> 0.4](https://github.com/georust/gdal/pull/71)
- [Allow reading block-size of Rasters](https://github.com/georust/gdal/pull/67)
- [Add prebuilt-bindings GDAL 2.3 and GDAL 2.4](https://github.com/georust/gdal/pull/69)
- [Make GdalType trait public](https://github.com/georust/gdal/pull/66)
- [RasterBand to Ndarray, with failure](https://github.com/georust/gdal/pull/68)

## 0.4.0
* [Migrate to the `geo-types` crate](https://github.com/georust/gdal/pull/60)
* [Replace `error-chain` with `failure`](https://github.com/georust/gdal/pull/58)
* [Use `bindgen` to generate the low-level bindings](https://github.com/georust/gdal/pull/55)

- [Migrate to the `geo-types` crate](https://github.com/georust/gdal/pull/60)
- [Replace `error-chain` with `failure`](https://github.com/georust/gdal/pull/58)
- [Use `bindgen` to generate the low-level bindings](https://github.com/georust/gdal/pull/55)

## 0.3.0

* [Add support for creating a SpatialRef from a esri "wkt" definition](https://github.com/georust/gdal/pull/37)
* [Travis now uses GDAL 2.x](https://github.com/georust/gdal/pull/36)
* [API extensions](https://github.com/georust/gdal/pull/35)
* [Extend the existing possibilities of writing ogr datasets](https://github.com/georust/gdal/pull/31)
* [Allow to transform ogr geometries to other SRS](https://github.com/georust/gdal/pull/29)
* [Move ffi into a seperate crate](https://github.com/georust/gdal/pull/26)
* [Added rasterband.rs and moved all band functions](https://github.com/georust/gdal/pull/24)
- [Add support for creating a SpatialRef from a esri "wkt" definition](https://github.com/georust/gdal/pull/37)
- [Travis now uses GDAL 2.x](https://github.com/georust/gdal/pull/36)
- [API extensions](https://github.com/georust/gdal/pull/35)
- [Extend the existing possibilities of writing ogr datasets](https://github.com/georust/gdal/pull/31)
- [Allow to transform ogr geometries to other SRS](https://github.com/georust/gdal/pull/29)
- [Move ffi into a seperate crate](https://github.com/georust/gdal/pull/26)
- [Added rasterband.rs and moved all band functions](https://github.com/georust/gdal/pull/24)

## 0.2.1

* [First version of metadata handling](https://github.com/georust/gdal/pull/21)
- [First version of metadata handling](https://github.com/georust/gdal/pull/21)
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ semver = "0.11"

[dev-dependencies]
tempfile = "3.1"
trybuild = "1.0.39"

[workspace]
members = ["gdal-sys"]
Expand Down
4 changes: 2 additions & 2 deletions examples/read_write_ogr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::fs;
use std::path::Path;

fn run() -> Result<()> {
let mut dataset_a = Dataset::open(Path::new("fixtures/roads.geojson"))?;
let layer_a = dataset_a.layer(0)?;
let dataset_a = Dataset::open(Path::new("fixtures/roads.geojson"))?;
let mut layer_a = dataset_a.layer(0)?;
let fields_defn = layer_a
.defn()
.fields()
Expand Down
4 changes: 2 additions & 2 deletions examples/read_write_ogr_datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ fn run() -> gdal::errors::Result<()> {

println!("gdal crate was build with datetime support");

let mut dataset_a = Dataset::open(Path::new("fixtures/points_with_datetime.json"))?;
let layer_a = dataset_a.layer(0)?;
let dataset_a = Dataset::open(Path::new("fixtures/points_with_datetime.json"))?;
let mut layer_a = dataset_a.layer(0)?;

// Create a new dataset:
let path = std::env::temp_dir().join("later.geojson");
Expand Down
12 changes: 6 additions & 6 deletions src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl Dataset {
}

/// Set the projection reference string for this dataset.
pub fn set_projection(&self, projection: &str) -> Result<()> {
pub fn set_projection(&mut self, projection: &str) -> Result<()> {
let c_projection = CString::new(projection)?;
unsafe { gdal_sys::GDALSetProjection(self.c_dataset, c_projection.as_ptr()) };
Ok(())
Expand All @@ -267,7 +267,7 @@ impl Dataset {

#[cfg(major_ge_3)]
/// Set the spatial reference system for this dataset.
pub fn set_spatial_ref(&self, spatial_ref: &SpatialRef) -> Result<()> {
pub fn set_spatial_ref(&mut self, spatial_ref: &SpatialRef) -> Result<()> {
let rv = unsafe { gdal_sys::GDALSetSpatialRef(self.c_dataset, spatial_ref.to_c_hsrs()) };
if rv != CPLErr::CE_None {
return Err(_last_cpl_err(rv));
Expand Down Expand Up @@ -362,7 +362,7 @@ impl Dataset {
///
/// Applies to vector datasets, and fetches by the given
/// _0-based_ index.
pub fn layer(&mut self, idx: isize) -> Result<Layer> {
pub fn layer(&self, idx: isize) -> Result<Layer> {
let c_layer = unsafe { gdal_sys::OGR_DS_GetLayer(self.c_dataset, idx as c_int) };
if c_layer.is_null() {
return Err(_last_null_pointer_err("OGR_DS_GetLayer"));
Expand All @@ -371,7 +371,7 @@ impl Dataset {
}

/// Fetch a layer by name.
pub fn layer_by_name(&mut self, name: &str) -> Result<Layer> {
pub fn layer_by_name(&self, name: &str) -> Result<Layer> {
let c_name = CString::new(name)?;
let c_layer = unsafe { gdal_sys::OGR_DS_GetLayerByName(self.c_dataset(), c_name.as_ptr()) };
if c_layer.is_null() {
Expand Down Expand Up @@ -437,7 +437,7 @@ impl Dataset {
/// y-coordinate of the top-left corner pixel
/// column rotation (typically zero)
/// height of a pixel (y-resolution, typically negative)
pub fn set_geo_transform(&self, transformation: &GeoTransform) -> Result<()> {
pub fn set_geo_transform(&mut self, transformation: &GeoTransform) -> Result<()> {
assert_eq!(transformation.len(), 6);
let rv = unsafe {
gdal_sys::GDALSetGeoTransform(self.c_dataset, transformation.as_ptr() as *mut f64)
Expand Down Expand Up @@ -567,7 +567,7 @@ impl Dataset {
///
/// let ds = Dataset::open(Path::new("fixtures/roads.geojson")).unwrap();
/// let query = "SELECT kind, is_bridge, highway FROM roads WHERE highway = 'pedestrian'";
/// let result_set = ds.execute_sql(query, None, sql::Dialect::DEFAULT).unwrap().unwrap();
/// let mut result_set = ds.execute_sql(query, None, sql::Dialect::DEFAULT).unwrap().unwrap();
///
/// assert_eq!(10, result_set.feature_count());
///
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
//! use std::path::Path;
//! use gdal::Dataset;
//!
//! let mut dataset = Dataset::open(Path::new("fixtures/roads.geojson")).unwrap();
//! let layer = dataset.layer(0).unwrap();
//! let dataset = Dataset::open(Path::new("fixtures/roads.geojson")).unwrap();
//! let mut layer = dataset.layer(0).unwrap();
//! for feature in layer.features() {
//! let highway_field = feature.field("highway").unwrap().unwrap();
//! let geometry = feature.geometry();
Expand Down
4 changes: 2 additions & 2 deletions src/raster/rasterband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<'a> RasterBand<'a> {
/// * window - the window position from top left
/// * window_size - the window size (GDAL will interpolate data if window_size != Buffer.size)
pub fn write<T: GdalType + Copy>(
&self,
&mut self,
window: (isize, isize),
window_size: (usize, usize),
buffer: &Buffer<T>,
Expand Down Expand Up @@ -254,7 +254,7 @@ impl<'a> RasterBand<'a> {
}

/// Set the no data value of this band.
pub fn set_no_data_value(&self, no_data: f64) -> Result<()> {
pub fn set_no_data_value(&mut self, no_data: f64) -> Result<()> {
let rv = unsafe { gdal_sys::GDALSetRasterNoDataValue(self.c_rasterband, no_data) };
if rv != CPLErr::CE_None {
return Err(_last_cpl_err(rv));
Expand Down
Loading

0 comments on commit dba29c9

Please sign in to comment.