Skip to content
Prev 9750 / 29559 Next

Changing the coordinates of a SpatialGridDataFrame

Hi there,

I have a SpatialGridDataFrame object and I wish to round the coordinates associated with the grid to three decimal places in order to match points in this object with points on another spatial object where the coordinates are recorded to three decimal places. 

Some information about the obj. It is quite a large grid that covers Australia with over 2 million points in it.
[1] 2287841       2
x         y
[1,] 112.0013 -9.999004
[2,] 112.0263 -9.999004
[3,] 112.0513 -9.999004
[4,] 112.0763 -9.999004
[5,] 112.1013 -9.999004
[6,] 112.1263 -9.999004
x          y
[1,] 112.0013 -43.999004
[2,] 154.0013  -9.999004
min        max
x 111.9888 154.013789
y -44.0115  -9.986504
My first attempt to do the rounding was based on the coordinates function. When I read the help file it  indicates that one can set the coordinates by passing a matrix here. I get an error as listed below.
Error in `coordinates<-`(`*tmp*`, value = c(112.001, 112.026, 112.051,  : 
  setting coordinates cannot be done on Spatial objects, where they have already been set

A second way was suggested to me that involved rounding obj at coords directly. This produces no errors but also doesn't do the job as you can see below. It does round the obj at coords part but this doesn't have any effect on coordinates(obj) or on bbox(obj).
+   obj at coords = round(obj at coords, r)
+   obj
+ }
x       y
[1,] 112.001 -43.999
[2,] 154.001  -9.999
min        max
x 111.9888 154.013789
y -44.0115  -9.986504
x         y
[1,] 112.0013 -9.999004
[2,] 112.0263 -9.999004
[3,] 112.0513 -9.999004
[4,] 112.0763 -9.999004
[5,] 112.1013 -9.999004
[6,] 112.1263 -9.999004
Does anyone know how to go about this in a way that will also not cause other potential problems - ie changing obj at coords doesn't automatically update coordinates(obj) or bbox(obj). 

Thanks in advance,

David

Dr David Clifford
Research Scientist
CSIRO Division of Mathematics, Informatics and Statistics
Phone: +61 7 3214 2816 | Fax: +61 7 3214 2855 
David.Clifford at csiro.au | www.csiro.au | www.csiro.au/people/David.Clifford.html 
Address: CSIRO Long Pocket Laboratories, 120 Meiers Road, INDOOROOPILLY QLD 4068 
New Postal Address from Nov 2010: CSIRO, EcoSciences Precinct, PO Box 2583, Brisbane, QLD 4001
New Street Address from Nov 2010: CSIRO, EcoSciences Precinct, 41 Boggo Road, Annerley, QLD 4103
New Phone from Nov 2010: +61 7 3833 5532

PLEASE NOTE
The information contained in this email may be confidential or privileged. Any unauthorised use or disclosure is prohibited. If you have received this email in error, please delete it immediately and notify the sender by return email. Thank you. To the extent permitted by law, CSIRO does not represent, warrant and/or guarantee that the integrity of this communication has been maintained or that the communication is free of errors, virus, interception or interference.
Please consider the environment before printing this email.