Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filling out GDALDataType metadata and utility support. #318

Merged
merged 16 commits into from Nov 10, 2022
9 changes: 8 additions & 1 deletion CHANGES.md
Expand Up @@ -36,9 +36,16 @@

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

- Added `GdalDataType` to provide access to metadata and supporting routines around `GDALDataType` ordinals.
- **Breaking**: `GDALDataType` is no longer `pub use` in `gdal::raster`,
as `GdalType` and `GdalDataType` sufficiently cover use cases in safe code.
Still accessible via `gdal_sys::GDALDataType`.

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

## 0.13

- Add prebuild bindings for GDAL 3.5
- Add prebuilt bindings for GDAL 3.5

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

Expand Down
8 changes: 4 additions & 4 deletions src/driver.rs
Expand Up @@ -98,7 +98,7 @@ impl Driver {
/// let ds = d.create("in-memory", 64, 64, 3)?;
/// assert_eq!(ds.raster_count(), 3);
/// assert_eq!(ds.raster_size(), (64, 64));
/// assert_eq!(ds.rasterband(1)?.band_type(), u8::gdal_type());
/// assert_eq!(ds.rasterband(1)?.band_type(), u8::gdal_ordinal());
/// # Ok(())
/// # }
/// ```
Expand Down Expand Up @@ -127,7 +127,7 @@ impl Driver {
/// let ds = d.create_with_band_type::<f64, _>("in-memory", 64, 64, 3)?;
/// assert_eq!(ds.raster_count(), 3);
/// assert_eq!(ds.raster_size(), (64, 64));
/// assert_eq!(ds.rasterband(1)?.band_type(), f64::gdal_type());
/// assert_eq!(ds.rasterband(1)?.band_type(), f64::gdal_ordinal());
/// # Ok(())
/// # }
/// ```
Expand Down Expand Up @@ -168,7 +168,7 @@ impl Driver {
/// ds.set_spatial_ref(&SpatialRef::from_epsg(4326)?)?;
/// assert_eq!(ds.raster_count(), 1);
/// assert_eq!(ds.raster_size(), (64, 64));
/// assert_eq!(ds.rasterband(1)?.band_type(), u8::gdal_type());
/// assert_eq!(ds.rasterband(1)?.band_type(), u8::gdal_ordinal());
/// assert_eq!(ds.spatial_ref()?.auth_code()?, 4326);
/// # Ok(())
/// # }
Expand Down Expand Up @@ -212,7 +212,7 @@ impl Driver {
size_x as c_int,
size_y as c_int,
bands as c_int,
T::gdal_type(),
T::gdal_ordinal(),
options_c.as_ptr(),
)
};
Expand Down
2 changes: 1 addition & 1 deletion src/raster/mdarray.rs
Expand Up @@ -164,7 +164,7 @@ impl<'a> MDArray<'a> {
let n_dst_buffer_alloc_size = 0;

let rv = unsafe {
let data_type = GDALExtendedDataTypeCreate(T::gdal_type());
let data_type = GDALExtendedDataTypeCreate(T::gdal_ordinal());

if !self.datatype().class().is_numeric() {
return Err(GdalError::UnsupportedMdDataType {
Expand Down
2 changes: 1 addition & 1 deletion src/raster/mod.rs
Expand Up @@ -91,7 +91,7 @@ pub use rasterband::{
StatisticsMinMax,
};
pub use rasterize::{rasterize, BurnSource, MergeAlgorithm, OptimizeMode, RasterizeOptions};
pub use types::{GDALDataType, GdalType};
pub use types::{AdjustedValue, GdalDataType, GdalType};
pub use warp::reproject;

/// Key/value pair for passing driver-specific creation options to
Expand Down
19 changes: 10 additions & 9 deletions src/raster/rasterband.rs
@@ -1,13 +1,14 @@
use crate::dataset::Dataset;
use crate::gdal_major_object::MajorObject;
use crate::metadata::Metadata;
use crate::raster::{GDALDataType, GdalType};
use crate::raster::GdalType;
use crate::utils::{_last_cpl_err, _last_null_pointer_err, _string};
use gdal_sys::{
self, CPLErr, GDALColorEntry, GDALColorInterp, GDALColorTableH, GDALComputeRasterMinMax,
GDALCreateColorRamp, GDALCreateColorTable, GDALDestroyColorTable, GDALGetPaletteInterpretation,
GDALGetRasterStatistics, GDALMajorObjectH, GDALPaletteInterp, GDALRIOResampleAlg, GDALRWFlag,
GDALRasterBandH, GDALRasterIOExtraArg, GDALSetColorEntry, GDALSetRasterColorTable,
GDALCreateColorRamp, GDALCreateColorTable, GDALDataType, GDALDestroyColorTable,
GDALGetPaletteInterpretation, GDALGetRasterStatistics, GDALMajorObjectH, GDALPaletteInterp,
GDALRIOResampleAlg, GDALRWFlag, GDALRasterBandH, GDALRasterIOExtraArg, GDALSetColorEntry,
GDALSetRasterColorTable,
};
use libc::c_int;
use std::ffi::CString;
Expand Down Expand Up @@ -232,7 +233,7 @@ impl<'a> RasterBand<'a> {
/// use gdal::raster::{GdalType, ResampleAlg};
/// let dataset = Dataset::open("fixtures/m_3607824_se_17_1_20160620_sub.tif")?;
/// let band1 = dataset.rasterband(1)?;
/// assert_eq!(band1.band_type(), u8::gdal_type());
/// assert_eq!(band1.band_type(), u8::gdal_ordinal());
/// let size = 4;
/// let mut buf = vec![0; size*size];
/// band1.read_into_slice::<u8>((0, 0), band1.size(), (size, size), buf.as_mut_slice(), Some(ResampleAlg::Bilinear))?;
Expand Down Expand Up @@ -272,7 +273,7 @@ impl<'a> RasterBand<'a> {
buffer.as_mut_ptr() as GDALRasterBandH,
size.0 as c_int,
size.1 as c_int,
T::gdal_type(),
T::gdal_ordinal(),
0,
0,
options_ptr,
Expand Down Expand Up @@ -302,7 +303,7 @@ impl<'a> RasterBand<'a> {
/// use gdal::raster::{GdalType, ResampleAlg};
/// let dataset = Dataset::open("fixtures/m_3607824_se_17_1_20160620_sub.tif")?;
/// let band1 = dataset.rasterband(1)?;
/// assert_eq!(band1.band_type(), u8::gdal_type());
/// assert_eq!(band1.band_type(), u8::gdal_ordinal());
/// let size = 4;
/// let buf = band1.read_as::<u8>((0, 0), band1.size(), (size, size), Some(ResampleAlg::Bilinear))?;
/// assert_eq!(buf.size, (size, size));
Expand Down Expand Up @@ -346,7 +347,7 @@ impl<'a> RasterBand<'a> {
data.as_mut_ptr() as GDALRasterBandH,
size.0 as c_int,
size.1 as c_int,
T::gdal_type(),
T::gdal_ordinal(),
0,
0,
options_ptr,
Expand Down Expand Up @@ -463,7 +464,7 @@ impl<'a> RasterBand<'a> {
buffer.data.as_ptr() as GDALRasterBandH,
buffer.size.0 as c_int,
buffer.size.1 as c_int,
T::gdal_type(),
T::gdal_ordinal(),
0,
0,
)
Expand Down