[R-sig-Geo] Extract values with over()
ASANTOS
alexandresantosbr at yahoo.com.br
Mon Nov 21 20:47:36 CET 2011
Dear colleges,
I try to extract values with over () function , but not working
with my script, when I make:
require(sp)
#Create random points
x <- runif(n=500,min=0, max=20)
y <- runif(n=500,min=0, max=20)
xy<-cbind(x,y)
plot(x=x,y=y,axes=F, xlab="", ylab="",
xlim=c(-1,20),ylim=c(0,21))
pt0 <- c(0.5,0.5)##First point of grid
##Create subarea
limx<-c(2.5,2.5,18,18,2.5)
limy<-c(2.5,18,18,2.5,2.5)
lim=cbind(limx,limy)
lim<-as.matrix(lim)
##Convert in spatial objects of sp package
#Random points
pontos <- SpatialPoints(cbind(x,y))
pontos<- SpatialPoints(list(x,y))
pontos<- SpatialPoints(data.frame(x,y))
#Create the grid
grid0= GridTopology(c(0.5,0.5), c(1,1), c(20,20))
grid<-SpatialGrid(grid = grid0)
##Subarea
limite=SpatialPolygons(list(Polygons(list(Polygon(lim)),"lim")))
##For view
plot(limite)#Subarea
points(pontos,col='red')#Random points
fullgrid(grid)=FALSE
clip<-overlay(grid,limite)##Select the grid inside the subarea
sel.grid <-grid[!is.na(clip),]##Removings Na's that represents the grid
outside the subarea
points(sel.grid,col='blue')# New Grid
over(pontos,sel.grid)
was expected that the over() give the frequency of points inside each
parcel, but I don't know what is the problem,
any suggestion,
Thanks
--
Alexandre DOS SANTOS
Engenheiro Florestal, Msc.
Laboratório de Entomologia Florestal
Departamento de Entomologia
Universidade Federal de Lavras
Caixa Postal 3037
37200-000 - Lavras - Minas Gerais - Brasil
Tel: +55 35 92230304
More information about the R-sig-Geo
mailing list