Skip to content

Commit

Permalink
Merge pull request #75 from georust/modernize
Browse files Browse the repository at this point in the history
Modernize the GDAL crate
  • Loading branch information
jdroenner authored Jul 9, 2020
2 parents 56cf139 + efd060f commit 31fd553
Show file tree
Hide file tree
Showing 38 changed files with 12,078 additions and 742 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ authors = [
]
repository = "https://github.com/georust/gdal"
documentation = "https://georust.github.io/gdal/"
edition = "2018"

[features]
bindgen = ["gdal-sys/bindgen"]
gdal_2_2 = ["gdal-sys/min_gdal_version_2_2"]
gdal_2_4 = ["gdal-sys/min_gdal_version_2_4"]
gdal_3_0 = ["gdal-sys/min_gdal_version_3_0"]
array = ["ndarray"]
datetime = ["chrono"]

Expand All @@ -21,8 +24,8 @@ failure = "0.1"
failure_derive = "0.1"
libc = "0.2"
geo-types = "0.4"
# gdal-sys = { path = "gdal-sys", version = "0.2"}
gdal-sys = "0.2"
gdal-sys = { path = "gdal-sys", version = "0.2"}
#gdal-sys = "0.2"
num-traits = "0.2"
ndarray = {version = "0.12.1", optional = true }
chrono = { version = "0.4", optional = true }
Expand Down
7 changes: 2 additions & 5 deletions examples/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
extern crate gdal;

