Skip to content

Commit bd07e3f

Browse files
committed
further changes for _R_CHECK_DEPENDS_ONLY_=true; #117
1 parent e11bee5 commit bd07e3f

File tree

9 files changed

+61
-20
lines changed

9 files changed

+61
-20
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: sp
2-
Version: 1.5-0
2+
Version: 1.5-1
33
Title: Classes and Methods for Spatial Data
44
Authors@R: c(person("Edzer", "Pebesma", role = c("aut", "cre"),
55
email = "[email protected]"),

inst/include/sp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#endif
99
/* remember to touch local_stubs.c */
1010

11-
#define SP_VERSION "1.5-0"
11+
#define SP_VERSION "1.5-1"
1212

1313
#include <R.h>
1414
/* RSB 091203 */

man/disaggregate.Rd

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ per \link{Polygons}, respectively.
2424

2525
\author{ Robert Hijmans, Edzer Pebesma }
2626
\examples{
27+
if (require(rgeos, quietly = TRUE)) {
2728
Sr1 = Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)), hole = FALSE)
2829
Sr2 = Polygon(cbind(c(5,4,2,5),c(2,3,2,2)), hole = FALSE)
2930
Sr3 = Polygon(cbind(c(4,4,5,10,4),c(5,3,2,5,5)), hole = FALSE)
@@ -47,4 +48,5 @@ sl = SpatialLines(list(S1,S2))
4748
length(sl)
4849
length(disaggregate(sl))
4950
}
51+
}
5052
\keyword{methods}

man/over.Rd

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ and use \link[rgeos:pred-binary-gIntersects]{gIntersects}.}
138138
\code{vignette("over")} for examples and figures;
139139
\link{point.in.polygon}, package \link[rgeos:pred-binary-gIntersects]{gIntersects}}
140140
\examples{
141+
if (require(rgeos, quietly = TRUE)) {
141142
r1 = cbind(c(180114, 180553, 181127, 181477, 181294, 181007, 180409,
142143
180162, 180114), c(332349, 332057, 332342, 333250, 333558, 333676,
143144
332618, 332413, 332349))
@@ -195,4 +196,5 @@ over(meuse.grid, srdf, fn = mean)
195196
over(as(meuse.grid, "SpatialPoints"), sr)
196197
over(as(meuse.grid, "SpatialPoints"), srdf)
197198
}
199+
}
198200
\keyword{methods}

src/sp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#endif
99
/* remember to touch local_stubs.c */
1010

11-
#define SP_VERSION "1.5-0"
11+
#define SP_VERSION "1.5-1"
1212

1313
#include <R.h>
1414
/* RSB 091203 */

tests/agg.R

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
options("rgdal_show_exportToProj4_warnings"="none")
22
library(sp)
3+
if (require(rgeos, quietly = TRUE)) {
34
g = SpatialGrid(GridTopology(c(5,5), c(10,10), c(3,3)))
45
p = as(g, "SpatialPolygons")
56
p$z = c(1,0,1,0,1,0,1,0,1)
@@ -31,3 +32,4 @@ rnd2(c(aggregate(p, sq, mean)[[1]],
3132
aggregate(p, sq, mean, minDimension = 1)[[1]],
3233
aggregate(p, sq, mean, minDimension = 2)[[1]],
3334
aggregate(p, sq, mean, areaWeighted=TRUE)[[1]]))
35+
}

tests/over2.R

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
options("rgdal_show_exportToProj4_warnings"="none")
22
library(sp)
33

4+
if (require(rgeos, quietly = TRUE)) {
45
g = SpatialGrid(GridTopology(c(0,0), c(1,1), c(3,3)))
56
p = as(g, "SpatialPolygons")
67
over(g,g)
@@ -39,3 +40,4 @@ rgeos::overGeomGeom(pt,sp,returnList=TRUE, minDimension = 0)
3940
rgeos::overGeomGeom(pt,pt,minDimension=2)
4041
rgeos::overGeomGeom(pt,pt,minDimension=1)
4142
rgeos::overGeomGeom(pt,pt,minDimension=0)
43+
}

vignettes/csdacm.Rnw

+11-8
Original file line numberDiff line numberDiff line change
@@ -961,12 +961,13 @@ Let us first generate, as an example, a set of 100 conditional Gaussian
961961
simulations for the zinc variable in the meuse data set:
962962
\begin{footnotesize}
963963
<<eval=TRUE,echo=TRUE>>=
964-
library(gstat)
965964
data(meuse)
966965
coordinates(meuse) <- ~x+y
967-
v <- vgm(.5, "Sph", 800, .05)
968-
sim <- krige(log(zinc)~1, meuse, meuse.grid, v, nsim=100, nmax=30)
969-
sim@data <- exp(sim@data)
966+
if (require(gstat, quietly = TRUE)) {
967+
v <- vgm(.5, "Sph", 800, .05)
968+
sim <- krige(log(zinc)~1, meuse, meuse.grid, v, nsim=100, nmax=30)
969+
sim@data <- exp(sim@data)
970+
}
970971
@
971972
\end{footnotesize}
972973

@@ -985,16 +986,20 @@ after which we can find the sample lower and upper 95\%
985986
confidence limits by
986987
\begin{footnotesize}
987988
<< >>=
989+
if (require(gstat, quietly = TRUE)) {
988990
sim$lower <- quantile.Spatial(sim[1:100], probs = 0.025)
989991
sim$upper <- quantile.Spatial(sim[1:100], probs = 0.975)
992+
}
990993
@
991994
\end{footnotesize}
992995

