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

Move ffi into a seperate crate. #26

Merged
merged 2 commits into from
Jan 2, 2017
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
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ repository = "https://github.com/georust/rust-gdal"
documentation = "https://georust.github.io/rust-gdal/"

[dependencies]
libc = "0.2.13"
libc = "0.2.13"
geo = "0.0.5"
gdal-sys = { path = "gdal-sys", version = "0.1.0"}

[workspace]
members = ["gdal-sys"]
7 changes: 7 additions & 0 deletions gdal-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "gdal-sys"
version = "0.1.0"
authors = ["Johannes Drönner <[email protected]>"]

[dependencies]
libc = "0.2.13"
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions gdal-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extern crate libc;

// gdal modules
pub mod gdal;
pub mod gdal_enums;

// OGR modules
pub mod ogr;
File renamed without changes.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

extern crate libc;
extern crate geo;
extern crate gdal_sys;

pub use version::version_info;

Expand Down
69 changes: 35 additions & 34 deletions src/raster/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ use libc::{c_int, c_double, c_void};
use std::ffi::CString;
use std::path::Path;
use utils::_string;
use raster::{gdal, Driver, RasterBand};
use raster::{Driver, RasterBand};
use raster::driver::_register_drivers;
use raster::gdal_enums::{GDALAccess, GDALDataType};
use raster::gdal_enums::{GDALAccess, GDALDataType};
use raster::types::GdalType;
use gdal_major_object::MajorObject;
use metadata::Metadata;
use gdal_sys::gdal;

pub type GeoTransform = [c_double; 6];

Expand All @@ -16,13 +17,13 @@ pub struct Dataset {
}

impl MajorObject for Dataset {
unsafe fn gdal_object_ptr(&self) -> *const c_void {
unsafe fn gdal_object_ptr(&self) -> *const c_void {
self.c_dataset
}
}

impl Metadata for Dataset {}

impl Drop for Dataset {
fn drop(&mut self) {
unsafe { gdal::GDALClose(self.c_dataset); }
Expand All @@ -48,22 +49,22 @@ impl Dataset {

pub unsafe fn _c_ptr(&self) -> *const c_void {
return self.c_dataset;
}
pub fn rasterband<'a>(&'a self, band_index: isize) -> Option<RasterBand<'a>> {
unsafe {
let c_band = gdal::GDALGetRasterBand(self.c_dataset, band_index as c_int);
if c_band.is_null() {
return None;
}
Some(RasterBand::_with_c_ptr(c_band, self))
}
}
pub fn size(&self) -> (usize, usize) {
let size_x = unsafe { gdal::GDALGetRasterXSize(self.c_dataset) } as usize;
let size_y = unsafe { gdal::GDALGetRasterYSize(self.c_dataset) } as usize;
}


pub fn rasterband<'a>(&'a self, band_index: isize) -> Option<RasterBand<'a>> {
unsafe {
let c_band = gdal::GDALGetRasterBand(self.c_dataset, band_index as c_int);
if c_band.is_null() {
return None;
}
Some(RasterBand::_with_c_ptr(c_band, self))
}
}

pub fn size(&self) -> (usize, usize) {
let size_x = unsafe { gdal::GDALGetRasterXSize(self.c_dataset) } as usize;
let size_y = unsafe { gdal::GDALGetRasterYSize(self.c_dataset) } as usize;
return (size_x, size_y);
}

Expand Down Expand Up @@ -132,11 +133,11 @@ impl Dataset {
true => None,
false => Some(Dataset{c_dataset: c_dataset}),
};
}
pub fn band_type(&self, band_index: isize) -> Option<GDALDataType> {
self.rasterband(band_index).map(|band| band.band_type())
}
}

pub fn band_type(&self, band_index: isize) -> Option<GDALDataType> {
self.rasterband(band_index).map(|band| band.band_type())
}

/// Read a 'Buffer<u8>' from a 'Dataset'.
/// # Arguments
Expand All @@ -149,7 +150,7 @@ impl Dataset {
window: (isize, isize),
window_size: (usize, usize),
size: (usize, usize)
) -> Option<ByteBuffer>
) -> Option<ByteBuffer>
{
self.read_raster_as::<u8>(
band_index,
Expand All @@ -165,10 +166,10 @@ impl Dataset {
pub fn read_full_raster_as<T: Copy + GdalType>(
&self,
band_index: isize,
) -> Option<Buffer<T>>
) -> Option<Buffer<T>>
{
self.rasterband(band_index).map(|band| band.read_band_as())
}
self.rasterband(band_index).map(|band| band.read_band_as())
}

/// Read a 'Buffer<T>' from a 'Dataset'. T implements 'GdalType'
/// # Arguments
Expand All @@ -182,9 +183,9 @@ impl Dataset {
window: (isize, isize),
window_size: (usize, usize),
size: (usize, usize),
) -> Option<Buffer<T>>
) -> Option<Buffer<T>>
{
self.rasterband(band_index).map(|band| band.read_as(window, window_size, size))
self.rasterband(band_index).map(|band| band.read_as(window, window_size, size))
}

