gdal icon indicating copy to clipboard operation
gdal copied to clipboard

'rasterize' should accept references to geometries

Open ianliu opened this issue 3 years ago • 1 comments

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.md if knowledge of this change could be valuable to users.

ianliu avatar Aug 09 '22 17:08 ianliu

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.

ianliu avatar Aug 09 '22 20:08 ianliu

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?

msalib avatar Aug 31 '22 18:08 msalib

Right! Didn't know about that function, I will change the docs then.

ianliu avatar Aug 31 '22 21:08 ianliu