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>

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

_______________________________________________
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