r - Obtaining the subset of points which are outside a specified irregular polygon using {spatstat} -
r - Obtaining the subset of points which are outside a specified irregular polygon using {spatstat} -
i have big set of points (latitude , longitude) constrained complex polygon. of points not within bounds of polygon, , subset these points original info frame (not ppp object, described below).
#simple illustration of polygon , points. ex.poly <- data.frame(x=c(0,5,5,2.5,0), y=c(0,0,5,2.5,5)) df <- data.frame(x=c(0.5, 2.5, 4.5, 2.5), y=c(4,1,4, 4)) bound <- owin(poly=data.frame(x=ex.poly$x, y=ex.poly$y)) test.ppp <- ppp(x=df$x, y=df$y, window=bound) #plotting example, show 1 out of bound owin object plot(bound) points(df$x, df$y) the error message 1 point rejected lying outside specified window comes up, expected. how subset original dataframe df find out point(s) rejected?
generate boundary , list of points
ex.poly <- data.frame(x=c(0,5,5,2.5,0), y=c(0,0,5,2.5,5)) df <- data.frame(x=c(0.5, 2.5, 4.5, 2.5), y=c(4,1,4, 4)) identify , plot points within , outside polygon using bundle spatstat
library(spatstat) bound <- owin(poly=data.frame(x=ex.poly$x, y=ex.poly$y)) isin<-inside.owin(x=df$x,y=df$y,w=bound) point_in <- df[isin,] point_out <- df[!isin,] plot(bound) points(df) points(point_out,col="red",cex = 3 ) points(point_in,col="green",cex = 3 ) alternatively, using bundle splancs
library(splancs) pts<-as.matrix(df) poly<-as.matrix(ex.poly) point_in<-pip(pts,poly,out=false) point_out<-pip(pts,poly,out=true) plot(pts, ylim=c(0,5), xlim=c(0,5)) polygon (poly) points(point_out,col="red",cex = 3 ) points(point_in,col="green",cex = 3 ) r spatstat
Comments
Post a Comment