gdal
gdal copied to clipboard
'rasterize' should accept references to geometries
As of now, gdal::raster::rasterize is accepting &[Geometry], but this is a little bit cumbersome, since gdal::vector::Feature's geometry method returns a reference &Geometry.
To work around, one has to copy the geometry like so:
...
let geom = feature.geometry();
let wkb = geom.wkb().unwrap();
let copy = Geometry::from_wkb(&wkb);
rasterize(..., &[copy], ...);
By changing the rasterize function signature to accept a slice of references to geometries, this is not needed anymore.
- [x] I agree to follow the project's code of conduct.
- [x] I added an entry to
CHANGES.mdif knowledge of this change could be valuable to users.
Ok, now I see that Geometry implements Clone, so it is not that cumbersome. Nonetheless, rasterize shouldn't need a copy to perform its operations, as it only needs a read-only reference to the geometry.
Converting a reference to a single element slice can be done without copying though using std::slice::from_ref. I think that slices of references are awkward to handle, so maybe instead of changing the interface, you might consider updating the docs to point to from_ref for the common single-geometry case instead?
Right! Didn't know about that function, I will change the docs then.