[R-sig-Geo] error message rgdal: dimensions do not match
karl.sommer at dpi.vic.gov.au
karl.sommer at dpi.vic.gov.au
Wed Jul 5 02:02:33 CEST 2006
As suggested by Roger Bivand and Edzer Pebesma I have included the
output of str(t1) and str(SPDF) below.
The error persited when I tried to do the kriging in two steps, using gstat
() and project().
Kriging a different variable, eg. "band1", results in the same error.
Converting t1 to a SpatialPointsDataFrame before kriging results in the
same error.
I also eliminated all zero values before calculating ndvi but the error
persited.
The traceback() info is included below.
Regards
Karl
Indeed strange, given that 880 by 860 is 756800 (though 756800*2 is the
first number). What does summary(t1) say? Is the single column named band1
or ndvi? The class of t1 will be SpatialGridDataFrame, wouldn't
SpatialPointsDataFrame be more digestible? Does doing it in two steps
(gstat() then predict() of the gstat object) show anything? What did
traceback() say after krige()?
Roger
ouput follows:
> str(t1)
Loading required package: sp
Formal class 'SpatialGridDataFrame' [package "sp"] with 6 slots
..@ data :Formal class 'AttributeList' [package "sp"] with 1 slots
.. .. ..@ att:List of 5
.. .. .. ..$ band1: int [1:834470] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ band2: int [1:834470] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ band3: int [1:834470] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ band4: int [1:834470] 0 0 0 0 0 0 0 0 0 0 ...
.. .. .. ..$ ndvi : num [1:834470] NaN NaN NaN NaN NaN NaN NaN NaN NaN
NaN ...
..@ grid :Formal class 'GridTopology' [package "sp"] with 3 slots
.. .. ..@ cellcentre.offset: Named num [1:2] 599029 6228561
.. .. .. ..- attr(*, "names")= chr [1:2] "x" "y"
.. .. ..@ cellsize : num [1:2] 0.5 0.5
.. .. ..@ cells.dim : int [1:2] 917 910
..@ grid.index : int(0)
..@ coords : num [1:2, 1:2] 599029 599487 6228561 6229016
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:2] "x" "y"
..@ bbox : num [1:2, 1:2] 599029 6228561 599487 6229016
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "x" "y"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
.. .. ..@ projargs: chr NA
> str(SPDF)
Formal class 'SpatialPixelsDataFrame' [package "sp"] with 7 slots
..@ data :Formal class 'AttributeList' [package "sp"] with 1 slots
.. .. ..@ att:List of 1
.. .. .. ..$ field: num [1:481262] 1 1 1 1 1 1 1 1 1 1 ...
..@ coords.nrs : num(0)
..@ grid :Formal class 'GridTopology' [package "sp"] with 3 slots
.. .. ..@ cellcentre.offset: Named num [1:2] 599059 6228577
.. .. .. ..- attr(*, "names")= chr [1:2] "s1" "s2"
.. .. ..@ cellsize : Named num [1:2] 0.5 0.5
.. .. .. ..- attr(*, "names")= chr [1:2] "s1" "s2"
.. .. ..@ cells.dim : Named int [1:2] 809 830
.. .. .. ..- attr(*, "names")= chr [1:2] "s1" "s2"
..@ grid.index : int [1:481262] 421 422 423 424 425 426 427 428 429 430
...
..@ coords : num [1:481262, 1:2] 599269 599269 599270 599270 599271
...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:2] "s1" "s2"
..@ bbox : num [1:2, 1:2] 599058 6228577 599463 6228992
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "s1" "s2"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
.. .. ..@ projargs: chr NA
> summary(t1)
Object of class SpatialGridDataFrame
Coordinates:
min max
x 599028.5 599487
y 6228561.0 6229016
Is projected: NA
proj4string : [NA]
Number of points: 2
Grid attributes:
cellcentre.offset cellsize cells.dim
x 599028.8 0.5 917
y 6228561.3 0.5 910
Data attributes:
band1 band2 band3 band4
Min. : 0.0 Min. : 0.0 Min. : 0.0 Min. : 0.0
1st Qu.: 299.0 1st Qu.: 480.0 1st Qu.: 261.0 1st Qu.: 491.0
Median : 347.0 Median : 613.0 Median : 387.0 Median : 776.0
Mean : 302.5 Mean : 540.4 Mean : 467.4 Mean : 633.3
3rd Qu.: 394.0 3rd Qu.: 715.0 3rd Qu.: 637.0 3rd Qu.: 913.0
Max. :2352.0 Max. :3279.0 Max. :2815.0 Max. :1653.0
ndvi
Min. :-3.235e-01
1st Qu.: 9.552e-03
Median : 2.467e-01
Mean : 1.992e-01
3rd Qu.: 4.209e-01
Max. : 7.185e-01
NA's : 2.046e+05
# traceback after kriging provides the following messages
> traceback()
5: .Call("gstat_new_data", as.double(raw$y), as.double(raw$locations),
as.double(raw$X), as.integer(raw$has.intercept), as.double(d$beta),
nmax, nmin, maxdist, as.integer(d$vfn), as.numeric(w), double(0),
as.integer(d$degree))
4: predict.gstat(g, newdata = newdata, block = block, nsim = nsim,
indicators = indicators, na.action = na.action)
3: .local(formula, locations, ...)
2: krige(ndvi ~ 1, t1, SPDF)
1: krige(ndvi ~ 1, t1, SPDF)
# converting to a SpatialPointsDataFrame before kriging resulted in
the same error
t1 <- as(t1, "SpatialPointsDataFrame")
> t1.idw <- krige(ndvi~1, t1, SPDF)
Error: dimensions do not match: locations 1668940 and data 629822
# using two steps as suggested by Roger Bivand results in the same error
> t1.idw <- gstat(id = "ndvi", formula = ndvi ~ 1,
data = t1, nmax = 7, set = list(idp = .5))
> predict(t1.idw, SPDF)
Error: dimensions do not match: locations 1668940 and data 629822
_________________________________
Karl J Sommer,
Department of Primary Industries,
Catchment & Agriculture Services,
PO Box 905
Mildura, VIC, Australia 3502
Tel: +61 (0)3 5051 4390
Fax +61 (0)3 5051 4534
Email: karl.sommer at dpi.vic.gov.au
More information about the R-sig-Geo
mailing list