-
Notifications
You must be signed in to change notification settings - Fork 96
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
Support for accessing the SpatialRef
of GCPs.
#397
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Binary file not shown.
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,37 @@ | ||
//! Raster ground control point support | ||
|
||
use crate::spatial_ref::SpatialRef; | ||
use crate::Dataset; | ||
|
||
impl Dataset { | ||
/// Get output spatial reference system for GCPs. | ||
/// | ||
/// # Notes | ||
/// * This is separate and distinct from [`Dataset::spatial_ref`], and only applies to | ||
/// the representation of ground control points, when embedded. | ||
/// | ||
/// See: [`GDALGetGCPSpatialRef`](https://gdal.org/api/raster_c_api.html#_CPPv420GDALGetGCPSpatialRef12GDALDatasetH) | ||
pub fn gcp_spatial_ref(&self) -> Option<SpatialRef> { | ||
let c_ptr = unsafe { gdal_sys::GDALGetGCPSpatialRef(self.c_dataset()) }; | ||
|
||
if c_ptr.is_null() { | ||
return None; | ||
} | ||
|
||
unsafe { SpatialRef::from_c_obj(c_ptr) }.ok() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::test_utils::fixture; | ||
use crate::Dataset; | ||
|
||
#[test] | ||
fn test_gcp_spatial_ref() { | ||
let dataset = Dataset::open(fixture("gcp.tif")).unwrap(); | ||
let gcp_srs = dataset.gcp_spatial_ref(); | ||
let auth = gcp_srs.and_then(|s| s.authority().ok()); | ||
assert_eq!(auth.unwrap(), "EPSG:4326"); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -74,6 +74,7 @@ | |
//! ... | ||
//! ``` | ||
|
||
mod gcp; | ||
#[cfg(all(major_ge_3, minor_ge_1))] | ||
mod mdarray; | ||
mod rasterband; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is leaking theNo, it doesn't.OGRSpatialReferenceH
(check out the implementation offrom_c_obj
).Does
foreign_types
really solve issues like this? I only skimmed your changes, but it would be great if it did.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lnicola It solves it in the sense that we can more accurately reflect the owned vs borrowed semantics described in the GDAL docs, in a principled manner. After digging into the
Layer
andMDArray
bindings, I'm pretty sure we're either leaking resources or dangerously borrowing them (no proof yet, just suspicion). Usingforeign_types
would also replaceGeometryRef
andOwnedLayer
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be awesome, I'll try to look into it.