-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from jdroenner/metadata2
first version of metadata handling
- Loading branch information
Showing
9 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
extern crate gdal; | ||
|
||
fn main() { | ||
use std::path::Path; | ||
use gdal::raster::dataset::Dataset; | ||
use gdal::metadata::Metadata; | ||
|
||
let driver = gdal::raster::driver::Driver::get("mem").unwrap(); | ||
println!("driver description: {:?}", driver.get_description()); | ||
|
||
let path = Path::new("./fixtures/tinymarble.png"); | ||
let dataset = Dataset::open(path).unwrap(); | ||
println!("dataset description: {:?}", dataset.get_description()); | ||
|
||
let key = "INTERLEAVE"; | ||
let domain = "IMAGE_STRUCTURE"; | ||
let meta = dataset.get_metadata_item(key, domain); | ||
println!("domain: {:?} key: {:?} -> value: {:?}", domain, key, meta); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use libc::{c_void}; | ||
|
||
pub trait MajorObject { | ||
unsafe fn get_gdal_object_ptr(&self) -> *const c_void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use libc::{c_char, c_void, c_int}; | ||
use utils::{_string}; | ||
use std::ffi::{CString}; | ||
use gdal_major_object::MajorObject; | ||
|
||
#[link(name="gdal")] | ||
extern { | ||
fn GDALGetDescription(hGdalMayorObject: *const c_void) -> *const c_char; | ||
fn GDALGetMetadataItem(hGdalMayorObject: *const c_void, pszName: *const c_char, pszDomain: *const c_char) -> *const c_char; | ||
fn GDALSetMetadataItem(hGdalMayorObject: *const c_void, pszName: *const c_char, pszValue: *const c_char, pszDomain: *const c_char ) -> c_int; | ||
} | ||
|
||
pub trait Metadata: MajorObject { | ||
|
||
fn get_description(&self) -> Option<String>{ | ||
let c_res = unsafe { GDALGetDescription(self.get_gdal_object_ptr())}; | ||
if c_res.is_null() { | ||
None | ||
} else { | ||
Some(_string(c_res)) | ||
} | ||
} | ||
|
||
fn get_metadata_item(&self, key: &str, domain: &str) -> Option<String> { | ||
if let Ok(c_key) = CString::new(key.to_owned()) { | ||
if let Ok(c_domain) = CString::new(domain.to_owned()){ | ||
let c_res = unsafe { GDALGetMetadataItem(self.get_gdal_object_ptr(), c_key.as_ptr(), c_domain.as_ptr())}; | ||
if !c_res.is_null() { | ||
return Some(_string(c_res)); | ||
} | ||
} | ||
} | ||
None | ||
} | ||
|
||
fn set_metadata_item(&mut self, key: &str, value: &str, domain: &str) -> Result<(), ()> { | ||
if let Ok(c_key) = CString::new(key.to_owned()){ | ||
if let Ok(c_domain) = CString::new(domain.to_owned()){ | ||
if let Ok(c_value) = CString::new(value.to_owned()){ | ||
let c_res = unsafe { GDALSetMetadataItem(self.get_gdal_object_ptr(), c_key.as_ptr(), c_value.as_ptr(), c_domain.as_ptr())}; | ||
if c_res == 0 { | ||
return Ok(()); | ||
} | ||
} | ||
} | ||
} | ||
Err(()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters