This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# list required packages | |
list_r_files = function() { | |
list.files(patt = "(?i)\\.(r|rmd)$", full = TRUE, recursive = TRUE) | |
} | |
regular_expression <- function(x, p) regmatches(x, regexec(p, x)) | |
last = function(x) x[length(x)] | |
scan_packages = function(x) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("raster") | |
setMethod("rasterize", signature(x="data.frame", y="missing"), | |
function(x, field, res = 1, fun = 'last', ...) { | |
r = raster(res = res, xmn = min(x$x), xmx = max(x$x), ymn = min(x$y), ymx = max(x$y)) | |
rasterize(x, r, field = field, fun = fun, ...) | |
}) | |
setMethod("rasterize", signature(x="SpatialPoints", y="missing"), | |
function(x, field, res = 1, fun = 'last', ...) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from osgeo import gdal | |
if len(sys.argv) > 1: | |
ds = gdal.Open(sys.argv[1]) | |
print(ds.GetRasterBand(1).GetOverview(0).GetBlockSize()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Transform extent coordinates to data.frame | |
#' @param e Raster or Extent object | |
#' @param loop Should first and last coordinates be the same ? (defautl TRUE, required to create a polygon) | |
extent_as_data_frame_poly = function (e, loop = TRUE) { | |
e = extent(e) | |
e_poly = data.frame(x = c(e@xmin, e@xmax, e@xmax, e@xmin), | |
y = c(e@ymin, e@ymin, e@ymax, e@ymax)) | |
if (loop) e_poly = rbind(e_poly, e_poly[1, ]) | |
e_poly | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
say_x <- function(x) { | |
deparse(substitute(x)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Transform raster to data.table | |
#' | |
#' @param x Raster* object | |
#' @param row.names `NULL` or a character vector giving the row names for the data frame. Missing values are not allowed | |
#' @param optional logical. If `TRUE`, setting row names and converting column names (to syntactic names: see make.names) is optional | |
#' @param xy logical. If `TRUE`, also return the spatial coordinates | |
#' @param centroids logical. If TRUE return the centroids instead of all spatial coordinates (only relevant if xy=TRUE) | |
#' @param sepNA logical. If TRUE the parts of the spatial objects are separated by lines that are NA (only if xy=TRUE and, for polygons, if centroids=FALSE | |
#' @param ... Additional arguments (none) passed to `raster::as.data.frame` | |
#' |
NewerOlder