Comments (1)
You're confusing two concepts: The storage mode of the data, and the datatype attribute of the raster object. velox typically preserves the storage mode of the data, even if you cast to a matrix or a raster object. To continue your example:
mat <- matrix(1:9, 3, 3)
class(mat[1,1])
# "integer"
vx <- velox(mat, extent=c(0,3,0,3), res=c(1,1), crs="+proj=longlat +datum=WGS84 +no_defs")
class(vx$as.matrix()[1,1])
# "integer"
class(as.matrix(vx$as.RasterLayer())[1,1])
# "integer"
The raster package uses float32 as the default data type (unless the default was changed using raster::rasterOptions), regardless of the storage mode of the actual data. E.g.
mat <- matrix(rep(1L, 9), 3, 3)
storage.mode(mat)
# "integer"
ras <- raster(mat)
dataType(ras)
# "FLT4S"
Consequently, the fact that the raster object you get from vx$as.RasterStack()
has data type float32 is due to the raster package, rather than velox. Nonetheless, I've implemented an extra argument that allows assigning appropriate data types to raster objects created from velox rasters:
mat <- matrix(1:9, 3, 3)
vx <- velox(mat, extent=c(0,3,0,3), res=c(1,1), crs="+proj=longlat +datum=WGS84 +no_defs")
ras <- vx$as.RasterLayer(assign_data_type = TRUE) # New argument
dataType(ras)
# "INT1U"
Note, however, that the raster::writeRaster
function doesn't automatically respect the datatype attribute. You still need to do
writeRaster(x = ras, filename = "/foo/bar.tif", datatype=dataType(ras))
Alternatively, you could just use vx$write()
, which always uses the smallest possible data type when writing to disk.
from velox.
Related Issues (20)
- Velox Got A Lot Lot Lot Slower? HOT 1
- Error: long vectors not supported yet: memory.c:3451
- Failed to install on Mac HOT 5
- vx$extract_points failure HOT 1
- copy VeloxRaster object
- Access cell number of extracted value? HOT 3
- Velox extract error: "Error in boostFactory$makePointGrid ... std::bad_alloc" HOT 6
- velox extract area weighted mean
- Include st. dev, min and max focal functions when applying a moving window kernel filter
- extract for lines files
- pointextract.cpp - unused input?
- GeoTIFF raster values "reasonable" with raster extract but all NA velox extract HOT 2
- Feature request: raster arithmetic!
- along = TRUE argument for extract function?
- CRAN archive notification HOT 24
- Failed trying to install in Mac HOT 3
- fatal error: 'math.h' file not found macos Catalina
- compatibility with R 4.0 HOT 3
- Unable to install package HOT 1
- Velox is still the fastest, but compatibility issues make it difficult to share HOT 1
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 velox.