MAJOR=248
MINOR=1
DEVNAME=bsg/0:0:1:0
  7   -ˆl–Ü4ý( ©”u( 	•åÀ¹p.)‹Fÿ�þ_�¯¬Ü¢#Î‘§_h þË„h	¿ÐÁÍ ?÷     -%% $Id: csdacm.Rnw,v 1.44 2008-04-06 20:47:04 roger Exp $
% -*- mode: noweb; noweb-default-code-mode: R-mode; -*-

% merge all depth coefficients!!

% Customising spatial data analysis classes and methods

%\SweaveOpts{echo=TRUE}
%*Intro and plan*

%motivate spatial data handling
\documentclass{article}
% \VignetteIndexEntry{Customising spatial data classes and methods}

\usepackage{graphicx}
\usepackage[colorlinks=true,urlcolor=blue]{hyperref}

\usepackage{color}

\usepackage{Sweave}
\SweaveOpts{keep.source=FALSE}
\usepackage{natbib}

\newcommand{\strong}[1]{{\normalfont\fontseries{b}\selectfont #1}}
\let\pkg=\strong

\newcommand\code{\bgroup\@codex}
\def\@codex#1{\small {\normalfont\ttfamily\hyphenchar\font=45 #1}\egroup}

\usepackage{xspace}
\def\RR{\textsf{R}\xspace}
\def\SP{\texttt{S-PLUS}\texttrademark\xspace}
\def\SS{\texttt{S}\xspace}
\def\SIII{\texttt{S3}\xspace}
\def\SIV{\texttt{S4}\xspace}

\title{{\bf Customising spatial data classes and methods}\footnote{This vignette formed pp. 127--148 of the first edition of Bivand, R. S.,
Pebesma, E. and G\'{o}mez-Rubio V. (2008) Applied Spatial Data Analysis with R,
Springer-Verlag, New York. It was retired from the second edition (2013) to
accommodate material on other topics, and is made available in this form
with the understanding of the publishers. It has been updated to the 2013
state of the software, e.g. using \code{over}.} }
\author{Edzer Pebesma\footnote{Institute for Geoinformatics,
University of Muenster, Weseler Strasse 253, 48151 M\"{u}nster, Germany.
{\tt edzer.pebesma@uni-muenster.de}}}
\date{Feb 2008}

\begin{document}

\maketitle
\tableofcontents

<<echo=FALSE>>= 
owidth <- getOption("width")
options("width"=90)
.PngNo <- 0
@

<<label=figreset,echo=FALSE,eval=FALSE>>= 
.iwidth <- 5
.iheight <- 6
.ipointsize <- 12
@

<<echo=FALSE,results=hide>>= 
<<figreset>>
@
<<label=afig,echo=FALSE,eval=FALSE>>= 
.PngNo <- .PngNo + 1; file <- paste("Fig-bitmap-", .PngNo, ".pdf", sep="")
pdf(file=file, width = .iwidth, height = .iheight, pointsize = .ipointsize)
opar <- par(mar=c(3,3,1,1)+0.1)
@

<<label=zfig,echo=FALSE,eval=FALSE>>= 
dev.null <- dev.off()
cat("\\includegraphics[width=0.95\\textwidth]{", file, "}\n\n", sep="")
@

Although the classes defined in the \pkg{sp} package cover many needs,
they do not go far beyond the most typical GIS data models. In applied
research, it often happens that customised classes would suit the
actual data coming from the instruments better. Since \SIV classes have
mechanisms for inheritance, it may be attractive to build on the \pkg{sp}
classes, so as to utilise their methods where appropriate. Here, we will
demonstrate a range of different settings in which \pkg{sp} classes can
be extended. Naturally, this is only useful for researchers with specific
and clear needs, so our goal is to show how (relatively) easy it may be
to prototype classes extending \pkg{sp} classes for specific purposes.

\section{Programming with classes and methods}
\label{sect:cls}

This section will explain the elementary basics of programming with
classes and methods in \RR. The \SS language (implemented in \RR and
\SP) contains two mechanisms for creating classes and methods: the
traditional \SIII system and the more recent \SIV system (see Section 2.2 in
\cite{bivand}, in which classes were described for the use{\RR} ---
here they are described for the develope{\RR}).  This chapter is not a
full introduction to \RR programming \citep[see][for more details]{braun+murdoch:07}, but it will try to give some
feel of how the \code{Spatial} classes in package \pkg{sp} can be
extended to be used for wider classes of problems.  For full details,
the interested reader is referred to e.g.\ \cite{R:Venables+Ripley:2000}
and \cite{R:Chambers:1998}, the latter being a reference for new-style
\SIV classes and methods. Example code is for example found in the source
code for package \pkg{sp}, available from CRAN.

Suppose we define myfun as
\begin{footnotes