Contour function for GeoR

From: Patrick Giraudoux (patrick.giraudoux@univ-fcomte.fr)
Date: Sat Dec 13 2003 - 20:50:38 MET


Allez, au diable les 5 mn pour écrire la fonction. C'est samedi, on est donc en vacance. Voici une version béta d'une fonction permettant de dresser une "contour map" inscrite dans un polygone à partir des paramètres passés à (et reçu de) un krige.conv dans GeoR:

contour.krige<-function(pred.grid,kc,fcshape,addit=F) {

# Create a contour plot, or add contour lines, based on the parameters
# passed to krige.conv (package GeoR). Allows the contours to be limited
# by a polygon

# pred.grid = a N x 2 matrix or data-frame with the 2-D coordinates of
# the N prediction locations of a sqrt(N) x sqrt(N) grid
# kc = vector of predictions (length = N). Typically x$predict or x$krige.var
# dans x<-krige.conv(...)
# fcshape = a two column matrix defining a polygon (passed to the option "borders")
# addit = logical. If `TRUE', add to a current plot. Default is 'FALSE'

    require(splancs)
    long<-sqrt(length(pred.grid[,1]))
    pred.gridna<-inout(pred.grid,fcshape)
    x<-seq(min(pred.grid[,1]),max(pred.grid[,1]),le=long)
    y<-seq(min(pred.grid[,2]),max(pred.grid[,2]),le=long)
    j<-1;z<-rep(0,length(pred.grid[,1]))
    for (i in 1:length(pred.grid[,1])) if (pred.gridna[i]) {z[i]<-kc[j];j<-j+1} else z[i]<-NA
    zR<-matrix(z,ncol=long,nrow=long)
    contour(x,y,zR,add=addit)
    polygon(fcshape)
}
Bien cordialement à tous,

Patrick Giraudoux



This archive was generated by hypermail 2b30 : Tue Sep 07 2004 - 13:45:27 MEST