hunzikp / velox

https://hunzikp.github.io/velox/
119 stars 23 forks source link

Crop and keep original? #23

Closed rogerhyam closed 6 years ago

rogerhyam commented 6 years ago

Hi,

I may be well off on this as I'm new to R but I want to be able to crop and keep the original. In the raster package I do this

buffer_osg <- gBuffer( postcode_point, width=500, byid=TRUE) buffer_wgs84 <- spTransform(buffer_osg, LATLON_CRS) cropped <- crop(ndvi_raster, buffer_wgs84), vals <- extract(cropped, buffer_wgs84)

And it takes about a second on a raster of dimension : 13561, 26809, 363556849 (nrow, ncol, ncell)

But I need to do it 90,000+ times on a sequence of 10 rasters so faster would be nicer

With Velox I do

vx1$extract(buffer_wgs84)

Which take 30+ seconds so I try cropping first (like with raster)

vx1$crop(extent(buffer_wgs84))

Which is really quick but I lose the original raster as it treats vx1 as mutable.

Is there a way to crop and get the results of the crop and keep the original to use next time around in the loop?

Sorry if this is a dumb question and thanks for sharing your work.

Roger

hunzikp commented 6 years ago

Hi Roger, Currently, the only way to do this is to copy your raster, and then crop the copied raster. E.g.

vx_crop <- vx1$copy()
vx_crop$crop(extent(buffer_wgs84))

On a related note: Cropping prior to extraction shouldn't make a huge time difference. If it does, this might be the result of issue #22. Maybe you can speed things up by installing the development version of velox.

rogerhyam commented 6 years ago

Thanks. I installed the binary version of the package so am probably on an older version. I'll look into building from the dev version.