Commits

Paul Hiemstra  committed b7f31e4

No using spDists to calculate the diagonal of the area, also
supports non projected data.

  • Participants
  • Parent commits 93af08e

Comments (0)

Files changed (4)

 Description: This package performs an automatic interpolation by automatically estimating the variogram and then calling gstat.
 Depends: R (>= 2.10.0), methods, sp (>= 0.9-55), gstat (>= 0.9-65)
 Imports: lattice
-Suggests: ggplot2,maptools
+Suggests: ggplot2,maptools,gpclib
 License: GPL

File R/autofitVariogram.r

     # is chosen here. A standard boundary set is used and is scaled for the size of the area.
     # This could give problems if the extent of the area is much smaller or larger then the corellation
     # length of the phenomenon that is studied.
-    x = coordinates(input_data)[,1]
-    y = coordinates(input_data)[,2]
-    scale_number = (0.35*sqrt((max(x) - min(x))^2 + (max(y) - min(y))^2) / 100 )   # 0.35 times the length of the central axis through the area
-    boundaries = c(2,4,6,9,12,15,25,35,50,65,80,100) * scale_number                # Boundaries for the bins in km
-
+    longlat = !is.projected(input_data)
+    if(is.na(longlat)) longlat = FALSE
+    diagonal = spDists(t(bbox(input_data)), longlat = longlat)[1,2]                # 0.35 times the length of the central axis through the area
+    boundaries = c(2,4,6,9,12,15,25,35,50,65,80,100) * diagonal * 0.35/100         # Boundaries for the bins in km
+    
+    
 	# If you specifiy a variogram model in GLS.model the Generelised least squares sample variogram is constructed
 	if(!is(GLS.model, "variogramModel")) {
 		experimental_variogram = variogram(formula, input_data,boundaries = boundaries, ...)
         initial_nugget = start_vals[1]
     }
     if(is.na(start_vals[2])) { # Range
-        initial_range = (0.1*sqrt((max(x) - min(x))^2 + (max(y) - min(y))^2) )   # 0.10 times the length of the central axis through the area
+        initial_range = 0.1 * diagonal   # 0.10 times the length of the central axis through the area
     } else {
         initial_range = start_vals[2]
     }

File tests/autoKrige.cv.Rout.save

 
-R version 2.13.0 (2011-04-13)
+R version 2.14.1 (2011-12-22)
 Copyright (C) 2011 The R Foundation for Statistical Computing
 ISBN 3-900051-07-0
 Platform: i686-pc-linux-gnu (32-bit)
 > library(automap)
 Loading required package: sp
 Loading required package: gstat
+Loading required package: spacetime
+Loading required package: zoo
+
+Attaching package: 'zoo'
+
+The following object(s) are masked from 'package:base':
+
+    as.Date, as.Date.numeric
+
+Loading required package: xts
 > 
 > data(meuse)
 > coordinates(meuse) = ~x+y

File tests/automap.Rout.save

 
-R version 2.13.0 (2011-04-13)
+R version 2.14.1 (2011-12-22)
 Copyright (C) 2011 The R Foundation for Statistical Computing
 ISBN 3-900051-07-0
 Platform: i686-pc-linux-gnu (32-bit)
 > library(automap)
 Loading required package: sp
 Loading required package: gstat
+Loading required package: spacetime
+Loading required package: zoo
+
+Attaching package: 'zoo'
+
+The following object(s) are masked from 'package:base':
+
+    as.Date, as.Date.numeric
+
+Loading required package: xts
 > 
 > # Data preparation
 > data(meuse)
 Object of class SpatialPixelsDataFrame
 Coordinates:
      min    max
-x 178440 181560
-y 329600 333760
+x 178460 181540
+y 329620 333740
 Is projected: NA 
 proj4string : [NA]
 Number of points: 3103
 Object of class SpatialPixelsDataFrame
 Coordinates:
      min    max
-x 178440 181560
-y 329600 333760
+x 178460 181540
+y 329620 333740
 Is projected: NA 
 proj4string : [NA]
 Number of points: 3103
 Object of class SpatialPixelsDataFrame
 Coordinates:
      min    max
-x 178440 181560
-y 329600 333760
+x 178460 181540
+y 329620 333740
 Is projected: NA 
 proj4string : [NA]
 Number of points: 3103
 Object of class SpatialPixelsDataFrame
 Coordinates:
      min    max
-x 178440 181560
-y 329600 333760
+x 178460 181540
+y 329620 333740
 Is projected: NA 
 proj4string : [NA]
 Number of points: 3103