Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Jul 9, 2019
1 parent 9241d25 commit 89cc846
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 154 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: raster
Type: Package
Title: Geographic Data Analysis and Modeling
Version: 2.9-19
Date: 2019-07-02
Version: 2.9-22
Date: 2019-07-09
Depends: sp (>= 1.2-0), R (>= 3.0.0)
Suggests: rgdal (>= 0.9-1), rgeos (>= 0.3-8), ncdf4, igraph, tcltk, parallel, rasterVis, MASS, sf, testthat
LinkingTo: Rcpp
Expand Down
10 changes: 3 additions & 7 deletions R/AAgeneric_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@ if (!isGeneric("approxNA")) {setGeneric("approxNA", function(x, ...) standardGe
if (!isGeneric("as.data.frame")) { setGeneric("as.data.frame", function(x, row.names = NULL, optional = FALSE, ...) standardGeneric("as.data.frame")) }

if (!isGeneric("as.factor")) {setGeneric("as.factor", function(x) standardGeneric("as.factor"))}

if (!isGeneric("is.factor")) {setGeneric("is.factor", function(x) standardGeneric("is.factor"))}


if (!isGeneric("atan2")) { setGeneric("atan2", function(y, x) standardGeneric("atan2"))}
if (!isGeneric("boundaries")) { setGeneric("boundaries", function(x, ...) standardGeneric("boundaries"))}

if (!isGeneric('buffer')) {setGeneric('buffer', function(x, ...) standardGeneric('buffer'))}

if (!isGeneric("calc")) {setGeneric("calc", function(x, fun, ...) standardGeneric("calc")) }
if (!isGeneric("clamp")) {setGeneric("clamp", function(x, ...) standardGeneric("clamp")) }
if (!isGeneric("cover")) {setGeneric("cover", function(x, y, ...) standardGeneric("cover"))}
if (!isGeneric("crop")) { setGeneric("crop", function(x, y, ...) standardGeneric("crop"))}
if (!isGeneric("crs")) { setGeneric("crs", function(x, ...) standardGeneric("crs")) }
if (!isGeneric("crs<-")) { setGeneric("crs<-", function(x, ..., value) standardGeneric("crs<-")) }
if (!isGeneric("disaggregate")) {setGeneric("disaggregate", function(x, ...) standardGeneric("disaggregate"))}

if (!isGeneric("distance")) {setGeneric("distance", function(x, y, ...)standardGeneric("distance"))}
if (!isGeneric("erase")) {setGeneric("erase", function(x, y, ...) standardGeneric("erase"))}

if (!isGeneric("extend")) {setGeneric("extend", function(x, y, ...) standardGeneric("extend"))}
if (!isGeneric("extract")) { setGeneric("extract", function(x, y, ...) standardGeneric("extract"))}
if (!isGeneric("flip")) { setGeneric("flip", function(x, direction, ...) standardGeneric("flip")) }
if (!isGeneric("focal")) { setGeneric("focal", function(x, ...) standardGeneric("focal"))}
Expand All @@ -37,7 +33,7 @@ if (!isGeneric("hasValues")) { setGeneric("hasValues", function(x, ...) standard
if (!isGeneric("ifel")) {setGeneric("ifel", function(test, yes, no, ...) standardGeneric("ifel"))}
if (!isGeneric("image")) {setGeneric("image", function(x,...) standardGeneric("image"))}
if (!isGeneric("init")) {setGeneric("init", function(x, ...) standardGeneric("init"))}

if (!isGeneric("interpolate")) { setGeneric("interpolate", function(object, ...) standardGeneric("interpolate"))}
if (!isGeneric("isLonLat")) { setGeneric("isLonLat", function(x, ...) standardGeneric("isLonLat"))}
if (!isGeneric("couldBeLonLat")) { setGeneric("couldBeLonLat", function(x, ...) standardGeneric("couldBeLonLat"))}

Expand Down
5 changes: 0 additions & 5 deletions R/extend.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@



if (!isGeneric("extend")) {
setGeneric("extend", function(x, y, ...)
standardGeneric("extend"))
}

setMethod('extend', signature(x='Extent'),
# function by Etienne B. Racine
function(x, y, ...) {
Expand Down
14 changes: 10 additions & 4 deletions R/geom.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,19 @@ setMethod("geom", signature(x="data.frame"),
function(x, d, gt, crs, ...) {
if (gt == "polygons") {
sp <- as(x, "SpatialPolygons")
sp <- sp::SpatialPolygonsDataFrame(sp, d)
if (NROW(d) > 0) {
sp <- sp::SpatialPolygonsDataFrame(sp, d)
}
} else if (gt == "lines") {
sp <- as(x, "SpatialLines")
sp <- sp::SpatialLinesDataFrame(sp, d)
if (NROW(d) > 0) {
sp <- sp::SpatialLinesDataFrame(sp, d)
}
} else {
sp <- as(x, "SpatialPoints")
sp <- sp::SpatialPointsDataFrame(sp, d)
sp <- sp::SpatialPoints(x[,c("x", "y")])
if (NROW(d) > 0) {
sp <- sp::SpatialPointsDataFrame(sp, d)
}
}
crs(sp)<- crs
sp
Expand Down
7 changes: 4 additions & 3 deletions R/ifelse.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
# Version 1.0
# Licence GPL v3

setMethod("ifel", signature(test="Raster", yes="ANY", no="ANY"),
function(test, yes, no, filename="", ...) {
#setMethod("ifel", signature(test="Raster", yes="ANY", no="ANY"),

.ifel <- function(test, yes, no, filename="", ...) {
if (!inherits(no, "Raster")) {
stopifnot(is.numeric(no))
if (length(no) > 1) warning('only the first element of "no" is used')
Expand All @@ -19,4 +20,4 @@ setMethod("ifel", signature(test="Raster", yes="ANY", no="ANY"),
}
cover(no, yes, filename=filename)
}
)
#)
4 changes: 0 additions & 4 deletions R/interpolate.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@

if (!isGeneric("interpolate")) {
setGeneric("interpolate", function(object, ...)
standardGeneric("interpolate"))
}

# to do: should allow index to be a vector

Expand Down
4 changes: 2 additions & 2 deletions man/cluster.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ values(r) <- runif(ncell(r))
m <- c(0, 0.25, 1, 0.25, 0.5, 2, 0.5, 1, 3)
m <- matrix(m, ncol=3, byrow=TRUE)
rc1 <- clusterR(r, reclassify, args=list(rcl=m, right=FALSE),
filename='rcltest.grd', datatype='INT2S', overwrite=TRUE)
filename=rasterTmpFile(), datatype='INT2S', overwrite=TRUE)

# equivalent to:
rc2 <- reclassify(r, rcl=m, right=FALSE, filename='rcltest.grd', datatype='INT2S', overwrite=TRUE)
rc2 <- reclassify(r, rcl=m, right=FALSE, filename=rasterTmpFile(), datatype='INT2S', overwrite=TRUE)


# example with the calc function
Expand Down
6 changes: 3 additions & 3 deletions man/datasource.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ fromDisk(rs)
rs <- setValues(rs, 1:ncell(rs))
inMemory(rs)
fromDisk(rs)
rs <- writeRaster(rs, filename='test', overwrite=TRUE)
inMemory(rs)
fromDisk(rs)
#rs <- writeRaster(rs, filename=rasterTmpFile(), overwrite=TRUE)
#inMemory(rs)
#fromDisk(rs)
}

\keyword{ spatial }
4 changes: 2 additions & 2 deletions man/factor.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ i
factorValues(r, i)

# write to file:
rr <- writeRaster(r, 'test.grd', overwrite=TRUE)
rr
# rr <- writeRaster(r, rasterTmpFile(), overwrite=TRUE)
# rr

# create a single-layer factor
x <- deratify(r, 'landcover')
Expand Down
52 changes: 0 additions & 52 deletions man/ifelse.Rd

This file was deleted.

4 changes: 2 additions & 2 deletions man/init.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ y <- init(r, fun=runif)

# there are different ways to set all values to 1
# for large rasters:
set1f <- function(x){rep(1, x)}
z1 <- init(r, fun=set1f, filename='test.grd', overwrite=TRUE)
# set1f <- function(x){rep(1, x)}
# z1 <- init(r, fun=set1f, filename=rasterTmpFile(), overwrite=TRUE)

# This is equivalent to (but not memory safe):
z2 <- setValues(r, rep(1, ncell(r)))
Expand Down
8 changes: 5 additions & 3 deletions man/metadata.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ Raster* object or list

\examples{
r <- raster(nc=10, nr=10)
r[] <- 1:ncell(r)
values(r) <- 1:ncell(r)

m <- list(wave=list(a=1, b=2, c=c('cool', 'important')), that=list(red='44', blue=1:5,
days=as.Date(c('2014-1-15','2014-2-15'))), this='888 miles from here', today=NA)

metadata(r) <- m
x <- writeRaster(r, 'test.grd', overwrite=TRUE)

\dontrun{

x <- writeRaster(r, rasterTmpFile(), overwrite=TRUE)
metax <- metadata(x)

identical(metax, m)

\dontrun{
# nested too deep
badmeta1 <- list(wave=list(a=1, b=2, c='x'), that=list(red='4', blue=list(bad=5)))
metadata(r) <- badmeta1
Expand Down
6 changes: 4 additions & 2 deletions man/update.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ RasterLayer or RasterBrick
}

\examples{
\dontrun{
# setting up an example RasterLayer with file
r <- raster(nrow=5, ncol=10, vals=0)
r <- writeRaster(r, 'test', overwrite=TRUE, datatype='INT2S')
r <- writeRaster(r, rasterTmpFile(), overwrite=TRUE, datatype='INT2S')
as.matrix(r)

# update with a vector starting a cell
Expand All @@ -52,10 +53,11 @@ r <- update(r, v=5:1, cell=c(5,15,25,35,45))
as.matrix(r)

# updating with a marix, anchored at a cell number
m = matrix(1:10, ncol=2)
m <- matrix(1:10, ncol=2)
r <- update(r, v=m, cell=2)
as.matrix(r)
}
}

\keyword{methods}
\keyword{spatial}
Expand Down
14 changes: 1 addition & 13 deletions src/distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
*/

#ifndef M_PI
#define M_PI (3.14159265358979323846)
#endif

#include <Rcpp.h>
using namespace Rcpp;
using namespace std;
#include <vector>
#include "geodesic.h"
#include <math.h>
#include "util.h"


double distance_lonlat(double lon1, double lat1, double lon2, double lat2, double a, double f) {
Expand Down Expand Up @@ -92,16 +90,6 @@ std::vector<double> distanceToNearest_plane(std::vector<double> x1, std::vector<



// Convert degrees to radians
double toRad(double deg) {
return( deg * 0.0174532925199433 );
}

double toDeg(double rad) {
return( rad * 57.2957795130823 );
}



double direction_lonlat(double lon1, double lat1, double lon2, double lat2, bool degrees, double a, double f) {
double s12, azi1, azi2;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 12 additions & 4 deletions src/util.c → src/util.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#include <R.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#ifndef RASTERUTIL_GUARD
#define RASTERUTIL_GUARD


#include <math.h>
#include "Rmath.h"

#ifndef M_PI
#define M_PI (3.14159265358979323846)
#endif


double mod(double x, double n) {
Expand All @@ -30,3 +35,6 @@ double toDeg(double rad) {




#endif

46 changes: 0 additions & 46 deletions src/wirth.c

This file was deleted.

File renamed without changes.

0 comments on commit 89cc846

Please sign in to comment.