airbusgeo / godal

golang wrapper for github.com/OSGEO/gdal
Apache License 2.0
137 stars 27 forks source link

we don't wrap `GDALAutoCreateWarpedVRT` (yet). We do however wrap the GDALWarp command which will probably get you where you want #109

Closed pdxrlj closed 1 year ago

pdxrlj commented 1 year ago
          we don't wrap `GDALAutoCreateWarpedVRT` (yet). We do however wrap the GDALWarp command which will probably get you where you want

Originally posted by @tbonfort in https://github.com/airbusgeo/godal/issues/108#issuecomment-1500060086

pdxrlj commented 1 year ago

Can you give me some examples? I tried to use BuildVrt in the "example" folder but it didn't work. I want to achieve the following effect: fn warped_vrt(&self, sp_ref: &SpatialRef) -> Result<Dataset, Box> { let src_wkt = CString::new(self.ds.spatial_ref()?.to_wkt()?)?; let target_wkt = CString::new(sp_ref.to_wkt()?)?;

let mut str_opts = CslStringList::new();
str_opts.set_name_value("INIT_DEST", "NO_DATA")?;
str_opts.set_name_value("NUM_THREADS", "1")?;

let mut options = unsafe { GDALCreateWarpOptions() };

unsafe { (*options).dfWarpMemoryLimit = 2048. * 1024. * 1024. };
unsafe {
    (*options).papszWarpOptions = str_opts.as_ptr();
}

let vrt: GDALDatasetH = unsafe {
    GDALAutoCreateWarpedVRT(
        self.ds.c_dataset(),
        src_wkt.as_ptr(),
        target_wkt.as_ptr(),
        GDALResampleAlg::GRA_NearestNeighbour,
        0. as c_double,
        options,
    )
};

if vrt.is_null() {
    return Err(String::from("could not create WarpedVRT").into());
}

let gdal_dataset = unsafe { GDALDataset::from_c_dataset(vrt) };
Ok(Dataset { ds: gdal_dataset })

}