-
Notifications
You must be signed in to change notification settings - Fork 94
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
A Consistent and Principled Approach to GDAL C Pointers #445
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[alias] | ||
# Run doctests, displaying compiler output | ||
# doc-test-output: Run doctests, displaying compiler output | ||
dto = "test --doc -- --show-output" | ||
# Run clippy, raising warnings to errors | ||
nowarn = "clippy --all-targets -- -D warnings" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
<PAMDataset> | ||
<SRS dataAxisToSRSAxisMapping="2,1">GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]</SRS> | ||
<PAMRasterBand band="1"> | ||
<Metadata> | ||
<MDI key="STATISTICS_MAXIMUM">255</MDI> | ||
<MDI key="STATISTICS_MEAN">68.4716</MDI> | ||
<MDI key="STATISTICS_MINIMUM">0</MDI> | ||
<MDI key="STATISTICS_STDDEV">83.68444773935</MDI> | ||
<MDI key="STATISTICS_VALID_PERCENT">100</MDI> | ||
</Metadata> | ||
</PAMRasterBand> | ||
</PAMDataset> |
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 |
---|---|---|
|
@@ -6,9 +6,10 @@ use std::marker::PhantomData; | |
use gdal_sys::CPLErr; | ||
|
||
use crate::errors::Result; | ||
use crate::spatial_ref::SpatialRef; | ||
use crate::spatial_ref::{SpatialRef, SpatialRefRef}; | ||
use crate::utils::{_last_cpl_err, _string}; | ||
use crate::Dataset; | ||
use foreign_types::{ForeignType, ForeignTypeRef}; | ||
|
||
/// An owned Ground Control Point. | ||
#[derive(Clone, Debug, PartialEq, PartialOrd)] | ||
|
@@ -120,8 +121,9 @@ impl Dataset { | |
if c_ptr.is_null() { | ||
return None; | ||
} | ||
|
||
unsafe { SpatialRef::from_c_obj(c_ptr) }.ok() | ||
// NB: Creating a `SpatialRefRef` from a pointer acknowledges that GDAL is giving us | ||
// a shared reference. We then call `to_owned` to appropriately get a clone. | ||
Some(unsafe { SpatialRefRef::from_ptr(c_ptr) }.to_owned()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lnicola said in 7db2868#r128939164
|
||
} | ||
|
||
/// Get the projection definition string for the GCPs in this dataset. | ||
|
@@ -207,7 +209,7 @@ impl Dataset { | |
self.c_dataset(), | ||
len, | ||
gdal_gcps.as_ptr(), | ||
spatial_ref.to_c_hsrs() as *mut _, | ||
spatial_ref.as_ptr() as *mut _, | ||
) | ||
}; | ||
|
||
|
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,38 @@ | ||
//! Raster ground control point support | ||
|
||
use foreign_types::ForeignTypeRef; | ||
use crate::spatial_ref::SpatialRefRef; | ||
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<&SpatialRefRef> { | ||
let c_ptr = unsafe { gdal_sys::GDALGetGCPSpatialRef(self.c_dataset()) }; | ||
|
||
if c_ptr.is_null() { | ||
return None; | ||
} | ||
|
||
Some(unsafe { SpatialRefRef::from_ptr(c_ptr) }) | ||
} | ||
} | ||
|
||
#[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
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'll revert this.