-
Notifications
You must be signed in to change notification settings - Fork 95
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
Too hard to create a raster with a run-time data type #483
Comments
i guess that depends how you use it. I usually want to read data with the type of the dataset and when creating a dataset i want that to have the type of the data. In both cases it is nice to use the same generic T for rasterio and driver/band creation. |
I find this super frustrating also. As a point of comparison, I have this sort of thing all over my code: match &raster.cell_type {
CellType::UInt8 => write_dataset(&raster.data.cast_as::<u8>(), &raster.mask, self),
CellType::UInt16 => write_dataset(&raster.data.cast_as::<u16>(), &raster.mask, self),
CellType::UInt32 => write_dataset(&raster.data.cast_as::<u32>(), &raster.mask, self),
CellType::Int16 => write_dataset(&raster.data.cast_as::<i16>(), &raster.mask, self),
CellType::Int32 => write_dataset(&raster.data.cast_as::<i32>(), &raster.mask, self),
CellType::Float32 => write_dataset(&raster.data.cast_as::<f32>(), &raster.mask, self),
CellType::Float64 => write_dataset(&raster.data.cast_as::<f64>(), &raster.mask, self),
} As an antidote, i've been working on a side project called |
I just realized it's Time for a |
ooof 🤢 |
Hi there, |
Writing an output with the same data type as the input, or with a compatible one if you have multiple inputs with different types. In the end, it boils down to the same thing metasim had. |
What about create_copy() then? I guess the problem would be that you can't define how many bands you want right? |
Well, I don't want a copy, I want a new dataset/band with runtime-dependent data type. You can even take advantage of the built-in type conversions, e.g. writing a https://docs.rs/gdal/latest/src/gdal/driver.rs.html#188 already takes |
Oh, I see now, sorry... the type as an argument to the function rather than a generic :). |
Yeah. I think we can safely rename |
What about having a DatasetBuilder; Something like: let filename = "/tmp/image.tif";
let size_x = 256;
let size_y = 256;
let bands = 3;
let data_type = GdalDataType::UInt16;
let options = RasterCreationOptions::from_iter(["COMPRESS=LZW"]);
let driver = DriverManager::get_driver_by_name("GTiff")?;
let dataset = DatasetBuilder::new(filename, size_x, size_y, bands)
.data_type(data_type) // not required, default to u8
.options(&options) // not required, default to none
.build(&driver)?; or would it be too different to the rest of the API ? |
Driver::create_with_band_type_with_options
takes the type as a generic parameter, which is pretty annoying.The text was updated successfully, but these errors were encountered: