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

update changes, readme #120

Merged
merged 6 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
# Changes

## 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>

## 0.5.0

* [Bump geo-types from 0.3 -> 0.4](https://github.com/georust/gdal/pull/71)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ libc = "0.2"
geo-types = "0.6"
gdal-sys = { path = "gdal-sys", version = "0.2"}
num-traits = "0.2"
ndarray = {version = "0.13", optional = true }
ndarray = {version = "0.14", optional = true }
chrono = { version = "0.4", optional = true }

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion gdal-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ edition = "2018"
libc = "0.2"

[build-dependencies]
bindgen = { version = "0.54", optional = true }
bindgen = { version = "0.56", optional = true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recently hit some surprising behavior with a bindgen update

georust/proj#53

Note sure if this affects you, or maybe you've already dealt with it, but bindgen recently changed how size_t gets translated to rust.

It used to map size_t to usize. In rust, the byte size of usize changes depending on your platform to match the pointer size. On all "first class" rust platforms the size of usize in rust is equal to sizeof size_t in C.

But there's nothing in the c standard that says size_t needs to equal pointer width. So in theory, technically, they could be different.

...so the (controversial) decision was made to output a concretely sized type (based on the size of size_t on the person running bindgen).

So, long story short, if you are packaging and relying on pre-builting bindings and want them to work on 32bit and 64bit machines, you need to enable the --size_t-is-usize option for bindgen when you're packing your pre-built bindings.

You can trace the thread back from: rust-lang/rust-bindgen#1688

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow i did not know. So if i add .size_t_is_usize(true) to bindgen in build.rs it should work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a created a PR for this: #127

Copy link
Member

@michaelkirk michaelkirk Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i add .size_t_is_usize(true) to bindgen in build.rs it should work?

Yes, my understanding is that this will maintain the behavior from 0.53 and before.

I notice you're updating from bindgen 0.54, so that ship may have already sailed, but it would have only affected your pre-built bindings if you'd regenerated the bindings when you last updated bindgen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think all the bindings are older then the last bindgen update :)

pkg-config = "0.3"
semver = "0.11"
1 change: 1 addition & 0 deletions gdal-sys/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Build Status](https://travis-ci.org/georust/gdal.png?branch=master)](https://travis-ci.org/georust/gdal)

Low level [GDAL](http://gdal.org/) bindings for [Rust](http://www.rust-lang.org/).
The build script will try to auto-dectect the installed GDAL version.

Contains:

Expand Down
17 changes: 11 additions & 6 deletions src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl Dataset {
}

pub fn layers(&self) -> LayerIterator {
return LayerIterator::with_dataset(self);
LayerIterator::with_dataset(self)
}

pub fn raster_count(&self) -> isize {
Expand Down Expand Up @@ -404,7 +404,7 @@ impl Dataset {
pub struct LayerIterator<'a> {
dataset: &'a Dataset,
idx: isize,
count: isize
count: isize,
}

impl<'a> Iterator for LayerIterator<'a> {
Expand All @@ -415,13 +415,14 @@ impl<'a> Iterator for LayerIterator<'a> {
let idx = self.idx;
if idx < self.count {
self.idx += 1;
let c_layer = unsafe { gdal_sys::OGR_DS_GetLayer(self.dataset.c_dataset, idx as c_int) };
let c_layer =
unsafe { gdal_sys::OGR_DS_GetLayer(self.dataset.c_dataset, idx as c_int) };
if !c_layer.is_null() {
let layer = unsafe { Layer::from_c_layer(self.dataset, c_layer) };
return Some(layer);
}
}
return None;
None
}

fn size_hint(&self) -> (usize, Option<usize>) {
Expand All @@ -434,7 +435,11 @@ impl<'a> Iterator for LayerIterator<'a> {

impl<'a> LayerIterator<'a> {
pub fn with_dataset(dataset: &'a Dataset) -> LayerIterator<'a> {
LayerIterator { dataset, idx: 0, count: dataset.layer_count() }
LayerIterator {
dataset,
idx: 0,
count: dataset.layer_count(),
}
}
}

Expand Down Expand Up @@ -564,7 +569,7 @@ mod tests {
.tempfile()
.unwrap()
.into_parts();
file.write(&input_data).unwrap();
file.write_all(&input_data).unwrap();
// Close the temporary file so that Dataset can open it safely even if the filesystem uses
// exclusive locking (Windows?).
drop(file);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod utils;
pub mod vector;
pub mod version;

pub use dataset::{Dataset, GeoTransform, Transaction, LayerIterator};
pub use dataset::{Dataset, GeoTransform, LayerIterator, Transaction};
pub use driver::Driver;
pub use metadata::Metadata;

Expand Down
12 changes: 4 additions & 8 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ pub trait Metadata: MajorObject {

fn metadata_domains(&self) -> Vec<String> {
let mut domains = Vec::new();
let c_res = unsafe {
gdal_sys::GDALGetMetadataDomainList(self.gdal_object_ptr())
};
let c_res = unsafe { gdal_sys::GDALGetMetadataDomainList(self.gdal_object_ptr()) };

if !c_res.is_null() {
for i in 0.. {
Expand All @@ -35,11 +33,9 @@ pub trait Metadata: MajorObject {

fn metadata_domain(&self, domain: &str) -> Option<Vec<String>> {
let mut metadata = Vec::new();
if let Ok(c_domain) = CString::new(domain.to_owned()){
let c_res = unsafe {
gdal_sys::GDALGetMetadata(self.gdal_object_ptr(),
c_domain.as_ptr())
};
if let Ok(c_domain) = CString::new(domain.to_owned()) {
let c_res =
unsafe { gdal_sys::GDALGetMetadata(self.gdal_object_ptr(), c_domain.as_ptr()) };

if c_res.is_null() {
return None;
Expand Down
2 changes: 1 addition & 1 deletion src/raster/rasterband.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl<'a> RasterBand<'a> {
)
};
if rv != CPLErr::CE_None {
return Err(_last_cpl_err(rv).into());
return Err(_last_cpl_err(rv));
}

unsafe {
Expand Down
13 changes: 10 additions & 3 deletions src/raster/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,19 @@ fn test_get_description() {
fn test_get_metadata_domains() {
let dataset = Dataset::open(fixture!("tinymarble.png")).unwrap();
let mut domains = dataset.metadata_domains();
if domains[0] == "" {
if domains[0].is_empty() {
domains.remove(0);
}

assert_eq!(domains, vec!("IMAGE_STRUCTURE", "xml:XMP",
"DERIVED_SUBDATASETS", "COLOR_PROFILE"));
assert_eq!(
domains,
vec!(
"IMAGE_STRUCTURE",
"xml:XMP",
"DERIVED_SUBDATASETS",
"COLOR_PROFILE"
)
);
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions src/raster/warp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::dataset::Dataset;
use crate::utils::_last_cpl_err;
use gdal_sys::{self, CPLErr, GDALResampleAlg};
use libc::c_double;
use std::ptr::{null, null_mut};

use crate::errors::*;
Expand All @@ -15,7 +14,7 @@ pub fn reproject(src: &Dataset, dst: &Dataset) -> Result<()> {
null(),
GDALResampleAlg::GRA_Bilinear,
0.0,
0.0 as c_double,
0.0,
None,
null_mut(),
null_mut(),
Expand Down
2 changes: 1 addition & 1 deletion src/spatial_ref/srs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::utils::{_last_cpl_err, _last_null_pointer_err, _string};
use gdal_sys::{self, CPLErr, OGRCoordinateTransformationH, OGRErr, OGRSpatialReferenceH};
use libc::{c_int, c_char};
use libc::{c_char, c_int};
use std::ffi::{CStr, CString};
use std::ptr;
use std::str::FromStr;
Expand Down
35 changes: 23 additions & 12 deletions src/vector/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ impl<'a> Feature<'a> {
OGRFieldType::OFTRealList => {
let rv = unsafe {
let mut len: i32 = 0;
let ptr = gdal_sys::OGR_F_GetFieldAsDoubleList(self.c_feature, field_id, &mut len);
let ptr =
gdal_sys::OGR_F_GetFieldAsDoubleList(self.c_feature, field_id, &mut len);
slice::from_raw_parts(ptr, len as usize).to_vec()
};
Ok(FieldValue::RealListValue(rv))
Expand All @@ -114,7 +115,8 @@ impl<'a> Feature<'a> {
OGRFieldType::OFTIntegerList => {
let rv = unsafe {
let mut len: i32 = 0;
let ptr = gdal_sys::OGR_F_GetFieldAsIntegerList(self.c_feature, field_id, &mut len);
let ptr =
gdal_sys::OGR_F_GetFieldAsIntegerList(self.c_feature, field_id, &mut len);
slice::from_raw_parts(ptr, len as usize).to_vec()
};
Ok(FieldValue::IntegerListValue(rv))
Expand All @@ -126,7 +128,8 @@ impl<'a> Feature<'a> {
OGRFieldType::OFTInteger64List => {
let rv = unsafe {
let mut len: i32 = 0;
let ptr = gdal_sys::OGR_F_GetFieldAsInteger64List(self.c_feature, field_id, &mut len);
let ptr =
gdal_sys::OGR_F_GetFieldAsInteger64List(self.c_feature, field_id, &mut len);
slice::from_raw_parts(ptr, len as usize).to_vec()
};
Ok(FieldValue::Integer64ListValue(rv))
Expand Down Expand Up @@ -344,7 +347,7 @@ impl<'a> Feature<'a> {
FieldValue::Integer64Value(value) => self.set_field_integer64(field_name, *value),

#[cfg(feature = "datetime")]
FieldValue::DateTimeValue(value) => self.set_field_datetime(field_name, value.clone()),
FieldValue::DateTimeValue(value) => self.set_field_datetime(field_name, *value),

#[cfg(feature = "datetime")]
FieldValue::DateValue(value) => {
Expand All @@ -353,7 +356,7 @@ impl<'a> Feature<'a> {
_ => Err(GdalError::UnhandledFieldType {
field_type: value.ogr_field_type(),
method_name: "OGR_Fld_GetType",
})
}),
}
}

Expand All @@ -369,8 +372,7 @@ impl<'a> Feature<'a> {
Ok(())
}
pub fn field_count(&self) -> i32 {
let count = unsafe { gdal_sys::OGR_F_GetFieldCount(self.c_feature) };
count
unsafe { gdal_sys::OGR_F_GetFieldCount(self.c_feature) }
}

pub fn fields(&self) -> FieldValueIterator {
Expand All @@ -386,7 +388,11 @@ pub struct FieldValueIterator<'a> {

impl<'a> FieldValueIterator<'a> {
pub fn with_feature(feature: &'a Feature<'a>) -> Self {
FieldValueIterator { feature, idx: 0, count: feature.field_count() }
FieldValueIterator {
feature,
idx: 0,
count: feature.field_count(),
}
}
}

Expand All @@ -398,12 +404,17 @@ impl<'a> Iterator for FieldValueIterator<'a> {
let idx = self.idx;
if idx < self.count {
self.idx += 1;
let field_defn = unsafe { gdal_sys::OGR_F_GetFieldDefnRef(self.feature.c_feature, idx) };
let field_defn =
unsafe { gdal_sys::OGR_F_GetFieldDefnRef(self.feature.c_feature, idx) };
let field_name = unsafe { gdal_sys::OGR_Fld_GetNameRef(field_defn) };
let name = _string(field_name);
let fv: Option<(String, FieldValue)> = self.feature.field_from_id(idx).ok()
let fv: Option<(String, FieldValue)> = self
.feature
.field_from_id(idx)
.ok()
.map(|field_value| (name, field_value));
if let None = fv { //skip unknown types
if fv.is_none() {
//skip unknown types
if self.idx < self.count {
return self.next();
}
Expand Down Expand Up @@ -517,7 +528,7 @@ impl FieldValue {
FieldValue::DateValue(_) => OGRFieldType::OFTDate,

#[cfg(feature = "datetime")]
FieldValue::DateTimeValue(_) => OGRFieldType::OFTDateTime
FieldValue::DateTimeValue(_) => OGRFieldType::OFTDateTime,
}
}
}
7 changes: 6 additions & 1 deletion src/vector/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ impl<'a> Iterator for FeatureIterator<'a> {
}

fn size_hint(&self) -> (usize, Option<usize>) {
match self.layer.try_feature_count().map(|s| s.try_into().ok()).flatten() {
match self
.layer
.try_feature_count()
.map(|s| s.try_into().ok())
.flatten()
{
Some(size) => (size, Some(size)),
None => (0, None),
}
Expand Down
2 changes: 1 addition & 1 deletion src/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ pub trait ToGdal {
}

#[cfg(test)]
mod tests;
mod vector_tests;
File renamed without changes.
Loading