[Raster-commits] r363 - in pkg/raster: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Mar 15 12:07:54 CET 2009
Author: rhijmans
Date: 2009-03-15 12:07:54 +0100 (Sun, 15 Mar 2009)
New Revision: 363
Modified:
pkg/raster/R/pointdistance.R
pkg/raster/man/raster.Rd
Log:
Modified: pkg/raster/R/pointdistance.R
===================================================================
--- pkg/raster/R/pointdistance.R 2009-03-14 13:26:33 UTC (rev 362)
+++ pkg/raster/R/pointdistance.R 2009-03-15 11:07:54 UTC (rev 363)
@@ -5,36 +5,35 @@
# Licence GPL v3
+.pointsToMatrix <- function(p) {
+ if (class(p) == 'SpatialPoints' | class(p) == 'SpatialPointsDataFrame') {
+ p <- coordinates(p)
+ }
+ if (!is.vector(p) & !is.matrix(p)) {
+ stop('points should be vectors of length 2, matrices with 2 columns, or a SpatialPoints* object')
+ }
+ if(is.vector(p)){
+ if (length(p) != 2) {
+ stop('Wrong length for a vector, should be 2')
+ } else {
+ p <- matrix(p, ncol=2)
+ }
+ } else {
+ if (length(p[1,]) != 2) {
+ stop( 'A points matrix should have 2 columns')
+ }
+ }
+ return(p)
+}
+
+
pointDistance <- function (point1, point2, type='Euclidean', ...) {
if (!(type %in% c('Euclidean', 'GreatCircle'))) {
stop('type should be Euclidean or GreatCircle')
}
-
- for (i in 1:2) {
- if (i == 1) { p <- point1 } else { p <- point2 }
-
- if (class(p) == 'SpatialPoints' | class(p) == 'SpatialPointsDataFrame') {
- p <- coordinates(p)
- }
- if (!is.vector(p) & !is.matrix(p)) {
- stop('points should be vectors of length 2, matrices with 2 columns, or a SpatialPoints* object')
- }
-
- if(is.vector(p)){
- if (length(p) != 2) {
- stop(paste('point', i, '. Wrong length for a vector, should be 2', sep=""))
- } else {
- p <- matrix(p, ncol=2)
- }
- } else {
- if (length(p[1,]) != 2) {
- stop(paste('point', i, '. The matrix should have 2 columns', sep=""))
- }
- }
- if (i == 1) { point1 <- p } else { point2 <- p }
- }
- rm(p)
+ point1 <- .pointsToMatrix(point1)
+ point2 <- .pointsToMatrix(point2)
if(length(point1[,1]) != length(point2[,1])) {
if(length(point1[,1]) > 1 & length(point2[,1]) > 1) {
Modified: pkg/raster/man/raster.Rd
===================================================================
--- pkg/raster/man/raster.Rd 2009-03-14 13:26:33 UTC (rev 362)
+++ pkg/raster/man/raster.Rd 2009-03-15 11:07:54 UTC (rev 363)
@@ -32,12 +32,15 @@
\code{raster(x, values=FALSE, band=1)}
-\item{\code{x}}{character. name of raster file }
-\item{\code{band}}{band number in case of a file of multiple bands, default = 1 }
-\item{\code{values}}{logical. If \code{TRUE}, RasterLayer values will be read into memory with 'readAll()'}
+\tabular{rll}{
+\tab \code{x} \tab character. name of raster file \cr
+\tab \code{band} \tab band number in case of a file of multiple bands, default = 1 \cr
+\tab \code{values} \tab logical. If \code{TRUE}, RasterLayer values are read into memory with \code{\link[raster]{readAll}} \cr
+}
+
If \code{x} is a character value, it should be a filename of a file that the raster package can read. Supported file types are the
-'native' raster package format and those that can be read via rgdal. See ?readGDAL help for supported file types.
+'native' raster package format and those that can be read via rgdal. See \code{\link[gdal]{readGDAL}} help for supported file types.
@@ -45,14 +48,16 @@
\code{raster(nrows=180, ncols=360, xmn=-180, xmx=180, ymn=-90, ymx=90, projs="+proj=longlat +datum=WGS84")}
-\item{\code{nrows}}{number of rows on raster }
-\item{\code{ncols}}{number of columns on raster }
-\item{\code{xmn}}{minimum x coordinate or raster (left border) }
-\item{\code{xmx}}{maximum x coordinate of raster (right border) }
-\item{\code{ymn}}{minimum y coordinate or raster (bottom border) }
-\item{\code{ymx}}{maximum y coordinate of raster (top border) }
-\item{\code{projs}}{character. PROJ4 type description of a map projection}
-\item{\code{bndbox}}{bounding box used to crop a raster. Any object that is a BoundingBox object or contains one (such as Raster* objects)}
+\tabular{rll}{
+ \tab \code{nrows} \tab number of rows on raster \cr
+ \tab \code{ncols} \tab number of columns on raster \cr
+ \tab \code{xmn} \tab minimum x coordinate or raster (left border) \cr
+ \tab \code{xmx} \tab maximum x coordinate of raster (right border) \cr
+ \tab \code{ymn} \tab minimum y coordinate or raster (bottom border) \cr
+ \tab \code{ymx} \tab maximum y coordinate of raster (top border) \cr
+ \tab \code{projs} \tab character. PROJ4 type description of a map projection \cr
+ \tab \code{bndbox} \tab bounding box used to crop a raster. Any object that is a BoundingBox object or contains one (such as Raster* objects) \cr
+}
(item \code{x} is 'missing' in this case)
@@ -62,10 +67,12 @@
\code{raster(x, nrows=10, ncols=10, projs='NA')}
-\item{\code{x}}{BoundingBox object}
-\item{\code{nrows}}{number of rows on raster }
-\item{\code{ncols}}{number of columns on raster}
-\item{\code{projs}}{PROJ4 type description of a map projection}
+\tabular{rll}{
+ \tab \code{x} \tab BoundingBox object \cr
+ \tab \code{nrows} \tab number of rows on raster \cr
+ \tab \code{ncols} \tab number of columns on raster \cr
+ \tab \code{projs} \tab PROJ4 type description of a map projection \cr
+}
@@ -75,9 +82,11 @@
\code{raster(x, filename="", values=NULL)}
-\item{\code{x}}{a Raster* object}
-\item{\code{filename}}{new filename for new RasterLayer }
-\item{\code{values}}{If not \code{NULL} it is used to set values to new object. Either pass a vector of length == ncells(x), or a single number}
+\tabular{rll}{
+ \tab \code{x} \tab a Raster* object \cr
+ \tab \code{filename} \tab new filename for new RasterLayer \cr
+ \tab \code{values} \tab If not \code{NULL} it is used to set values to new object. Either pass a vector of length == ncells(x), or a single number \cr
+}
}}
More information about the Raster-commits
mailing list