Jan.Verbesselt at csiro.au
2008-Jul-01  08:03 UTC
[R] Are centre coordinates or upper left corners used of x, y for SpatialPixels?
Dear all,
I'm working with satellite images in R and plotting them via the code
below.
I was wondering whether coordinates (spatial["x"],
spatial["y"]) are
used as centre coordinates of the pixels in the GRID? In this script;
spatial["x"] & spatial["y"] are the centre coordinates
of the satellite
image pixels. I'm asking this because some software packages use the
upper left corner of a pixel as a reference.
require(sp)
  # --> Create GRID and image in R
   S <- SpatialPoints(cbind(spatial["x"], spatial["y"]),
proj4string proj)
    SP <- SpatialPixels(S, proj4string = proj, tolerance = 5e-07)
    GRID <- SpatialPixelsDataFrame(points = SP , tolerance = 5e-07, data
= spatial[columnname])
    proj4string(GRID) <- proj
    gridded(GRID)
    
    nr <- 30
    zaxis <- c(0.7, 1)
    plot(as(GRID, "Spatial"), axes=T)
    title(main = paste(" Day ",dy[i,1], " Year ",dy[i,2],
sep=""))
    image(GRID, zlim=zaxis, col=rainbow(nr,start=0, end=2/6),add=T)
Thanks for your help,
Regards,
Jan
Ps. Is this good approach to plot satellite images as spatial grids in
R? is rgdal an better approach?
Paul Hiemstra
2008-Jul-01  08:33 UTC
[R] Are centre coordinates or upper left corners used of x, y for SpatialPixels?
Hi Jan,
In response to your ps. I think using rgdal is the best way to go. If 
your data is for example in a GeoTIFF file, reading it is as simple as:
GRID = readGDAL("your_file.tif")
Saves you some hassel and a number of lines of code.
cheers and hth,
Paul
Jan.Verbesselt at csiro.au wrote:> Dear all,
>
> I'm working with satellite images in R and plotting them via the code
> below.
> I was wondering whether coordinates (spatial["x"],
spatial["y"]) are
> used as centre coordinates of the pixels in the GRID? In this script;
> spatial["x"] & spatial["y"] are the centre
coordinates of the satellite
> image pixels. I'm asking this because some software packages use the
> upper left corner of a pixel as a reference.
>
> require(sp)
>   # --> Create GRID and image in R
>    S <- SpatialPoints(cbind(spatial["x"],
spatial["y"]), proj4string > proj)
>     SP <- SpatialPixels(S, proj4string = proj, tolerance = 5e-07)
>     GRID <- SpatialPixelsDataFrame(points = SP , tolerance = 5e-07, data
> = spatial[columnname])
>     proj4string(GRID) <- proj
>     gridded(GRID)
>     
>     nr <- 30
>     zaxis <- c(0.7, 1)
>     plot(as(GRID, "Spatial"), axes=T)
>     title(main = paste(" Day ",dy[i,1], " Year
",dy[i,2], sep=""))
>     image(GRID, zlim=zaxis, col=rainbow(nr,start=0, end=2/6),add=T)
>
> Thanks for your help,
> Regards,
> Jan
>
> Ps. Is this good approach to plot satellite images as spatial grids in
> R? is rgdal an better approach?
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>   
-- 
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone: 	+31302535773
Fax:	+31302531145
http://intamap.geo.uu.nl/~paul
Paul Hiemstra
2008-Jul-01  08:34 UTC
[R] Are centre coordinates or upper left corners used of x, y for SpatialPixels?
...and in addition: The r-sig-geo mailing list is a better forum for your kind of questions, you are much more likely to get good answers. cheers, Paul Jan.Verbesselt at csiro.au wrote:> Dear all, > > I'm working with satellite images in R and plotting them via the code > below. > I was wondering whether coordinates (spatial["x"], spatial["y"]) are > used as centre coordinates of the pixels in the GRID? In this script; > spatial["x"] & spatial["y"] are the centre coordinates of the satellite > image pixels. I'm asking this because some software packages use the > upper left corner of a pixel as a reference. > > require(sp) > # --> Create GRID and image in R > S <- SpatialPoints(cbind(spatial["x"], spatial["y"]), proj4string > proj) > SP <- SpatialPixels(S, proj4string = proj, tolerance = 5e-07) > GRID <- SpatialPixelsDataFrame(points = SP , tolerance = 5e-07, data > = spatial[columnname]) > proj4string(GRID) <- proj > gridded(GRID) > > nr <- 30 > zaxis <- c(0.7, 1) > plot(as(GRID, "Spatial"), axes=T) > title(main = paste(" Day ",dy[i,1], " Year ",dy[i,2], sep="")) > image(GRID, zlim=zaxis, col=rainbow(nr,start=0, end=2/6),add=T) > > Thanks for your help, > Regards, > Jan > > Ps. Is this good approach to plot satellite images as spatial grids in > R? is rgdal an better approach? > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +31302535773 Fax: +31302531145 http://intamap.geo.uu.nl/~paul