The root of the problem was that you did not notice that writeAsciiGrid in 
maptools can *only* write square grid cells, not rectangular grid cells. The 
following code shows how both spatstat and splancs can be set up to make square 
cells:
 
library(spatstat) 
library(maptools) 
d <- readShapePoints("drawing")
w <- owin(c(-15000,16500),c(-15000,15000)) 
dppp <- as(d["DHL_Sales"], "ppp") 
cpt <- ppp(x=dppp$x, y=dppp$y, marks=dppp$marks, window=w) 
z <- density.ppp(cpt, sigma=500, eps=c(100,100), dimxy=c(315,300))
gridded_z <- as.SpatialGridDataFrame.im(z) 
summary(gridded_z)
writeAsciiGrid(gridded_z, "KDE_Store2.asc") 
library(splancs)
sh_pts <- readShapePoints("drawing")
splancs_pts <- coordinates(sh_pts)
splancs_poly <- bboxx(bbox(sh_pts))
grd <- GridTopology(cellcentre.offset=c(-14950, -14950),
 cellsize=c(100, 100), cells.dim=c(315,300))
kde_sp <- spkernel2d(splancs_pts, splancs_poly, h0=200, grd)
df <- data.frame(kde_sp=kde_sp)
kde_grd <- SpatialGridDataFrame(grd, data=df)
summary(kde_grd)
writeAsciiGrid(kde_grd, "SKDE_Store2.asc")
 
It is also often good practice to use the argument names, which in this case 
would have showed you where the eps= and cellsize= were causing difficulties.
 
Roger
 
--- Roger Bivand, NHH, Helleveien 30, N-5045 Bergen, [EMAIL PROTECTED]

________________________________

Fra: [EMAIL PROTECTED] på vegne av KAM Tin Seong
Sendt: ti 19.06.2007 05:21
Til: KAM Tin Seong; r-sig-geo@stat.math.ethz.ch
Emne: Re: [R-sig-Geo] ESRI ASCII Grid file shifted




Hi all, 

I am new to R and would like to get some advice.  I performed kernel density 
estimation using spatstat.  The point data (i.e. drawing) is in ESRI shapefile 
format.  It was read in using "readShapePoints" of maptools.  After the 
analysis, the result was exported using "writeAsciiGrid" of maptools.  The 
entire codes are as follows:

library(spatstat) 
library(maptools) 
d=readShapePoints("C:/TEMP/shp/drawing") 
w = owin(c(-15000,16500),c(-15000,15000)) 
dppp=as(d["DHL_Sales"], "ppp") 
cpt = ppp(x=dppp$x, y=dppp$y, marks=dppp$marks, window=w) 
plot(dppp) 
z = density.ppp(cpt, 500) 
image(z) 
gridded_z = as.SpatialGridDataFrame.im(z) 
writeAsciiGrid(gridded_z, "C:/TEMP/grid/KDE_Store1.asc") 

When I compared the exported grid file (i.e. KDE_Store1) with the input 
shapefile (i.e. drawing), I notice that there is a shift in the grid file.  
Refer to the enclosed screenshoot.  I wonder if anyone can advice me whats went 
wrong.

Thanks in advance.   

<<KDE1.jpg>> 
Dr Kam Tin Seong
Practice Associate Professor
School of Information Systems

Singapore Management University
80 Stamford Road
Singapore 178902
e-mail: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 
DID: + 65 6828 0932 



        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to