/// Write a 'Buffer<T>' into a 'Dataset'.
Expand All @@ -199,9 +200,9 @@ impl Dataset {
window_size: (usize, usize),
buffer: Buffer<T>
) {
self.rasterband(band_index).expect("Invalid RasterBand").write(window, window_size, buffer)
self.rasterband(band_index).expect("Invalid RasterBand").write(window, window_size, buffer)
}

}

pub struct Buffer<T: GdalType> {
Expand All @@ -215,4 +216,4 @@ impl<T: GdalType> Buffer<T> {
}
}

pub type ByteBuffer = Buffer<u8>;
pub type ByteBuffer = Buffer<u8>;
4 changes: 2 additions & 2 deletions src/raster/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use libc::{c_int, c_void};
use std::ffi::CString;
use std::sync::{Once, ONCE_INIT};
use utils::_string;
use raster::{gdal, Dataset};
use raster::{Dataset};
use raster::types::GdalType;
use gdal_major_object::MajorObject;
use metadata::Metadata;

use gdal_sys::gdal;

static START: Once = ONCE_INIT;
static mut registered_drivers: bool = false;
Expand Down
12 changes: 6 additions & 6 deletions src/raster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

pub use raster::dataset::{Dataset, Buffer, ByteBuffer};
pub use raster::driver::Driver;
pub use raster::warp::reproject;
pub use raster::rasterband::{RasterBand};
pub use raster::warp::reproject;
pub use raster::rasterband::{RasterBand};

pub use gdal_sys::gdal_enums;

mod gdal;
mod types;
mod gdal_enums;
pub mod dataset;
pub mod driver;
pub mod warp;
pub mod rasterband;
pub mod warp;
pub mod rasterband;

#[cfg(test)]
mod tests;
3 changes: 2 additions & 1 deletion src/raster/rasterband.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use libc::{c_int, c_void};
use raster::{gdal, Dataset, Buffer};
use raster::{Dataset, Buffer};
use raster::types::{GdalType};
use raster::gdal_enums;
use gdal_major_object::MajorObject;
use metadata::Metadata;
use gdal_sys::gdal;

pub struct RasterBand<'a> {
c_rasterband: *const c_void,
Expand Down
3 changes: 2 additions & 1 deletion src/raster/warp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use libc::c_double;
use std::ptr::null;
use raster::{gdal, Dataset};
use raster::{Dataset};
use raster::gdal_enums::GDALResampleAlg;
use gdal_sys::gdal;

pub fn reproject(src: &Dataset, dst: &Dataset) {
let rv = unsafe {
Expand Down
3 changes: 2 additions & 1 deletion src/vector/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::ffi::CString;
use std::path::Path;
use std::ptr::null;
use libc::{c_int, c_void};
use vector::{ogr, Layer};
use vector::{Layer};
use vector::driver::_register_drivers;
use gdal_major_object::MajorObject;
use metadata::Metadata;
use gdal_sys::ogr;

/// Vector dataset
///
Expand Down
2 changes: 1 addition & 1 deletion src/vector/defn.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use libc::{c_int, c_void};
use utils::_string;
use vector::ogr;
use gdal_sys::ogr;

/// Layer definition
///
Expand Down
3 changes: 2 additions & 1 deletion src/vector/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::ptr::null;
use std::sync::{Once, ONCE_INIT};
use std::path::Path;
use libc::{c_void};
use vector::{ogr, Dataset};
use vector::{Dataset};
use gdal_sys::ogr;


static START: Once = ONCE_INIT;
Expand Down
2 changes: 1 addition & 1 deletion src/vector/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ffi::CString;
use libc::{c_void};
use vector::Defn;
use utils::_string;
use vector::ogr;
use gdal_sys::ogr;
use vector::geometry::Geometry;


Expand Down
3 changes: 2 additions & 1 deletion src/vector/gdal_to_geo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use vector::{Geometry, ogr};
use vector::{Geometry};
use geo;
use gdal_sys::ogr;

impl geo::ToGeo for Geometry {
fn to_geo(&self) -> geo::Geometry {
Expand Down
3 changes: 2 additions & 1 deletion src/vector/geo_to_gdal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use libc::c_int;
use vector::{Geometry, ToGdal, ogr};
use vector::{Geometry, ToGdal};
use geo;
use gdal_sys::ogr;

impl ToGdal for geo::Point {
fn to_gdal(&self) -> Geometry {
Expand Down
2 changes: 1 addition & 1 deletion src/vector/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use libc::{c_char, c_int, c_double, c_void};
use std::ffi::CString;
use std::cell::RefCell;
use utils::_string;
use vector::ogr;
use gdal_sys::ogr;

/// OGR Geometry
pub struct Geometry {
Expand Down
3 changes: 2 additions & 1 deletion src/vector/layer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::ptr::null;
use libc::{c_void};
use vector::{ogr, Feature, Geometry};
use vector::{Feature, Geometry};
use vector::defn::Defn;
use gdal_major_object::MajorObject;
use metadata::Metadata;
use gdal_sys::ogr;

/// Layer in a vector dataset
///
Expand Down
1 change: 0 additions & 1 deletion src/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub trait ToGdal {
fn to_gdal(&self) -> Geometry;
}

mod ogr;
mod driver;
mod dataset;
mod layer;
Expand Down