[R-sig-Geo] SpatialPoints to SpatialGridDataFrame problems
Hailey Eckstrand
haileyeckstrand at gmail.com
Fri Apr 1 23:36:37 CEST 2011
Hello All,
I am trying to convert some points to a SpatialGridDataFrame and am running
into difficulties.
When I convert the SpatialPointsDataFrame into a gridded object, it gives
many warning messages
and the output is incorrect. It says that the cellsize is 500x500 which is
incorrect, it is actually 50,000 by 50,000)
my.pts <- SpatialPointsDataFrame(coords=spatial.coords, data=my.df,
proj4string=CRS(p4s))
gridded(my.pts) <- T
Warning messages:
1: In points2grid(points, tolerance, round) :
grid has empty column/rows in dimension 1
2: In points2grid(points, tolerance, round) :
grid topology may be corrupt in dimension 1
3: In points2grid(points, tolerance, round) :
grid has empty column/rows in dimension 2
4: In points2grid(points, tolerance, round) :
grid topology may be corrupt in dimension 2
str(my.pts)
Formal class 'SpatialPixelsDataFrame' [package "sp"] with 7 slots
..@ data :'data.frame': 35 obs. of 2 variables:
.. ..$ X1: num [1:35] 140.5 84.2 66.3 74.7 98.2 ...
.. ..$ X2: num [1:35] 155.8 73.9 57.4 72.6 88.4 ...
..@ coords.nrs : num(0)
..@ grid :Formal class 'GridTopology' [package "sp"] with 3 slots
.. .. ..@ cellcentre.offset: Named num [1:2] -633000 -4422000
.. .. .. ..- attr(*, "names")= chr [1:2] "x" "y"
.. .. ..@ cellsize : Named num [1:2] 500 500
.. .. .. ..- attr(*, "names")= chr [1:2] "x" "y"
.. .. ..@ cells.dim : Named int [1:2] 503 902
.. .. .. ..- attr(*, "names")= chr [1:2] "x" "y"
..@ grid.index : int [1:35] 453405 453505 453605 453706 402904 403005
403105 403205 403305 403406 ...
..@ coords : num [1:35, 1:2] -532500 -482500 -432500 -382000 -633000
...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:2] "x" "y"
..@ bbox : num [1:2, 1:2] -633250 -4422250 -381750 -3971250
.. ..- 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 " +proj=stere +lat_0=90 +lat_ts=60 +lon_0=-110
+k=1 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs
+towgs84=0,0,0"
I have also tried to build the GridTopology & glue it together with my data:
gtop.coords.min <- c(min(spatial.coords[,1]), min(spatial.coords[,2]))
gtop.coords.max <- c(max(my.coords[,1]), max(my.coords[,2]))
gtop.cell.size <- c(50000, 50000)
gtop.cells.dim.xc <- length(seq(gtop.coords.min[1], gtop.coords.max[1],
by=gtop.cell.size[1]))
gtop.cells.dim.yc <- length(seq(gtop.coords.min[2], gtop.coords.max[2],
by=gtop.cell.size[2]))
gtop.cells.dim <- c(gtop.cells.dim.xc, gtop.cells.dim.yc)
cangrid.gtop <- GridTopology(gtop.coords.min, gtop.cell.size,
gtop.cells.dim)
str(cangrid.gtop)
Formal class 'GridTopology' [package "sp"] with 3 slots
..@ cellcentre.offset: num [1:2] -633000 -4422000
..@ cellsize : num [1:2] 50000 50000
..@ cells.dim : int [1:2] 6 10
SpatialGridDataFrame(grid=cangrid.gtop, data=my.df, proj4string=CRS(p4s))
Error in validityMethod(object) :
unequal number of objects in full grid and data slot
I have included an image of what the coordinates look like. Here is a
description of my variables:
p4s
"+proj=stere +lat_0=90 +lat_ts=60 +lon_0=-110 +k=1 +x_0=0 +y_0=0
+ellps=GRS80 +datum=NAD83 +units=m +no_defs"
spatial.coords
x y
1 -532500 -4422000
2 -482500 -4422000
3 -432500 -4422000
4 -382000 -4422000
5 -633000 -4372000
6 -582500 -4372000
7 -532500 -4372000
8 -482500 -4372000
9 -432500 -4372000
10 -382000 -4372000
11 -583000 -4322000
12 -532500 -4322000
13 -482500 -4322000
14 -432500 -4322000
15 -382000 -4322000
16 -583000 -4272000
17 -532500 -4272000
18 -482500 -4272000
19 -432500 -4272000
20 -382000 -4272000
21 -583000 -4222000
22 -532500 -4222000
23 -482500 -4222000
24 -432500 -4222000
25 -583000 -4172000
26 -532500 -4172000
27 -482500 -4172000
28 -583000 -4122000
29 -532500 -4122000
30 -482500 -4122000
31 -633000 -4071500
32 -583000 -4072000
33 -532500 -4072000
34 -583000 -4021500
35 -633000 -3971500
str(my.df)
'data.frame': 35 obs. of 2 variables:
$ X1: num 140.5 84.2 66.3 74.7 98.2 ...
$ X2: num 155.8 73.9 57.4 72.6 88.4 ...
Many thanks,
Hailey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20110401/64f627fc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: points_to_sgdf.JPG
Type: image/jpeg
Size: 12893 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20110401/64f627fc/attachment.jpe>
More information about the R-sig-Geo
mailing list