993996
To get the sample distribution of the areal median, we can aggregate over
994997
layers:
995998
\begin{footnotesize}
996999
<< >>=
1000+
if (require(gstat, quietly = TRUE)) {
9971001
medians <- quantile.Spatial(sim[1:100], probs = 0.5, byLayer = TRUE)
1002+
}
9981003
@
9991004
<<eval=FALSE>>=
10001005
hist(medians)
@@ -1025,9 +1030,11 @@ fractionBelow <- function(x, q, byLayer = FALSE) {
10251030
options("width"=70)
10261031
@
10271032
<< >>=
1033+
if (require(gstat, quietly = TRUE)) {
10281034
over500 <- 1 - fractionBelow(sim[1:100], 200, byLayer = TRUE)
10291035
summary(over500)
10301036
quantile(over500, c(0.025, 0.975))
1037+
}
10311038
@
10321039
\end{footnotesize}
10331040

@@ -1072,12 +1079,8 @@ if (run) {
10721079
library(rgdal)
10731080
x <- GDAL.open(fn)
10741081
class(x)
1075-
}
1076-
if (run) {
10771082
x.subs <- x[1:100, 1:100, 1]
10781083
class(x.subs)
1079-
}
1080-
if (run) {
10811084
gridparameters(x.subs)
10821085
}
10831086
@

vignettes/over.Rnw

+39-9
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,14 @@ and shown in figure \ref{fig:toy}.
144144

145145
\begin{figure}[htb]
146146
<<fig=TRUE,echo=FALSE>>=
147-
library(RColorBrewer)
148-
pal = brewer.pal(5, "Set2")
149-
plot(pol, xlim = c(-1.1, 2.1), ylim = c(-1.1, 1.6), border=pal, axes=TRUE,
150-
col = paste0(pal, "4D"))
147+
if (require(RColorBrewer, quietly = TRUE)) {
148+
pal = brewer.pal(5, "Set2")
149+
col = paste0(pal, "4D")
150+
} else {
151+
pal = 1:5
152+
col = pal
153+
}
154+
plot(pol, xlim = c(-1.1, 2.1), ylim = c(-1.1, 1.6), border=pal, axes=TRUE, col = col)
151155
points(pts, col='red')
152156
text(c(-1,0.1,0.1,1.9,0.45), c(0.05,0.05,-.95,0.05,0.15),
153157
c("x1", "x2", "x3", "x4", "x5"))
@@ -188,7 +192,9 @@ row.names(pol[pts])
188192
\code{over} can also be used to query polygons in a single object overlay each other:
189193

190194
<<>>=
191-
over(pol, pol, returnList = TRUE)
195+
if (require(rgeos, quietly = TRUE)) {
196+
over(pol, pol, returnList = TRUE)
197+
}
192198
@
193199

194200
\noindent
@@ -300,7 +306,7 @@ text(c(0.52, 1.52), c(1.5, 1.5), c("L1", "L2"))
300306
The set of \code{over} operations on the polygons, lines and points
301307
is shown below (note that lists and vectors are named in this case):
302308
<<>>=
303-
library(rgeos)
309+
if (require(rgeos, quietly = TRUE)) {
304310
over(pol, pol)
305311
over(pol, pol,returnList = TRUE)
306312
over(pol, L)
@@ -309,6 +315,7 @@ over(L, pol, returnList = TRUE)
309315
over(L, L)
310316
over(pts, L)
311317
over(L, pts)
318+
}
312319
@
313320

314321
Another example overlays a line with a grid, shown in figure \ref{fig:grid}.
@@ -319,9 +326,11 @@ gridded(meuse.grid) = ~x+y
319326
Pt = list(x = c(178274.9,181639.6), y = c(329760.4,333343.7))
320327
sl = SpatialLines(list(Lines(Line(cbind(Pt$x,Pt$y)), "L1")))
321328
image(meuse.grid)
322-
xo = over(sl, geometry(meuse.grid), returnList = TRUE)
323-
image(meuse.grid[xo[[1]], ],col=grey(0.5),add=T)
324-
lines(sl)
329+
if (require(rgeos, quietly = TRUE)) {
330+
xo = over(sl, geometry(meuse.grid), returnList = TRUE)
331+
image(meuse.grid[xo[[1]], ],col=grey(0.5),add=T)
332+
lines(sl)
333+
}
325334
@
326335
\caption{ Overlay of line with grid, identifying cells crossed (or touched)
327336
by the line }
@@ -342,17 +351,21 @@ text(coordinates(g), labels = 1:9)
342351

343352
We can match these geometries with themselves by
344353
<<>>=
354+
if (require(rgeos, quietly = TRUE)) {
345355
over(g,g)
346356
over(p,p)
347357
over(p,g)
348358
over(g,p)
359+
}
349360
@
350361
and see that most give a 1:1 match, except for polygons-polygons \code{(p,p)}.
351362

352363
When we ask for the full set of matches, we see
353364
<<>>=
365+
if (require(rgeos, quietly = TRUE)) {
354366
over(px[5], g, returnList = TRUE)
355367
over(p[c(1,5)], p, returnList = TRUE)
368+
}
356369
@
357370
and note that the implementation lets grids/pixels not match
358371
(intersect) with neighbour grid cells, but that polygons do.
@@ -369,8 +382,10 @@ By default, polygon-polygon features are matched by
369382
{\em any} order (feature order, it seems). Although it is slower,
370383
we can however improve on this by switching to \code{rgeos::gRelate}, and see
371384
<<>>=
385+
if (require(rgeos, quietly = TRUE)) {
372386
over(px[5], g, returnList = TRUE, minDimension = 0)
373387
over(p[c(1,5)], p, returnList = TRUE, minDimension = 0)
388+
}
374389
@
375390
When \code{minDimension = 0} is specified, the matching geometries
376391
are being returned based on a nested ordering. First, ordering
@@ -391,7 +406,9 @@ Note that the ordering also determines which feature is matched
391406
when \code{returnList=FALSE}, as in this case the first element of
392407
the ordered set is taken:
393408
<<>>=
409+
if (require(rgeos, quietly = TRUE)) {
394410
over(p, p, minDimension = 0)
411+
}
395412
@
396413

397414
Consider the following example where a point is {\em on} \code{x1} and {\em in} \code{x2}:
@@ -413,12 +430,14 @@ When matching the point \code{pt} with the two polygons, the
413430
sp method (default) gives no preference of the second polygon
414431
that (fully) contains the point; the rgeos method however does:
415432
<<>>=
433+
if (require(rgeos, quietly = TRUE)) {
416434
over(pt,sp)
417435
over(pt,sp,minDimension=0)
418436
over(pt,sp,returnList=TRUE)
419437
rgeos::overGeomGeom(pt,sp)
420438
rgeos::overGeomGeom(pt,sp,returnList=TRUE)
421439
rgeos::overGeomGeom(pt,sp,returnList=TRUE,minDimension=0)
440+
}
422441
@
423442

424443
% # x1 x2
@@ -435,12 +454,14 @@ area overlap {\em or} line in common. This can be done using the
435454
parameter \code{minDimension}:
436455

437456
<<>>=
457+
if (require(rgeos, quietly = TRUE)) {
438458
over(p[5], p, returnList=TRUE, minDimension=0)
439459
over(p[5], p, returnList=TRUE, minDimension=1)
440460
over(p[5], p, returnList=TRUE, minDimension=2)
441461
rgeos::overGeomGeom(pt, pt, minDimension=2) # empty
442462
rgeos::overGeomGeom(pt, pt, minDimension=1) # empty
443463
rgeos::overGeomGeom(pt, pt, minDimension=0)
464+
}
444465
@
445466

446467
\section{Aggregation}
@@ -474,9 +495,11 @@ x 400 m grid}
474495
An example of the aggregated values of \code{meuse.grid} along
475496
(or under) the line shown in Figure \ref{fig:lines} are
476497
<<>>=
498+
if (require(rgeos, quietly = TRUE)) {
477499
sl.agg = aggregate(meuse.grid[,1:3], sl, mean)
478500
class(sl.agg)
479501
as.data.frame(sl.agg)
502+
}
480503
@
481504
Function \code{aggregate} returns a spatial object of the same
482505
class of \code{sl} (\code{SpatialLines}), and \code{as.data.frame}
@@ -490,6 +513,7 @@ specifying {\em how} polygons intersect\footnote{sp versions
490513
in Figure \ref{fig:agg}.
491514

492515
<<>>=
516+
if (require(rgeos, quietly = TRUE)) {
493517
g = SpatialGrid(GridTopology(c(5,5), c(10,10), c(3,3)))
494518
p = as(g, "SpatialPolygons")
495519
p$z = c(1,0,1,0,1,0,1,0,1)
@@ -499,10 +523,12 @@ p$ag1a = aggregate(p, p, mean, minDimension = 0)[[1]]
499523
p$ag2 = aggregate(p, p, mean, minDimension = 1)[[1]]
500524
p$ag3 = aggregate(p, p, mean, minDimension = 2)[[1]]
501525
p$ag4 = aggregate(p, p, areaWeighted=TRUE)[[1]]
526+
}
502527
@
503528

504529
\begin{figure}[ht]
505530
<<echo=FALSE,fig=TRUE>>=
531+
if (require(rgeos, quietly = TRUE)) {
506532
pts = cbind(c(9,21,21,9,9),c(9,9,21,21,9))
507533
sq = SpatialPolygons(list(Polygons(list(Polygon(pts)), "ID")))
508534
rnd2 = function(x) round(x, 2)
@@ -519,6 +545,8 @@ spplot(p, names.attr = c("source", "default aggregate", "minDimension=0",
519545
"minDimension=1", "minDimension=2", "areaWeighted=TRUE"), layout = c(3,2),
520546
as.table=TRUE, col.regions=bpy.colors(151)[50:151], cuts=100,
521547
sp.layout = l, scales = list(draw = TRUE))
548+
} else
549+
plot(1)
522550
@
523551
\caption{Effect of aggregating checker board {\tt SpatialPolygons} by themselves, for
524552
different values of {\tt minDimension} and {\tt areaWeighted}; the green square example
@@ -536,12 +564,14 @@ using {\tt minDimension}, and area weighting for aggregating the 0-1 checker
536564
board of figure \ref{fig:agg} by the green square polygon ({\tt sq})
537565
shown in the last panel of that figure:
538566
<<>>=
567+
if (require(rgeos, quietly = TRUE)) {
539568
round(c(
540569
aggDefault = aggregate(p, sq, mean)[[1]],
541570
aggMinDim0 = aggregate(p, sq, mean, minDimension = 0)[[1]],
542571
aggMinDim1 = aggregate(p, sq, mean, minDimension = 1)[[1]],
543572
aggMinDim2 = aggregate(p, sq, mean, minDimension = 2)[[1]],
544573
areaWeighted = aggregate(p, sq, areaWeighted=TRUE)[[1]]), 3)
574+
}
545575
@
546576

547577

0 commit comments

Comments
 (0)