Comments (8)
Thanks for \4... this seems still to improve performance significantly.
from geocompr.
raster tips: set options(rasterMaxMemory = nbytes) to change limit for redirect to file (by default not set, hard coded to 100Mb)
https://twitter.com/mdsumner/status/868655402224762880
https://gist.github.com/mdsumner/7cb21ce030ca5e9acae7d14e0d929162
from geocompr.
@mdsumner thanks for providing this list. Are they still your top tips or would you make any alterations to them based on recent developments? Are any not futureproof?
from geocompr.
4 and 5 are bugs, so they could be fixed - other than that I think they're pretty good :)
I'll add "use spex::polygonize(raster)
for fastest conversion to a polygon-per-pixel sf layer /14"
for 2 I'd add use tabularaster::cellnumbers
instead of juggling lists of cells
raster does now have some sf support (for extract, by conversion to Spatial)
also watch rhijmans/geospat, r-spatial/stars, and ecohealthalliance/fasterize
from geocompr.
Great - I think we've got most of those covered now:
- General intro to raster: http://geocompr.robinlovelace.net/spatial-class.html#raster-data
- Spatial operations: http://geocompr.robinlovelace.net/spatial-operations.html#spatial-ras
- Geometric operations: http://geocompr.robinlovelace.net/transform.html#geo-ras
- Raster-vector: http://geocompr.robinlovelace.net/raster-vector.html
One question: is the distinction between spatial and geometric operations clear? And have we missed anything? Thanks @mdsumner for all these tips, hope we've done them justice!
from geocompr.
LGTM! The book is awesome btw, it's great to see this all laid out in detail.
5/ is now fixed, it's in the queue on CRAN
There's no need to as(x, "Spatial")
for extract now for sf, since Nov 2017 (support for sf is patchy but more is coming)
One new "tip" is that extract can be massively sped up by using fasterize, but it's a bit abstract - and presumably raster will apply this improvement some time soon. I also didn't realize extract had that df
argument (which is embarassing).
library(raster)
library(sf)
#install.packages("spDataLarge", repos = "https://nowosad.github.io/drat/",
# type = "source")
library(spDataLarge)
srtm = raster(system.file("raster/srtm.tif", package = "spDataLarge"))
zion = read_sf(system.file("vector/zion.gpkg", package = "spDataLarge"))
zion = st_transform(zion, projection(srtm))
fast_extract <- function(x, y) {
y[["ID"]] <- seq_len(nrow(y))
rast_poly <- fasterize::fasterize(y, x, field = "ID")
vals <- values(rast_poly)
out <- raster::extract(x, seq_len(ncell(x))[!is.na(vals)], df = TRUE)
out[["ID"]] <- vals[!is.na(vals)]
out
}
library(rbenchmark)
benchmark(ex_values = raster::extract(x = srtm, y = zion, df = TRUE),
fex_values = fast_extract(srtm, zion),
replications = 2)
#test replications elapsed relative user.self sys.self user.child sys.child
#1 ex_values 2 9.773 12.402 9.776 0 0 0
#2 fex_values 2 0.788 1.000 0.788 0 0 0
ex_values = raster::extract(x = srtm, y = zion, df = TRUE)
fex_values = fast_extract(srtm, zion)
identical(ex_values, fex_values)
#[1] TRUE
from geocompr.
Hey @mdsumner! Thanks for you kind words and sharing your knowledge.
I like the idea for fast_extract()
, but it is probably too abstract for the book. It is also (I assume) more limited that raster::extract()
, e.g. extracting by points or lines are not supported.
Yep, I am waiting for more consistent sf support in raster. Right now, crop
expects sp object, while mask
can also work on sf ones...
from geocompr.
fwiw this suggests it shouldn't matter any more: rspatial/raster#5
from geocompr.
Related Issues (20)
- Error message on dev versions of packages
- Structure of MULTIPOINT geometry type in the console output HOT 6
- grain raster object modified HOT 1
- line_sfc object not used in any relationship queries HOT 3
- The **st_coordinates** will drop the decimal part. HOT 7
- Legends overlap objects in Figure 9.6 HOT 3
- Subsetting multilayer rasters with double brackets [[ ]] HOT 1
- Restructure data I/O chapter? HOT 10
- Additional information about Table 5.1 regarding geometry conversions might be needed HOT 5
- cppRouting update HOT 21
- Book cover competition II HOT 10
- Typo in chapter 1 HOT 1
- CI failing due to popups HOT 3
- Update citations: use year not date fields HOT 4
- Broken link HOT 4
- More missing references
- Fix urls HOT 1
- Robin: second edition HOT 3
- Jannes: second edition HOT 7
- Possible issue in the Introduction regarding a reference HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geocompr.