Comments (3)
The standard library File is a good example to base our decision on. It is also a wrapper around a handle, and makes system calls for the actual operations. See in particular File::set_len which modifies the underlying file structure, but takes &self
. This fact is also documented:
Note that this method alters the content of the underlying file, even though it takes
&self
rather than&mut self
.
Thus, we should be in the clear to simply use &self
in all methods of Dataset
, RasterBand
, and Layer
.
Another option, is to use the compiler to enforce some semantics:
- All "read" methods take
&self
- All "write" methods take
&mut self
- The sub-objects:
RasterBand
andLayer
keep&Dataset
reference (as they currently do)
I like this as it may help avoid some pitfals at compile-time. It is also minimal conceptual change from current code-base, as we anyway use &mut self
on some methods (like start_transaction
). Also, this is at best a slap on the wrist anyway, as the same RasterBand
could anyway be opened twice to get around the &mut self
methods on it.
let ds = Dataset::open(...);
let band = ds.rasterband(1)?;
let same_band = ds.rasterband(1)?;
from gdal.
This is a very interesting question. I don't have a good answer, but want to highlight a few points to discuss:
- Currently, even
RasterBand::write
needs only a&self
ref; in contrast,Dataset::create_layer
, andRasterBand::set_color_interpretation
(from #144) do required an&mut self
. This feels inconsistent, but I'm not sure which is the right way - If we were to make
RasterBand
"writing" methods&mut self
and also require it to have a&mut Dataset
, then it would prevent a standard use-case of reading from one band and writing to another band of the same dataset. This seems too strict, and probably not what we want. I guess the question is: does GDAL write something on theDataset
, when modifying something about aRasterBand
- Just to understand the other extreme. Suppose we take the extreme case of interior mutability, and do not require
&mut self
for any of the methods, what could break? Are we violating any assumptions of the underlying C api?
Fortunately, Dataset
is !Sync
, and RasterBand
is even !Send
, so the mutations are still going to happen only in the same thread, and it is more a question of semantics. For example, suppose I have a RasterBand
reference, and read pixel (0, 0)
into a variable, then call a func foo(&RasterBand)
which ends up writing to that pixel. Then, when the function returns, the value I read into the variable has been invalidated. Do we want to prevent this? Note that, it is anyway conceivable that someone else (either same thread, another thread, or even another process) could anyway have opened the same Dataset
and modified things, so it was never a hard guarantee in the first place.
from gdal.
thanks for looking this up. This is a very good overview and File is a matching example. I guess we should do the read, write separation?
from gdal.
Related Issues (20)
- Change raster and block sizes to `usize`
- Fix issues with `SpatialRef::set_axis_mapping_strategy` API.
- Mutators in `Feature` don't require mutable receiver
- `Feature` fields getters and setters should accept field indexes HOT 3
- [Feature Request] Guess the Driver Type based on the file extension HOT 18
- FeatureIterator doesn't reset if the iterator isn't completely read HOT 1
- [Feature] Add `DriverIterator` to iterate through the available drivers HOT 1
- Random test suite crash HOT 23
- Can it support macos? HOT 6
- Update OGR arrow example to use arrow-rs
- No iterator support for rasterbands
- Cannot share dataset safely between threads HOT 2
- Error reported when cross compiling on Windows HOT 2
- Discord link not working HOT 1
- is anyone here haved this problem solve? gdal-sys HOT 5
- Cross-compile for aarch64-linux-gnu
- `Polygonize` wrapper HOT 3
- Can `Geometry` be `Send`? HOT 2
- No pre-built bindings available for GDAL version 3.8 HOT 1
- Add Wrapper for OGR_L_Intersection
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gdal.