Hi Rick, thanks for the clean and reproducable example. instead of
SampPointsOneDeg <- as(SampGridOneDeg, "SpatialPoints") you now need to do a SampPointsOneDeg <- as(as(SampGridOneDeg, "SpatialPixels"),"SpatialPoints") to make your example work. As these coercion functions were written a long time ago I believe that the reason it stopped working are changes in the methods package rather than in sp. I'd agree that the first one should work as well, and I'll have a look at modifying sp such that it will, again, in the future. -- Edzer On 05/21/2010 02:10 AM, rick reeves wrote: > Hello List: > > The following script creates a point grid at user-supplied spatial > resolution; > this grid (SpatialPoints) is then used as an input to sp/overlay() to > extract > points at regular intervals from a SpatialPolygonsDataFrame object. > > Downloat the code and data for this example at: > http://www.nceas.ucsb.edu/files/scicomp/Dloads/CreatePointGridSP.zip > > CreatePointGrid <- function() > { > library(rgdal) # loads sp package > > # Read ESRI Shape File into SpatialPolygonsDataFrame > > EcoRegion <- > readOGR("BaileysEcoRegionUsaGP.shp","BaileysEcoRegionUsaGP") > theProjection <- proj4string(EcoRegion) > > vals <- ecoreg...@bbox > deltaLong <- as.integer((vals[1,2] - vals[1,1]) + 1.5) > deltaLat <- as.integer((vals[2,2] - vals[2,1]) + 1.5) > > # grid resolution units: decimal degress. > > gridRes <- 1.0 > gridSizeX <- deltaLong / gridRes > gridSizeY <- deltaLat / gridRes > > # GridTopology object is basis for sampling grid > > GridTopoOneDeg <- GridTopology(vals[,1], > c(gridRes,gridRes), > c(gridSizeX,gridSizeY)) > > # Create the SpatialGrid object.... > > SampGridOneDeg <- SpatialGrid(GridTopoOneDeg,proj4string = > CRS(theProjection)) > SampPointsOneDeg <- as(SampGridOneDeg,"SpatialPoints") > message("hit key to see first 20 points of One Degree Grid Points...") > browser() > print(SampPointsOneDeg[1:20,]) > message("done") > } > The issue: the line: > > SampPointsOneDeg <- as(SampGridOneDeg,"SpatialPoints") > > ...generates the required list of points when the script is run under > R version 2.8 and earlier. > However, if the script is run under R 2.9 or greater, the point list > contains only 2 coordinate pairs. > > Question: What has changed in R 2.9 and later? Is this technique > deprecated, and is there a better > way of creating such a point list? > > Thanks, > Rick R > > < Attached zip file contains the script and sample data set> > -- Edzer Pebesma Institute for Geoinformatics (ifgi), University of Münster Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebe...@wwu.de _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo