[R-sig-Geo] How should i change the shaplefile of a polygon to be used as a window in ppp function of spatstat?--still wrong?

zhijie zhang epistat at gmail.com
Fri Jun 1 13:56:09 CEST 2007


Dear Prof .Roger,
  There is still a little problem with your method, the following are the
programs:

a<-readShapePoly("d:/deleting/a/guichi2.shp")
W <-as(as(a, "SpatialPolygons"), "owin")  # polygons window
plot(W)

cases<-coordinates(readShapePoints('d:/deleting/a/cases.shp'))  #points
cases<-data.frame(cases)
names(cases)<-c("x","y")
cases[1:2,]

plot(W)
points(cases$x,cases$y)  #no errors,83 points were inside the window

W<-as.owin(W)
points<-ppp(cases$x,cases$y,win=W)  *#????????????
**#error*:83 points were rejected as lying outside the specified window in:
ppp(cases$x, cases$y, win = W)
*In fact,* 83 points were inside the specified window,what's wrong?
(This packages:
spatstat     mgcv maptools  foreign       sp
"1.11-6" "1.3-24" "0.6-12" "0.8-20" "0.9-13")
 BTW, i put the data in the attachment so that you can check it.
Thanks.

On 6/1/07, Roger Bivand <Roger.Bivand at nhh.no> wrote:
>
> On Fri, 1 Jun 2007, zhijie zhang wrote:
>
> > Dear friends,
> >   I have a polygon, which is the shapefile format. I want to use it as
> the
> > window of points in ppp(x,y,window) of spatstat package, how should i
> do?
> > The following programs can't work,:
> > a<-readShapePoly("d:/deleting/a/a.shp")  # read the boundary data
> > a2<-Polygon(coordinates(a), hole=as.logical(NA))
> > ppp(x,y,a2)
>
> Using the shapefile shipped with maptools:
>
> library(maptools)
> library(spatstat)
> xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1])
> xx1 <- xx[1,] # and taking just the first county
> plot(xx1)
> W <- as(as(xx1, "SpatialPolygons"), "owin")
> plot(W)
> points(rpoispp(1000, win=W))
>
> (This for:
>
> other attached packages:
> spatstat     mgcv maptools  foreign       sp
> "1.11-5" "1.3-24" "0.6-12" "0.8-20" "0.9-13")
>
> Hope this helps,
>
> Roger
>
>
> >  THANKS.
> >
>
> --
> Roger Bivand
> Economic Geography Section, Department of Economics, Norwegian School of
> Economics and Business Administration, Helleveien 30, N-5045 Bergen,
> Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
> e-mail: Roger.Bivand at nhh.no
>
>


-- 
With Kind Regards,

oooO:::::::::
(..):::::::::
:\.(:::Oooo::
::\_)::(..)::
:::::::)./:::
::::::(_/::::
:::::::::::::
[***********************************************************************]
Zhi Jie,Zhang ,PHD
Tel:86-21-54237149
Dept. of Epidemiology,School of Public Health,Fudan University
Address:No. 138 Yi Xue Yuan Road,Shanghai,China
Postcode:200032
Email:epistat at gmail.com
Website: www.statABC.com
[***********************************************************************]
oooO:::::::::
(..):::::::::
:\.(:::Oooo::
::\_)::(..)::
:::::::)./:::
::::::(_/::::
:::::::::::::
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20070601/b64f58b6/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: data.rar
Type: application/octet-stream
Size: 13328 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20070601/b64f58b6/attachment.obj>


More information about the R-sig-Geo mailing list