fn main() {
use std::path::Path;
use gdal::raster::dataset::Dataset;
use gdal::metadata::Metadata;
use gdal::raster::dataset::Dataset;
use std::path::Path;

let driver = gdal::raster::driver::Driver::get("mem").unwrap();
println!("driver description: {:?}", driver.description());
Expand All @@ -16,5 +14,4 @@ fn main() {
let domain = "IMAGE_STRUCTURE";
let meta = dataset.metadata_item(key, domain);
println!("domain: {:?} key: {:?} -> value: {:?}", domain, key, meta);

}
45 changes: 19 additions & 26 deletions examples/rasterband.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
extern crate gdal;

use std::path::Path;
use gdal::raster::{Dataset, RasterBand};
use gdal::metadata::Metadata;

fn main() {

let path = Path::new("./fixtures/tinymarble.png");
let dataset = Dataset::open(path).unwrap();
println!("dataset description: {:?}", dataset.description());

let rasterband: RasterBand = dataset.rasterband(1).unwrap();
println!("rasterband description: {:?}", rasterband.description());
println!("rasterband no_data_value: {:?}", rasterband.no_data_value());
println!("rasterband type: {:?}", rasterband.band_type());
println!("rasterband scale: {:?}", rasterband.scale());
println!("rasterband offset: {:?}", rasterband.offset());
if let Ok(rv) = rasterband.read_as::<u8>(
(20, 30),
(2, 3),
(2, 3)
) {
println!("{:?}", rv.data);
}
}
use gdal::metadata::Metadata;
use gdal::raster::{Dataset, RasterBand};
use std::path::Path;

fn main() {
let path = Path::new("./fixtures/tinymarble.png");
let dataset = Dataset::open(path).unwrap();
println!("dataset description: {:?}", dataset.description());

let rasterband: RasterBand = dataset.rasterband(1).unwrap();
println!("rasterband description: {:?}", rasterband.description());
println!("rasterband no_data_value: {:?}", rasterband.no_data_value());
println!("rasterband type: {:?}", rasterband.band_type());
println!("rasterband scale: {:?}", rasterband.scale());
println!("rasterband offset: {:?}", rasterband.offset());
if let Ok(rv) = rasterband.read_as::<u8>((20, 30), (2, 3), (2, 3)) {
println!("{:?}", rv.data);
}
}
16 changes: 8 additions & 8 deletions examples/read_write_ogr.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
extern crate gdal;

use std::fs;
use std::path::Path;
use gdal::errors::Error;
use gdal::spatial_ref::{CoordTransform, SpatialRef};
use gdal::vector::*;
use gdal::spatial_ref::{SpatialRef, CoordTransform};
use std::fs;
use std::path::Path;

fn run() -> Result<(), Error> {
let mut dataset_a = Dataset::open(Path::new("fixtures/roads.geojson"))?;
let layer_a = dataset_a.layer(0)?;
let fields_defn = layer_a.defn().fields()
.map(|field| (field.name(), field.field_type(), field.width()))
.collect::<Vec<_>>();
let fields_defn = layer_a
.defn()
.fields()
.map(|field| (field.name(), field.field_type(), field.width()))
.collect::<Vec<_>>();

// Create a new dataset:
let _ = fs::remove_file("/tmp/abcde.shp");
Expand Down
44 changes: 19 additions & 25 deletions examples/read_write_ogr_datetime.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@

extern crate gdal;
#[cfg(feature = "datetime")]
extern crate chrono;

use std::path::Path;
use chrono::Duration;
use gdal::errors::Error;
use gdal::vector::*;
use std::fs;
#[cfg(feature = "datetime")]
use chrono::Duration;
use std::ops::Add;
use std::path::Path;

#[cfg(feature = "datetime")]
fn run() -> Result<(), Error> {
Expand All @@ -19,7 +13,7 @@ fn run() -> Result<(), Error> {
let layer_a = dataset_a.layer(0)?;

// Create a new dataset:
let _ = fs::remove_file("/tmp/later.geojson");
let _ = std::fs::remove_file("/tmp/later.geojson");
let drv = Driver::get("GeoJSON")?;
let mut ds = drv.create(Path::new("/tmp/later.geojson"))?;
let lyr = ds.create_layer()?;
Expand All @@ -38,22 +32,24 @@ fn run() -> Result<(), Error> {
let mut ft = Feature::new(&defn)?;
ft.set_geometry(feature_a.geometry().clone())?;
// copy each field value of the feature:
for field in defn.fields() {
ft.set_field(&field.name(), &match feature_a.field(&field.name())? {

// add one day to dates
FieldValue::DateValue(value) => {
println!("{} = {}", field.name(), value);
FieldValue::DateValue(value.add(Duration::days(1)))
},
for field in defn.fields() {
ft.set_field(
&field.name(),
&match feature_a.field(&field.name())? {
// add one day to dates
FieldValue::DateValue(value) => {
println!("{} = {}", field.name(), value);
FieldValue::DateValue(value.add(Duration::days(1)))
}

// add 6 hours to datetimes
FieldValue::DateTimeValue(value) => {
println!("{} = {}", field.name(), value);
FieldValue::DateTimeValue(value.add(Duration::hours(6)))
// add 6 hours to datetimes
FieldValue::DateTimeValue(value) => {
println!("{} = {}", field.name(), value);
FieldValue::DateTimeValue(value.add(Duration::hours(6)))
}
v => v,
},
v => v
})?;
)?;
}
// Add the feature to the layer:
ft.create(lyr)?;
Expand All @@ -67,8 +63,6 @@ fn run() -> Result<(), Error> {
Ok(())
}


fn main() {
run().unwrap();
}

2 changes: 0 additions & 2 deletions examples/spatial_reference.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate gdal;

use gdal::spatial_ref::{CoordTransform, SpatialRef};
use gdal::vector::Geometry;

Expand Down
6 changes: 2 additions & 4 deletions examples/write_ogr.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
extern crate gdal;

use std::path::Path;
use std::fs;
use gdal::errors::Error;
use gdal::vector::{Defn, Driver, Feature, FieldDefn, FieldValue, Geometry, OGRFieldType};
use std::fs;
use std::path::Path;

/// Example 1, the detailed way:
fn example_1() -> Result<(), Error> {
Expand Down
4 changes: 3 additions & 1 deletion gdal-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ license = "MIT"
version = "0.2.4"
repository = "https://github.com/georust/gdal"
authors = ["Johannes Drönner <[email protected]>"]
edition = "2018"

[features]
default = ["min_gdal_version_1_11"]
Expand All @@ -14,10 +15,11 @@ min_gdal_version_2_1 = []
min_gdal_version_2_2 = []
min_gdal_version_2_3 = []
min_gdal_version_2_4 = []
min_gdal_version_3_0 = []

[dependencies]
libc = "0.2"

[build-dependencies]
bindgen = { version = "0.48", optional = true }
bindgen = { version = "0.54", optional = true }
pkg-config = "0.3"
6 changes: 4 additions & 2 deletions gdal-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(feature = "bindgen")]
extern crate bindgen;
extern crate pkg_config;
use bindgen;
use pkg_config;

use pkg_config::Config;
use std::env;
Expand Down Expand Up @@ -186,6 +186,8 @@ fn main() {
"prebuilt-bindings/gdal_2.3.rs",
#[cfg(feature = "min_gdal_version_2_4")]
"prebuilt-bindings/gdal_2.4.rs",
#[cfg(feature = "min_gdal_version_3_0")]
"prebuilt-bindings/gdal_3.0.rs",
];
std::fs::copy(&prebuilt_paths[prebuilt_paths.len() - 1], &out_path)
.expect("Can't copy bindings to output directory");
Expand Down
Loading

0 comments on commit 31fd553

Please sign in to comment.