[R-sig-Geo] Warning message: points were rejected as lying outside the specified window
Adrian Baddeley
adrian.baddeley at uwa.edu.au
Sat May 17 03:11:28 CEST 2014
In addition to Rolf's comments:
I suggest you make sure you are using the current version
of spatstat (1.37-0).
In the code below you have set 'checkpolygons=FALSE'
before converting from 'SpatialPolygons' to 'owin'.
That was useful in older versions of 'spatstat'
because the checking was time-consuming. However
turning off the checking carried the risk that the resulting 'owin' object
could be invalid, causing strange things to happen when we test whether a
point lies inside the window, etc.
In spatstat version 1.36-0 and later, polygon data is
automatically repaired by owin() using the package 'polyclip'.
The resulting polygon is always valid; so checking is no longer performed.
So it would be wide to make sure you are running spatstat 1.37-0,
and remove the calls to spatstat.options('checkpolygons').
To inspect the data interactively, you can also use iplot()
regards
Adrian
Prof Adrian Baddeley FAA
University of Western Australia
________________________________________
From: Rolf Turner [r.turner at auckland.ac.nz]
Sent: Saturday, 17 May 2014 8:29 AM
To: Hossain, Md
Cc: 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 16/05/14 02:05, Hossain, Md wrote:
> Hi,
> Apology, my problem may be so simple to answer. I am trying to read disease locations (in longitude and latitude) for 49 adjacent states of USA as an PPP object with the R code:
>
> usdat <- data.frame(x=data$X, y=data2$Y)
> usmap <- map('usa', fill=TRUE, col="transparent", plot=FALSE)
> uspoly <- map2SpatialPolygons(usmap, IDs=usmap$names, proj4string=CRS("+proj=longlat +datum=WGS84"))
> spatstat.options(checkpolygons=FALSE)
> usowin <- as.owin.SpatialPolygons(uspoly)
> spatstat.options(checkpolygons=TRUE)
> pts <- as.ppp(usdat, W=usowin)
> plot(pts)
>
> But, getting the warning messages:
> 1: point-in-polygon test had difficulty with 2 points (total score not 0 or 1)
> 2: In ppp(X[, 1], X[, 2], window = win, marks = marx, check = check) :
> 42 points were rejected as lying outside the specified window
>
> Please suggest if there is any way I can keep these 42 points.
Actually you *do* "keep" them. They form an attribute of your pattern;
this attribute is called "rejects". But they get plotted --- with a
different symbol from the non-rejected points --- when you plot the pattern.
These points are rejected because they lie outside the window that you
have specified. If you want them not to be deemed "rejects" you have
change your window. Or possibly *move* these points slightly. Both of
these strategies are really "cheating" and therefore dubious.
Polygons provided as map boundaries by GIS facilities are almost always
problematic. The boundaries are generally very messy --- that's the
nature of reality. There is apparently a particular problem with your
"usowin" window as indicated by the first warning message. You should
identify the two points that are causing the difficulty and figure out
why the problem is arising.
Plot your pattern that has the rejects and examine the rejects. Figure
out if there is something weird about them, or about the map boundary
near where they lie. Figure out how to fix the weirdness.
To "focus in" on a small region of your window it might be helpful to
use clickpoly():
plot(usowin)
W <- clickpoly(add=TRUE)
# Click on, e.g. 4, points in anticlockwise order to obtain
# a polygon containing the region which you want to examine closely.
# Read the help on clickpoly().
U <- intersect.owin(usowin,W)
plot(U)
You will then probably want to plot the points of "pts" that fall in U
and the points of the rejects that fall in U. Or perhaps in W:
plot(W)
plot(pts,add=TRUE)
plot(usowin,add=TRUE,border="red")
Things like that should give some insight into what is going wrong and
perhaps how to fix it. It will be fiddly. Good luck.
cheers,
Rolf Turner
More information about the R-sig-Geo
mailing list