Skip to content
Prev 21082 / 29559 Next

Warning message: points were rejected as lying outside the specified window

With sincere appreciation for all the suggestions so far I got, and thought it's better to keep you all updated.
To my datasets (coded as "points"), I did the point-in-polygon test with the R code:

library("maps")
library ("sp")
library("spatstat")
library(SDMTools)
usmap <- map("usa", fill=TRUE) 
polypnts = cbind(x=usmap$x, y=usmap$y)
points = cbind(x=my_usdat$x, y=my_usdat$y)
plot(rbind(polypnts, points))
out = pnt.in.poly(points,polypnts)
sum(out==0)
sum(out==1)
It shows that in my dataset there is no points outside of USA map. So the problem I was getting, mainly because of not using the correct coordinate reference system (CRS). It prompted me to apply another strategy that does not require to specify any CRS, posted by Rolf Turner as:

us.df <- with(usmap,data.frame(x=rev(x),y=rev(y)))
us.df <- unique(us.df)
B <- list(list(x=us.df$x, y=us.df$y))
owin(poly=B)

But, got the error message as:
Error in owin(poly = B) : 
  poly must be either a list(x,y) or a list of list(x,y)

After removing all the "NA" cases by the code:

us.df <- us.df[is.na(us.df$x)==FALSE, ]
B <- list(list(x=us.df$x, y=us.df$y))
owin(poly=B)

Got another error message as:
Error in owin(poly = B) : Area of window is negative;
 check that all polygons were traversed in the right direction

It seems I am very close, any idea please! 
Thanks,

Monir
 
-----Original Message-----
From: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
Sent: Sunday, May 18, 2014 11:39 AM
To: Hossain, Md
Cc: Barry Rowlingson; Rolf Turner; r-sig-geo at r-project.org; Adrian Baddeley
Subject: Re: [R-sig-Geo] Warning message: points were rejected as lying outside the specified window
On Sun, 18 May 2014, Hossain, Md wrote:

            
So either you can choose a different approximation to the shoreline you are interested in from another source. Or perhaps buffer it out the maximum distance from the excluded points to the original polygon (see rgeos::gDistance and rgeos::gBuffer)? This may not be adequate, as your polygon and points appear to be in geographical rather than planar coordinates, which will affect the naive distances obtained when using geographical coordinates as if they are planar.

Roger