Skip to content

Commit

Permalink
Extracted CoordTransform.
Browse files Browse the repository at this point in the history
  • Loading branch information
metasim committed May 9, 2023
1 parent 9852005 commit 3af5834
Show file tree
Hide file tree
Showing 9 changed files with 396 additions and 380 deletions.
5 changes: 3 additions & 2 deletions examples/read_write_ogr.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use gdal::errors::Result;
use gdal::spatial_ref::{CoordTransform, SpatialRef};
use gdal::spatial_ref::SpatialRef;
use gdal::Dataset;
use gdal::{vector::*, DriverManager};
use gdal::{DriverManager, vector::*};
use std::fs;
use std::path::Path;
use gdal::spatial_ref::CoordTransform;

fn run() -> Result<()> {
let dataset_a = Dataset::open(Path::new("fixtures/roads.geojson"))?;
Expand Down
3 changes: 2 additions & 1 deletion examples/spatial_reference.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use gdal::errors::Result;
use gdal::spatial_ref::{CoordTransform, SpatialRef};
use gdal::spatial_ref::SpatialRef;
use gdal::spatial_ref::CoordTransform;
use gdal::vector::Geometry;

fn run() -> Result<()> {
Expand Down
10 changes: 5 additions & 5 deletions src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl Dataset {
#[cfg(major_ge_3)]
/// Set the spatial reference system for this dataset.
pub fn set_spatial_ref(&mut self, spatial_ref: &SpatialRef) -> Result<()> {
let rv = unsafe { gdal_sys::GDALSetSpatialRef(self.c_dataset, spatial_ref.to_c_hsrs()) };
let rv = unsafe { gdal_sys::GDALSetSpatialRef(self.c_dataset, spatial_ref.c_handle()) };
if rv != CPLErr::CE_None {
return Err(_last_cpl_err(rv));
}
Expand Down Expand Up @@ -660,10 +660,6 @@ impl Dataset {
/// ```
pub fn create_layer(&mut self, options: LayerOptions<'_>) -> Result<Layer> {
let c_name = CString::new(options.name)?;
let c_srs = match options.srs {
Some(srs) => srs.to_c_hsrs(),
None => null_mut(),
};

// Handle string options: we need to keep the CStrings and the pointers around.
let c_options = options.options.map(|d| {
Expand All @@ -686,6 +682,10 @@ impl Dataset {
};

let c_layer = unsafe {
let c_srs = match options.srs {
Some(srs) => srs.c_handle(),
None => null_mut(),
};
// The C function takes `char **papszOptions` without mention of `const`, and this is
// propagated to the gdal_sys wrapper. The lack of `const` seems like a mistake in the
// GDAL API, so we just do a cast here.
Expand Down
6 changes: 4 additions & 2 deletions src/spatial_ref/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
//! <https://gdal.org/api/ogr_srs_api.html>

mod srs;
mod transform;
mod transform_opts;

pub use srs::{AxisOrientationType, CoordTransform, SpatialRef};
pub use transform_opts::CoordTransformOptions;
pub use srs::{AxisOrientationType, SpatialRef};
pub use transform::CoordTransform;
pub use transform_opts::CoordTransformOptions;
Loading

0 comments on commit 3af5834

Please sign in to comment.