In [1]:
##==============================================================
 library(splancs)
 data(cardiff)
 dat <- data.frame(x = cardiff$x, y = cardiff$y,
      n = round(runif(length(cardiff$x), min = 1, max = 10)))
 head(dat)
##==============================================================


Loading required package: sp

Spatial Point Pattern Analysis Code in S-Plus
 
 Version 2 - Spatial and Space-Time analysis

Out[1]:
xyn
193.9992.644
280.1694.8110
378.5990.4810
477.5591.772
575.7291.779
666.0692.648

In [2]:
library(deldir)
 s <- matrix(c(89.9, 28.9, 35.4, 7.9, 39.3, 87.2, 70.7, 
     12.3, 33, 23.3), ncol = 2)
 v <- deldir(s[, 1], s[, 2], rw = cardiff$area)
 plot(cardiff$poly, type = "l", xlab = "Easting", ylab = "Northing")
 plot(v, wline = "tess", pch = 19, cex = 2, add = TRUE)
 points(dat)


deldir 0.1-12

     PLEASE NOTE:  The components "delsgs" and "summary" of the
 object returned by deldir() are now DATA FRAMES rather than
 matrices (as they were prior to release 0.0-18).
 See help("deldir").
 
     PLEASE NOTE: The process that deldir() uses for determining
 duplicated points has changed from that used in version
 0.0-9 of this package (and previously). See help("deldir").


Error in file(con, "rb"):  コネクションを開くことができません 

In [3]:
##==============================================================
 library(maptools)
 v.tl <- tile.list(v)
 tl2sp <- function(x) {
     chrjoin <- function(x) {
         y <- x[1]
         x <- x[-1]
         for (i in 1:length(x)) {
             y <- paste(y, x[1], sep = ",")
             x <- x[-1]
         }
         return(y)
     }
     ys <- paste("y", 1:length(x), sep = "")
     for (i in 1:length(x)) {
         y <- rbind(cbind(x[[i]]$x, x[[i]]$y), cbind(x[[i]]$x[1], 
             x[[i]]$y[1]))
         sy <- Polygons(list(Polygon(y)), paste("y", i))
         eval(parse(text = paste(ys[i], "<- sy")))
     }
     syy <- eval(parse(text = paste("list(", chrjoin(ys), 
         ")")))
     return(SpatialPolygons(syy))
 }
 v.sp <- tl2sp(v.tl)
 v.spdf <- SpatialPolygonsDataFrame(v.sp, data = data.frame(n = 1:5), 
     match.ID = FALSE)
 writePolyShape(v.spdf, fn = "v")


Checking rgeos availability: TRUE

Attaching package: ‘maptools’

The following object is masked from ‘package:sp’:

    nowrapSpatialLines


In [4]:
##==============================================================
 dat.sp <- SpatialPointsDataFrame(SpatialPoints(dat[, 
     1:2]), data = data.frame(dat[, 3]))
##==============================================================

In [5]:
plot(cardiff$poly, type = "l", xlab = "Easting", ylab = "Northing", 
     xlim = c(0, 120), asp = 1)
 cols <- rev(heat.colors(10))
 plot(dat.sp, pch = 19, col = cols[dat.sp@data[, 1]], 
     add = TRUE)
 legend(100, 80, as.character(1:10), col = cols, pch = 19, 
     bty = "n")
 plot(v.spdf, add = TRUE)


Error in file(con, "rb"):  コネクションを開くことができません 

In [6]:
##==============================================================
 res <- overlay(dat.sp, v.spdf, fn = sum)
 v.spdf@data <- cbind(v.spdf@data, pop = res[, 1])
 spplot(v.spdf, zcol = "pop")


Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘overlay’ for signature ‘"SpatialPointsDataFrame"’
Error in cbind(v.spdf@data, pop = res[, 1]):  オブジェクト 'res' がありません 
Error in `[.data.frame`(obj@data, zcol): undefined columns selected

In [ ]: