[R-sig-Geo] creating a SGDF with transformed coordinates and spatial aggregation

Swagath Navin swagathnavin82 at gmail.com
Tue Mar 5 16:38:49 CET 2013


Sorry..i am resending my mail again ..first mail i sent as HTML format
Dear all,

I have a large data frame in form of (Lon, Lat, Value) ((coordinates in 
EPSG:3035). I can convert the data frame into a object of class SGDF 
using the following commands:

coordinates(df)=~x+y
proj4string(df)=CRS("+init=epsg:3035")
gridded(pts) = TRUE
fullgrid(pts)=TRUE

getGridTopology(df)

                      x       y
cellcentre.offset 2638500 1430500
cellsize             5000    5000
cells.dim             664     797

However, when i transform the coordinates to EPSG:4326 and then try to 
convert it to a SGDF, i get the following error:

coordinates(df)=~x+y
proj4string(df)=CRS("+init=epsg:3035")
pts = spTransform(df,CRS("+init=epsg:4326"))
gridded(df) = TRUE

suggested tolerance minimum: 0.154774
Error in points2grid(points, tolerance, round) :
   dimension 1 : coordinate intervals are not constant

Any ideas, how i can obtain a regular grid.

And off-course a reproducible example:

x=c(5013500, 5018500, 4883500, 4888500, 4893500, 4898500, 4908500, 
4948500, 4953500, 4958500, 4963500, 4973500, 4978500, 4988500, 5008500, 
5013500, 5028500, 4878500, 4883500, 4888500, 4893500, 4898500, 4903500, 
4928500, 4963500, 4968500, 4973500, 4978500, 4983500, 4988500)

y=c(5395500, 5395500, 5390500, 5390500, 5390500, 5390500, 5390500, 
5390500, 5390500, 5390500, 5390500, 5390500, 5390500, 5390500, 5390500, 
5390500, 5390500, 5385500, 5385500, 5385500, 5385500, 5385500, 5385500, 
5385500, 5385500, 5385500, 5385500, 5385500, 5385500, 5385500)

z=c(1.74, 1.74, 1.82, 1.82, 1.82, 1.81, 1.81, 1.78, 1.77, 1.77, 1.76, 
1.76, 1.75, 1.74, 1.73, 1.73, 1.72, 1.82, 1.82, 1.81, 1.81, 1.80, 1.80, 
1.78, 1.75, 1.75, 1.74, 1.74, 1.73, 1.73)

df1=data.frame(x,y,z)
coordinates(df1) <- c("x", "y")
proj4string(df1)=CRS("+init=epsg:3035")
df1 = spTransform(df1,CRS("+init=epsg:4326"))

gridded(df1)=TRUE
suggested tolerance minimum: 0.311581
Error in points2grid(points, tolerance, round) :
   dimension 1 : coordinate intervals are not constant

And with the example data, the spatial resolution is 5 km * 5 km and i 
would like to aggregate  to 15*15 km. The new cellsize would be now an 
average of the corresponding values in 3*3 cells. Also what to do if 
come grid cells contain NA. I would be thankful if people could provide 
some ideas on how to get around this.

Thanks a lot for your time.

Navin



More information about the R-sig-Geo mailing list