Last active
May 23, 2019 19:14
-
-
Save srgorelik/e8eea531ce44ba44d71053a93d475029 to your computer and use it in GitHub Desktop.
Quickly display a map of raster file from the command line.
This file contains 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
#!/usr/bin/env Rscript | |
# sgorelik 2019 | |
suppressPackageStartupMessages(library(optparse)) | |
suppressPackageStartupMessages(library(rasterVis)) | |
opt.list <- list( | |
make_option(c('-b','--band'), type = 'integer', default = 1, metavar = 'INTEGER', | |
help = 'The raster band to plot (default is %default).') | |
) | |
opt.parser <- OptionParser(option_list = opt.list, | |
prog = 'map', | |
usage = 'usage: %prog <raster>\n', | |
description = paste0('Quickly display a map of raster file from the command line.\n\n', | |
'Arguments:\n', | |
'\t<raster>\n', | |
'\t\tRaster file path.')) | |
arguments <- parse_args(opt.parser, positional_arguments = 1) | |
pos.args <- arguments$args | |
opt.args <- arguments$options | |
f <- pos.args[1] | |
b <- opt.args$band | |
r <- raster(f, band = b) | |
X11() | |
levelplot(r, margin = F) | |
message('Press return to close map...') | |
invisible(readLines('stdin', n = 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment