[R] Re: using shapefile as owin

Roger Bivand Roger.Bivand at nhh.no
Mon Dec 1 22:25:21 CET 2003


On Mon, 1 Dec 2003, Lisa Schweitzer wrote:

> My sincerest apologies, as this is a very elementary problem, but I have
> searched through archives and FAQs and on the web, and I am at the end of my
> own resources.
> 
> I need to do analysis of a spatial point process occuring with four
> counties, using spatstat. I've had no trouble importing the shapefiles, but
> I can't seem to figure out what I need to do in order to use the boundary as
> an owin. Why I use the Map2poly command, it appears to work, but not when I
> attempt define the window using the shapefile; it also gives me errors when
> I try to define a ppp.object.  I am using the latest release of Raqua on G4.
> My process looks like this:
> 
> #begin code
> > library(maptools)
> > Shapefile<-read.shape("county.shp", dbf.data=TRUE)
> Shapefile Type: Polygon   # of Shapes: 4
> > plot(Shapefile, fg="white")
> > rm(Map)

Why this?

>  
> > shapepoly<-Map2poly(Shapefile, region.id = NULL)

This should create a polylist object as a list with four elements, each 
a ring of county boundary points, an n by 2 matrix with a number of 
attributes.

>      Map2lines(Shapefile)
>      Map2points(Shapefile)
>      Map2bbs(Shapefile)

Why this?

> 
> [[1]]
>              [,1]     [,2]
>    [1,] -116.1655 34.03370
>    [2,] -116.1672 34.03370
>    [3,] -116.1819 34.03364
> 
> #R does its thing for a gillion more lines, then,
> 
> Error in Map2lines(Shapefile) : maptype not line/arc
> 

Obviously, since it is contains polygons ...

> > plot(shapepoly)
> Error in plot.window(xlim, ylim, log, asp, ...) :
>     need finite xlim values
> In addition: Warning messages:
> 1: no finite arguments to min; returning Inf
> 2: no finite arguments to max; returning -Inf
> 3: no finite arguments to min; returning Inf
> 4: no finite arguments to max; returning -Inf

No, not (yet) plot.polylist(), but plotpolys().

> > library(spatstat)
> spatstat 1.3-3
> Type "demo(spatstat)" for a demonstration
> See the Introduction and Quick Reference in
> /Users/lschwei/Library/RAqua/library/spatstat/doc
> > owin(shapepoly)
> Error in owin(shapepoly) : If one of xrange, yrange is specified then both
> must be.

Why would you think that owin() accepts a polylist object as its default 
argument? Although help(owin.object) doesn't tell you, you can finf out 
from:

http://www.maths.uwa.edu.au/~adrian/spatstat/doc/Intro/

that:

"If the window boundary is a single polygon, then p should be a list with 
components x and y giving the coordinates of the vertices of the window 
boundary, traversed anticlockwise. Note that polygons should not be 
closed, i.e. the last vertex should not equal the first vertex. If the 
window boundary consists of several separate polygons, then p should be a 
list, each of whose components p[[i]] is a list with components x and y 
describing one of the polygons. The vertices of each polygon should be 
traversed anticlockwise for external boundaries and clockwise for internal 
boundaries (holes)"

>From the ESRI shapefile definition, we read that the vertices of a single 
ringed polygon are in clockwise order.

So your object does not conform at all to the structure owin() seems to 
need, although there are ways of doing this - contributions welcome 
(owin.polylist() for example).

Roger Bivand

> #end code
> 
> 
> Lisa
> -------
> Lisa Schweitzer 
> Center for the Study of Urban Poverty
> Dept. of Urban Planning
> University of California, Los Angeles
> (lschwei at ucla.edu)
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-help mailing list