Skip to content

Commit

Permalink
p
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Jan 8, 2023
1 parent 56d4850 commit ad382cf
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ S3method(str, SpatRaster)
S3method(str, SpatExtent)
S3method(str, SpatGraticule)

export(focalMat, gdal, getGDALconfig, graticule, setGDALconfig, north, sbar, terraOptions, tmpFiles, makeVRT, mem_info, free_RAM, shade, gdalCache, fileBlocksize, vector_layers)
export(focalMat, gdal, getGDALconfig, graticule, setGDALconfig, map.pal, north, sbar, terraOptions, tmpFiles, makeVRT, mem_info, free_RAM, shade, gdalCache, fileBlocksize, vector_layers)

25 changes: 25 additions & 0 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,28 @@ shade <- function(slope, aspect, angle=45, direction=0, normalize=FALSE, filenam
messages(slope, "shade")
}


map.pal <- function(name, n=50, ...) {
f <- system.file("colors/palettes.rds", package="terra")
v <- readRDS(f)
if (missing(name)) {
return(names(v))
}
if (name %in% names(v)) {
r <- colorRampPalette(v[[name]], ...)
r(n)
} else {
error("map.pal", paste(name, "is not a known palette"))
}
}

map.leg <- function(name) {
f <- system.file("colors/legends.rds", package="terra")
v <- readRDS(f)
if (name %in% names(v)) {
v[[name]]
} else {
error("map.leg", paste(name, "is not a known legend"))
}
}

Binary file added inst/colors/legends.rds
Binary file not shown.
Binary file added inst/colors/palettes.rds
Binary file not shown.
38 changes: 38 additions & 0 deletions man/mappal.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
\name{map.pal}

\alias{map.pal}

\title{map.pal arrow}

\description{
Get a color palette for mapping. These palettes were copied from GRASS
}

\usage{
map.pal(name, n=50, ...)

}

\arguments{
\item{name}{character (name of a palette), or missing (to get the available names)}
\item{n}{numeric. The number of colors}
\item{...}{additional arguments that are passed to \code{\link{colorRamp}}}
}

\value{
none
}

\seealso{ \code{\link{terrain.colors}} }

\examples{
map.pal("elevation", 10)

r <- rast(system.file("ex/elev.tif", package="terra"))
plot(r, col=map.pal("elevation"))

map.pal()
}


\keyword{spatial}
7 changes: 5 additions & 2 deletions src/write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,16 @@ bool SpatRaster::writeValues(std::vector<double> &vals, size_t startrow, size_t

size_t nv = nrows * ncol() * nlyr();
if (vals.size() != nv) {
setError("incorrect number of values for writing");
if (nv > vals.size()) {
setError("incorrect number of values (too many) for writing");
} else {
setError("incorrect number of values (too few) for writing");
}
return false;
}

if (source[0].driver == "gdal") {
#ifdef useGDAL

success = writeValuesGDAL(vals, startrow, nrows, 0, ncol());
#else
setError("GDAL is not available");
Expand Down

0 comments on commit ad382cf

Please sign in to comment.