[R-sig-Geo] Apparent rotation when plotting a SpatialGridDataFrame?
MacQueen, Don
macqueen1 at llnl.gov
Mon Oct 1 18:14:05 CEST 2012
I have simple data coming to me from an outside source.
x,y are coordinates in a UTM projection, and z is a
measured value at each location.
I make a SpatialPointsDataFrame from it, plot it with spplot(),
and it appears as expected.
I convert to a SpatialGridDataFrame, plot using spplot(),
it appears to have been rotated 90 degrees.
See example code to illustrate below.
Am I doing something wrong?
I used the same sequence of conversions about 7 months ago on
a different set of data and did not see this problem. Inspecting
the two versions of the data does not suggest a problem with
the conversion process. The bounding box is consistent before
and after the conversion.
Here is a simple example to illustrate, followed by sessionInfo()
It should be possible to just source the example code into an
R session.
##
## simple example to illustrate the question
##
require(sp)
## example data
tstdf <- expand.grid(x=1:3, y=1:3)
tstdf$z <- 5
tstdf$z[tstdf$x==tstdf$y] <- 10
## move points to somewhere actually in the zone
tstdf$x <- tstdf$x + 608000
tstdf$y <- tstdf$y + 4167900
## convert to spatial points data frame; UTM projection
tstsp <- tstdf
coordinates(tstsp) <- c('x','y')
proj4string(tstsp) <- CRS('+init=epsg:32610')
print(bbox(tstsp))
## plot
tmppl1 <- spplot(tstsp)
print(tmppl1)
## convert to spatial grid
tstgr <- points2grid(tstsp)
tstsgr <- SpatialGrid(tstgr,
proj4string=CRS('+init=epsg:32610'))
print(bbox(tstsgr))
tstsgrd <- SpatialGridDataFrame(tstgr,
data=tstsp at data,
proj4string=CRS('+init=epsg:32610'))
print(bbox(tstsgrd))
## plot -- compare with first plot
tmppl2 <- spplot(tstsgrd)
print(tmppl2)
##
## sessionInfo()
##
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] sp_1.0-0
loaded via a namespace (and not attached):
[1] grid_2.15.1 lattice_0.20-6
-------------------------------
By the way, the reason for converting to a spatial grid is
so that I can then convert it to a SpatialPolygonsDataFrame,
spTransform() to long/lat and export to KML,
then display in GoogleEarth with a raster-like appearance.
There are no doubt other and likely better ways to accomplish
the same end goal, a raster-like display in GoogleEarth,
but this is a way I found.
--------------------------------
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
More information about the R-sig-Geo
mailing list