Hi

I am new to the sp package.  When I use over() with a
SpatialPolygoneDataframe and SpatialPoints objects I get an object of class
"integer", not a dataframe as the sp help documentation suggests.

The  SpatialPolygoneDataframe object is shape file imported using readOGR.
The SpatialPoints object is a random sample of points within each polygon.
I want to use this information to train a random forest model to classify a
raster image.  So I am using over () to combine the data from the two files
so I can extract the  variable name/class from my shapefile for each
point.  Unfortunately, the result of the over () application is simply a
string of numbers with no attributes.

Here is the code:

# get shapefile
vec<- readOGR('E:/', layer = "DVTraining")
## this is an objective of class SpatialPolygoneDataframe

# Code for abstracting random points from each polygon to create training
data
for (x in 1:9) {
  # Get the metadata for all polygons for a particular class (based on the
uniqueAtt variable)
  class_data<- vec[vec[[attName]]==uniqueAtt[x],]
  # Get the area of each polygon for a particular class
  areas <- sapply(slot(class_data, "polygons"), slot, "area")
  # Calculate the number of samples for each polygon based on the area in
proportion to total area for a class
  nsamps <- ceiling(numsamps*(areas/sum(areas)))
  # Use random sampling to select training points (proportial based on
area) from each polygon for a given class
  for (i in 1:dim(class_data)[1]) {
    xy_class <- spsample(class_data[i,], type="random", n=nsamps[i])
    # Add coordinates to create a list of random points for all polygons
    if (i == 1) cpts <- xy_class
    else cpts <- rbind(cpts, xy_class)
  }
# The number of points might not match numsamps exactly.
  classpts <- cpts
  if (x == 1) {
    xy_allClasses<- classpts
  } else {
    xy_allClasses<- rbind(xy_allClasses, classpts)
  }
}


### Now, combine the points and polygons to get the class number for each
point
temp <- over(vec, xy_allClasses)

Temp is an object of class "integer"  and as such does not have any
attributes - so there are no attribute names for the points.

Thanks for any help.

Note: I borrowed this code from
http://biodiversityinformatics.amnh.org/index.php?section=R_Scripts.  The
original code used readShapePoly to load the shapefile but when I tried
that it came in without a coordinate reference, so I switched to readOGR.

	[[alternative HTML version deleted]]

