代码如下
library(sp)
library(maptools)
library(spatstat)
library(ads)
setwd("E:\\asd100new")
fixstr<-"E:\\lysclip100result\\"
fixstr2<-".shp"
fixstr3<-"E:\\clip100\\"
for (i in 17:606){
Y=1
filename1<- paste(fixstr,i,fixstr2,sep="")
filename2<- paste(fixstr3,i,fixstr2,sep="")
tryCatch({B<-readShapePoints(filename1,verbose=TRUE,repair=TRUE)
C<-readShapePoly(filename2,repair=TRUE)
CC<-as(C,"SpatialPolygons")
W<-as(CC,"owin")
ppc<-ppp(B$coords.x1,B$coords.x2,window=W)
PP<-ppp2spp(ppc)
Y <- kfun(PP,4000,90,nsim=99,prec=0.01,alpha=0.1)},error=function(err){})
jpeg(file=paste(i,".jpeg",sep=""))
plot(Y,main=i)
dev.off()
}