Skip to content
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

Crop and keep original? #23

Closed
rogerhyam opened this issue Feb 23, 2018 · 2 comments
Closed

Crop and keep original? #23

rogerhyam opened this issue Feb 23, 2018 · 2 comments

Comments

@rogerhyam
Copy link

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
Copy link
Owner

hunzikp commented Feb 23, 2018

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
Copy link
Author

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.

@hunzikp hunzikp closed this as completed Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants