Skip to content
Prev 3286 / 29559 Next

writing shapefiles using write.pointShape

On Thu, 13 Mar 2008, modern82376 at mypacks.net wrote:

            
See ?tempfile, you were not using it correctly. Whether you should use it 
at all is of course also a good question - see below.
OK so far.
Why this step? It is unnecessary, just use fit.points=fitpts if the output 
Spatial*DataFrame is to be exported as a shapefile. If, on the other hand, 
you want to export it as a raster file, then don't try to write it as a 
shapefile.
If fit.points=fitpts, surv.local$SDF would be a SpatialPointsDataFrame, so 
then just say

fn <- "whatever"
writePointsShape(surv.local$SDF, fn)

and you are done. If you only want pca1, then

writePointsShape(surv.local$SDF[, "pca1"], fn)

will write just that column. If you wanted a raster, fit.points=fitpix, 
and for example:

SGDF <- as(surv.local$SDF["pca1"], "SpatialGridDataFrame")
writeAsciiGrid(SGDF, fn)

will give you an Arc ASCII grid.
You are getting exactly what you asked for - tempfile() is prepending 
"C:\temp" to the random suffix, and putting it into R's temporary 
directory as you requested.
So say:

fn <- "C:/Temp/B1pca1"

and do not use tempfile(). For obvious reasons, the examples in the help 
pages use tempfile() to avoid messing up users' own work.

Roger