[Raster-commits] r365 - in pkg/raster: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Mar 17 03:50:03 CET 2009


Author: jacobvanetten
Date: 2009-03-17 03:50:02 +0100 (Tue, 17 Mar 2009)
New Revision: 365

Modified:
   pkg/raster/R/pointdistance.R
   pkg/raster/man/pointdistance.Rd
Log:
pointDistance bug and doc

Modified: pkg/raster/R/pointdistance.R
===================================================================
--- pkg/raster/R/pointdistance.R	2009-03-16 08:29:52 UTC (rev 364)
+++ pkg/raster/R/pointdistance.R	2009-03-17 02:50:02 UTC (rev 365)
@@ -4,7 +4,6 @@
 # Version 0.8
 # Licence GPL v3
 
-
 .pointsToMatrix <- function(p) {
 	if (class(p) == 'SpatialPoints' | class(p) == 'SpatialPointsDataFrame') {
 		p <- coordinates(p)
@@ -60,11 +59,14 @@
 	}
 }
 
-
 .greatCircleDist <- function(x1, y1, x2, y2, r=6378137) {
-	#	cosd <- sin(y1) * sin(y2) + cos(y1) * cos(y2) * cos(x1-x2);
-	#	distance <- r * acos(cosd);
-	#  the following is supposedly more precise than above (http://en.wikipedia.org/wiki/Great_circle_distance):
+	x1 <- x1 * pi / 180
+	y1 <- y1 * pi / 180
+	x2 <- x2 * pi / 180
+	y2 <- y2 * pi / 180
+	#cosd <- sin(y1) * sin(y2) + cos(y1) * cos(y2) * cos(x1-x2)
+	#return(r * acos(cosd))
+	#  the following is supposedly more precise than above (http://en.wikipedia.org/wiki/Great_circle_distance)
 	x <- sqrt((cos(y2) * sin(x1-x2))^2 + (cos(y1) * sin(y2) - sin(y1) * cos(y2) * cos(x1-x2))^2)
 	y <- sin(y1) * sin(y2) + cos(y1) * cos(y2) * cos(x1-x2)
 	return ( r * atan2(x, y) )

Modified: pkg/raster/man/pointdistance.Rd
===================================================================
--- pkg/raster/man/pointdistance.Rd	2009-03-16 08:29:52 UTC (rev 364)
+++ pkg/raster/man/pointdistance.Rd	2009-03-17 02:50:02 UTC (rev 365)
@@ -5,7 +5,7 @@
 \title{distance between points}
 
 \description{
-Calculate the geographic distance between two points on a sphere (\code{type=GreatCircle}) or on a plane (\code{type=distanceEuclidean}).
+Calculate the geographic distance between two points on a sphere (\code{type='GreatCircle'}) or on a plane (\code{type='Euclidean'}).
 }
 
 \usage{
@@ -20,13 +20,13 @@
 
 }
 \details{
-  A sphere is an approximation for the earth (a spheroid) and distanceGreatcircle can thus be used with geographic 
+  A sphere is an approximation for the earth (a spheroid) and type='Greatcircle' can thus be used with geographic 
   coordinates (latitude & longitude). There are probably more sophisticated functions available in other packages.
-  You can use type=Euclidean for coordinates of a map projection such as UTM (but note that in some projections distance is distorted). 
+  You can use type='Euclidean' for coordinates of a map projection such as UTM (but note that in some projections distance is distorted). 
 }
 
 \value{
-  A single value or a vector of values giving the distance in meters (great circle distance) or map-units (for instance, meters in the case of UTM)
+  A single value or a vector of values giving the distance in meters (great-circle distance) or map-units (for instance, meters in the case of UTM)
 }
 
 \author{Robert J. Hijmans and Jacob van Etten }



More information about the Raster-commits mailing list