我有数据在边界外有数字,我试图使用下面的代码得到非加权和加权图像,但结果是一个非常小的图像,我可以看到数据在那里绘制,但它非常小:
RM(列表= LS()) setwd("〜/桌面/野生&#34) 库(' spatstat') 库(' SP') 库('光栅') 库(' maptools') 库(' rgeos') DATA1< -read.table(" AllObs.csv" 09月="",标题= TRUE) coordinates(data1)< - ~utm_x + utm_y 类(数据1) [1]" SpatialPointsDataFrame" ATTR("包&#34) [1]" sp"
导入Shapefile
约束< -readShapePoly("〜/桌面/野生动物/ Bounding_Box.shp&#34) 建筑< -readShapePoly("〜/桌面/野生动物/ BuildingFootsprints.shp&#34) 水< -readShapePoly("〜/桌面/野生动物/ Water_Bodies.shp&#34)
空间线
Roads_uw< -readShapeLines("〜/桌面/野生动物/ Roads_uw.shp&#34) 小溪< -readShapeLines("〜/桌面/野生动物/ Creeks.shp&#34) 道路及LT; -readShapeLines("〜/桌面/野生动物/ Roads.shp&#34)
绘制空间数据
参数(MAR = C(0.1,0.1,0.1,0.1)) 剧情(绑定) 框() data1< - data1 [!is.na(over(x = data1,y = as(bound," SpatialPolygons"))),] plot(building,add = TRUE,col =" pink",cex = 0.3,pch = 16) plot(Roads,add = TRUE,col =" black",cex = 0.3,pch = 16) plot(Roads_uw,add = TRUE,cex = 0.3,pch = 16) plot(water,add = TRUE,col =" cyan",lwd = 1) plot(creeks,add = TRUE,col =" red",lwd = 1) 传奇(" topright",inset = 0.001,cex = 0.7, + c(" Building"," Roads"," Roads_uw"," Water"," Creeks"),pch = c(16,NA),lty = c(NA,1),col = c("粉红色","黑","黑",&# 34;青色""红色&#34))
按学习区域剪辑额外
building_cl< -gIntersection(spgeom1 =建筑物,spgeom2 =结合)的 Roads_cl< -gIntersection(spgeom1 =道路,spgeom2 =结合)的 Roads_uw< -gIntersection(spgeom1 = Roads_uw,spgeom2 =结合) water_cl< -gIntersection(spgeom1 =水,spgeom2 =结合)的 creeks_cl< -gIntersection(spgeom1 =小溪,spgeom2 =结合)的
绘制空间数据
参数(MAR = C(0.1,0.1,0.1,0.1)) 剧情(绑定) 框() plot(building_cl,add = TRUE,col =" pink",cex = 0.3,pch = 16) plot(Roads_cl,add = TRUE,col =" black",cex = 0.3,pch = 16) plot(Roads_uw,add = TRUE,cex = 0.3,pch = 16) plot(water_cl,add = TRUE,col =" cyan",lwd = 1) plot(creeks_cl,add = TRUE,col =" red",lwd = 1) 传奇(" topright",inset = 0.001,cex = 0.7, + c(" Building"," Roads"," Roads_uw"," Water"," Creeks"),pch = c(16,NA),lty = c(NA,1),col = c("粉红色","黑","黑",&# 34;青色""红色&#34))
点模式分析
DATA2< -read.table(" PPP.csv" 09月="",标题= TRUE) data2win< -owin(C(分钟(DATA2 $ utm_x)-10000,最大值(DATA2 $ utm_x)万), + c(min(data2 $ utm_y)-10000,max(data2 $ utm_y)+10000)) data2win window:rectangle = [525488,547767] x [4801386,4844192]个单位 data2pp< -ppp(X = data2的$ utm_x,Y = data2的$ utm_y,窗口= data2win) data2pp 平面点图案:106点 window:rectangle = [525488,547767] x [4801386,4844192]个单位 sigma< - bw.ppl(data2pp) data2_nw< -density(data2pp,sigma = sigma) data2_w< -density(data2pp,sigma = sigma,weights = data2 $ num_indiv)
将非加权转换为栅格
data2_nwr< -raster(data2_nw) data2_nwr< -mask(data2_nwr,结合)的
将加权图像转换为栅格
data2_wr< -raster(data2_w) data2_wr< -mask(data2_wr,结合)的
设置两个面板图
参数(mfrow = C(1,1),擦伤= C(1,1,1,1))
在上面板中绘制非加权
plot(data2_nwr,axes = FALSE,main =" Non-Weighted") plot(bound,add = TRUE) 框() 点(DATA2 $ utm_x,DATA2 $ utm_y,PCH = 16,CEX = 0.3) plot(building_cl,add = TRUE,col =" pink",cex = 0.2,pch = 16) plot(Roads_cl,add = TRUE,col =" black",cex = 0.2,pch = 16) plot(Roads_uw,add = TRUE,cex = 0.2,pch = 16) plot(water_cl,add = TRUE,col =" cyan",lwd = 0.2) plot(creeks_cl,add = TRUE,col =" red",lwd = 0.2)
在下图中加权的情节
plot(data2_wr,axes = FALSE,main =" Weighted") plot(bound,add = TRUE) 点(DATA2 $ utm_x,DATA2 $ utm_y,PCH = 16,CEX = 0.2) plot(building_cl,add = TRUE,col =" pink",cex = 0.2,pch = 16) plot(Roads_cl,add = TRUE,col =" black",cex = 0.2,pch = 16) plot(Roads_uw,add = TRUE,cex = 0.2,pch = 16) plot(water_cl,add = TRUE,col =" cyan",lwd = 0.2) plot(creeks_cl,add = TRUE,col =" red",lwd = 0.2) 传奇(" topright",inset = 0.001,cex = 0.7, + c(" Building"," Roads"," Roads_uw"," Water"," Creeks"),pch = c(16,NA),lty = c(NA,1),col = c("粉红色","黑","黑",&# 34;青色""红色&#34))
我们的教授也给了我们这个代码,这是为了消除这个错误:
data2< - data2 [!is.na(over(x = data2,y = as(bound," SpatialPolygons"))),]
但是当我尝试使用它时,我收到此错误: (函数(classes,fdef,mtable)中的错误: 无法为签名'" data.frame"," SpatialPolygons"'
找到函数'over'的继承方法感谢您的帮助!