[R-sig-Geo] sp package/ spatial points operation works in R <= 2.8, fails for R >= 2.9 - resend with file download link

rick reeves reeves at nceas.ucsb.edu
Fri May 21 02:10:13 CEST 2010


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 <- EcoRegion at 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>

-- 
Rick Reeves
Scientific Programmer/Analyst and Data Manager
National Center for Ecological Analysis and Synthesis
UC Santa Barbara
www.nceas.ucsb.edu
805 892 2533



More information about the R-sig-Geo mailing list