Skip to content

Commit e58c364

Browse files
committed
docs(sedona-gdal): tighten wrapper API comments
1 parent 1f94bcb commit e58c364

4 files changed

Lines changed: 44 additions & 47 deletions

File tree

c/sedona-gdal/src/dataset.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ impl Dataset {
146146
unsafe { call_gdal_api!(self.api, GDALGetRasterCount, self.c_dataset) as usize }
147147
}
148148

149-
/// Get a raster band (1-indexed).
149+
/// Fetch a raster band by 1-indexed band number.
150+
/// Band numbers start at 1, as in GDAL.
150151
pub fn rasterband(&self, band_index: usize) -> Result<RasterBand<'_>> {
151152
let band_index_i32 = i32::try_from(band_index)?;
152153
let c_band =
@@ -157,7 +158,8 @@ impl Dataset {
157158
Ok(RasterBand::new(self.api, c_band, self))
158159
}
159160

160-
/// Get the geo-transform.
161+
/// Fetch the dataset geotransform coefficients.
162+
/// Return an error if no geotransform is available.
161163
pub fn geo_transform(&self) -> Result<[f64; 6]> {
162164
let mut gt = [0.0f64; 6];
163165
let rv = unsafe {
@@ -190,7 +192,8 @@ impl Dataset {
190192
Ok(())
191193
}
192194

193-
/// Get the projection string.
195+
/// Fetch the projection definition string for this dataset.
196+
/// Return an empty string if no projection is available.
194197
pub fn projection(&self) -> String {
195198
unsafe {
196199
let ptr = call_gdal_api!(self.api, GDALGetProjectionRef, self.c_dataset);
@@ -202,7 +205,7 @@ impl Dataset {
202205
}
203206
}
204207

205-
/// Set the projection string.
208+
/// Set the projection definition string for this dataset.
206209
pub fn set_projection(&self, projection: &str) -> Result<()> {
207210
let c_projection = CString::new(projection)?;
208211
let rv = unsafe {
@@ -219,7 +222,8 @@ impl Dataset {
219222
Ok(())
220223
}
221224

222-
/// Get the spatial reference.
225+
/// Fetch the spatial reference for this dataset.
226+
/// GDAL returns a borrowed handle; this method clones it.
223227
pub fn spatial_ref(&self) -> Result<SpatialRef> {
224228
let c_srs = unsafe { call_gdal_api!(self.api, GDALGetSpatialRef, self.c_dataset) };
225229
if c_srs.is_null() {
@@ -317,24 +321,12 @@ impl Dataset {
317321
)
318322
}
319323

320-
/// Add a raster band backed by an existing memory buffer (zero-copy).
321-
///
322-
/// This wraps `GDALAddBand` with the `DATAPOINTER`, `PIXELOFFSET`, and `LINEOFFSET`
323-
/// options, allowing you to attach existing memory to a MEM dataset without copying.
324-
///
325-
/// # Arguments
326-
/// * `data_type` - The GDAL data type of the band.
327-
/// * `data_ptr` - Pointer to the band pixel data.
328-
/// * `pixel_offset` - Byte offset between consecutive pixels. `None` defaults to the
329-
/// byte size of `data_type`.
330-
/// * `line_offset` - Byte offset between consecutive lines. `None` defaults to
331-
/// `pixel_offset * width`.
324+
/// Add a band backed by an existing memory buffer.
325+
/// Pass `DATAPOINTER`, `PIXELOFFSET`, and `LINEOFFSET` to `GDALAddBand`.
332326
///
333327
/// # Safety
334328
///
335-
/// The caller must ensure that `data_ptr` points to a valid buffer of at least
336-
/// `height * line_offset` bytes (or `height * width * data_type.byte_size()` when
337-
/// using defaults), and that the buffer outlives this dataset.
329+
/// `data_ptr` must point to valid band data that outlives this dataset.
338330
pub unsafe fn add_band_with_data(
339331
&self,
340332
data_type: RustGdalDataType,

c/sedona-gdal/src/raster/rasterband.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ impl<'a> RasterBand<'a> {
5252
self.c_rasterband
5353
}
5454

55-
/// Read a region of the band as a typed buffer.
56-
///
57-
/// If `e_resample_alg` is `None`, nearest-neighbour resampling is used.
55+
/// Read a window of this band into a typed buffer.
56+
/// If `e_resample_alg` is `None`, use nearest-neighbour resampling.
5857
pub fn read_as<T: GdalType + Copy>(
5958
&self,
6059
window: (isize, isize),
@@ -137,24 +136,24 @@ impl<'a> RasterBand<'a> {
137136
Ok(())
138137
}
139138

140-
/// Get the data type of this band.
139+
/// Fetch this band's data type.
141140
pub fn band_type(&self) -> GdalDataType {
142141
GdalDataType::from_c(self.c_band_type()).unwrap_or(GdalDataType::Unknown)
143142
}
144143

145-
/// Get the GDAL data type of this band.
144+
/// Fetch this band's raw GDAL data type.
146145
pub fn c_band_type(&self) -> GDALDataType {
147146
unsafe { call_gdal_api!(self.api, GDALGetRasterDataType, self.c_rasterband) }
148147
}
149148

150-
/// Get band size as (x_size, y_size).
149+
/// Fetch band size as `(x_size, y_size)`.
151150
pub fn size(&self) -> (usize, usize) {
152151
let x = unsafe { call_gdal_api!(self.api, GDALGetRasterBandXSize, self.c_rasterband) };
153152
let y = unsafe { call_gdal_api!(self.api, GDALGetRasterBandYSize, self.c_rasterband) };
154153
(x as usize, y as usize)
155154
}
156155

157-
/// Get the block size as (x_size, y_size).
156+
/// Fetch the natural block size as `(x_size, y_size)`.
158157
pub fn block_size(&self) -> (usize, usize) {
159158
let mut x: i32 = 0;
160159
let mut y: i32 = 0;
@@ -170,7 +169,8 @@ impl<'a> RasterBand<'a> {
170169
(x as usize, y as usize)
171170
}
172171

173-
/// Get the no-data value. Returns `Some(value)` if set, `None` otherwise.
172+
/// Fetch the band's nodata value.
173+
/// Return `None` if no nodata value is set.
174174
pub fn no_data_value(&self) -> Option<f64> {
175175
let mut success: i32 = 0;
176176
let value = unsafe {
@@ -188,7 +188,8 @@ impl<'a> RasterBand<'a> {
188188
}
189189
}
190190

191-
/// Set or clear the no-data value.
191+
/// Set the band's nodata value.
192+
/// Pass `None` to clear any existing nodata value.
192193
pub fn set_no_data_value(&self, value: Option<f64>) -> Result<()> {
193194
let rv = if let Some(val) = value {
194195
unsafe { call_gdal_api!(self.api, GDALSetRasterNoDataValue, self.c_rasterband, val) }
@@ -201,7 +202,8 @@ impl<'a> RasterBand<'a> {
201202
Ok(())
202203
}
203204

204-
/// Set or clear the no-data value as u64.
205+
/// Set the band's nodata value as `u64`.
206+
/// Pass `None` to clear any existing nodata value.
205207
pub fn set_no_data_value_u64(&self, value: Option<u64>) -> Result<()> {
206208
let rv = if let Some(val) = value {
207209
unsafe {
@@ -221,7 +223,8 @@ impl<'a> RasterBand<'a> {
221223
Ok(())
222224
}
223225

224-
/// Set or clear the no-data value as i64.
226+
/// Set the band's nodata value as `i64`.
227+
/// Pass `None` to clear any existing nodata value.
225228
pub fn set_no_data_value_i64(&self, value: Option<i64>) -> Result<()> {
226229
let rv = if let Some(val) = value {
227230
unsafe {
@@ -247,7 +250,8 @@ impl<'a> RasterBand<'a> {
247250
}
248251
}
249252

250-
/// Compute the actual block size (clamped to raster extent) for a given block index.
253+
/// Return the actual block size for a block index.
254+
/// Clamp edge blocks to the raster extent.
251255
pub fn actual_block_size(
252256
band: &RasterBand<'_>,
253257
block_index: (usize, usize),

c/sedona-gdal/src/vector/feature.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ impl<'a> Feature<'a> {
5151
}
5252
}
5353

54-
/// Get the geometry reference (borrowed, not owned — do not destroy).
55-
///
56-
/// Returns None if the feature has no geometry.
54+
/// Fetch the feature geometry.
55+
/// The returned geometry is borrowed; return `None` if no geometry is set.
5756
pub fn geometry(&self) -> Option<BorrowedGeometry<'_>> {
5857
let c_geom = unsafe { call_gdal_api!(self.api, OGR_F_GetGeometryRef, self.c_feature) };
5958
if c_geom.is_null() {
@@ -67,7 +66,8 @@ impl<'a> Feature<'a> {
6766
}
6867
}
6968

70-
/// Get a field's index by name. Returns an error if the field is not found.
69+
/// Fetch the index of a field by name.
70+
/// Return an error if the field is not found.
7171
pub fn field_index(&self, name: &str) -> Result<i32> {
7272
let c_name = CString::new(name)?;
7373
let idx = unsafe {
@@ -84,7 +84,7 @@ impl<'a> Feature<'a> {
8484
Ok(idx)
8585
}
8686

87-
/// Get a field value as f64.
87+
/// Fetch a field value as `f64`.
8888
pub fn field_as_double(&self, field_index: i32) -> f64 {
8989
unsafe {
9090
call_gdal_api!(
@@ -96,9 +96,8 @@ impl<'a> Feature<'a> {
9696
}
9797
}
9898

99-
/// Get a field value as i32.
100-
///
101-
/// Returns `Some(value)` if the field is set and not null, `None` otherwise.
99+
/// Fetch a field value as `i32`.
100+
/// Return `None` if the field is unset or null.
102101
pub fn field_as_integer(&self, field_index: i32) -> Option<i32> {
103102
let is_set = unsafe {
104103
call_gdal_api!(
@@ -163,7 +162,7 @@ impl<'a> BorrowedGeometry<'a> {
163162
Ok(buf)
164163
}
165164

166-
/// Get the bounding envelope.
165+
/// Fetch the 2D envelope of this geometry.
167166
pub fn envelope(&self) -> Envelope {
168167
let mut env = OGREnvelope {
169168
MinX: 0.0,

c/sedona-gdal/src/vector/layer.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ impl<'a> Layer<'a> {
5353
unsafe { call_gdal_api!(self.api, OGR_L_ResetReading, self.c_layer) };
5454
}
5555

56-
/// Get the next feature (returns None when exhausted).
56+
/// Fetch the next feature from the current read cursor.
57+
/// Return `None` when no more features are available.
5758
pub fn next_feature(&self) -> Option<Feature<'_>> {
5859
let c_feature = unsafe { call_gdal_api!(self.api, OGR_L_GetNextFeature, self.c_layer) };
5960
if c_feature.is_null() {
@@ -63,7 +64,8 @@ impl<'a> Layer<'a> {
6364
}
6465
}
6566

66-
/// Create a field on this layer.
67+
/// Create a field in this layer.
68+
/// Allow the driver to approximate the definition if needed.
6769
pub fn create_field(&self, field_defn: &FieldDefn) -> Result<()> {
6870
let rv = unsafe {
6971
call_gdal_api!(
@@ -83,9 +85,8 @@ impl<'a> Layer<'a> {
8385
Ok(())
8486
}
8587

86-
/// Get the number of features in this layer.
87-
///
88-
/// If `force` is true, the count will be computed even if it is expensive.
88+
/// Fetch the feature count for this layer.
89+
/// Return `-1` if the count is unknown and `force` is `false`.
8990
pub fn feature_count(&self, force: bool) -> i64 {
9091
unsafe {
9192
call_gdal_api!(
@@ -97,7 +98,8 @@ impl<'a> Layer<'a> {
9798
}
9899
}
99100

100-
/// Iterate over all features.
101+
/// Iterate over features from the start of the layer.
102+
/// This resets the layer read cursor before iteration.
101103
pub fn features(&mut self) -> FeatureIterator<'_> {
102104
self.reset_reading();
103105
FeatureIterator { layer: self }

0 commit comments

Comments
 (0)