• No results found

Estimated intensity

4.4 Using line segment patterns

Line segment patterns (objects of class "psp") were introduced in Section 2.4.4; methods for cre-ating them were described in Section 3.7. An object of class "psp" is effectively a list of line segments, together with a Window, a Frame, and an optional vector or data frame of marks. Each line segment must have both endpoints inside the observation window or on the boundary of the window.

Table 4.17 lists some of the more important functions for manipulating "psp" objects. The Window, Frame, and marks can be extracted and changed in the usual way. For the subset operator

"[.psp" the subset index can be either an index vector (selecting some of the line segments by their position in the list of segments), or a spatial window of class "owin" (computing the intersection between the line segment pattern and the window).

Additionally Table 4.6 lists some generic geometrical operations that are defined for spatial objects including "psp" objects.

Many of the functions listed in Table 4.17 are methods for generic functions for the class "psp".

However, many are not, despite the ‘.psp’ suffix in their names. A complete list of all methods for class "psp" may be obtained by methods(class="psp"). To obtain the larger list of all functions with names ending in ‘.psp’:

> ls(pos="package:spatstat",pattern="\\.psp$")

angles.psp orientation angle of segment as.data.frame.psp extract endpoints and marks if any

as.ppp.psp point pattern consisting of endpoints of segments closing.psp morphological closing of a point pattern

crossdist.psp distances between all pairs of segments from two patterns crossing.psp find any crossing points of two patterns

distfun.psp distance to nearest line segment (as a function) distmap.psp distance to nearest line segment (as a pixel image) endpoints.psp extract the endpoints of each segment

identify.psp find the segment which is nearest to the mouse position lengths.psp compute the length of each segment in a pattern marks.psp extract marks for each segment

"marks<-.psp" change marks for each segment midpoints.psp compute the midpoint of each segment

nndist.psp distance from each segment to its nearest neighbour nnfun.psp nearest-neighbour index map (as a function) nnmap.psp nearest-neighbour index map (as a pixel image) nsegments.psp number of segments in pattern

pairdist.psp matrix of distances between all pairs of segments periodify.psp make a periodic pattern from shifted copies selfcrossing.psp crossing points between the segments

selfcut.psp cuts the segments into pieces at crossing-points

Table 4.17.Functions for manipulating and obtaining information about a "psp" object.

4.5 Tessellations

A tessellation is a division of a window into non-overlapping regions. These regions are called ‘tiles’

(Latin tesserae) although their shape is arbitrary, so they may not look anything like ceramic tiles.

Tessellations are often used to represent administrative or political divisions, such as the subdivision of a country into states or provinces. They can be completely artificial, e.g., the rectangular quadrats which we use in quadrat counting. Tessellations can be observational data, such as the classification of a survey region into different rock types. A tessellation can be computed from data, e.g., the Dirichlet tessellation defined by a set of points.

Note that the tiles of a tessellation must be non-overlapping. The union of the tiles is the window associated with the tessellation: it is this window which is divided up by the tiles. Note that this window could be irregular or disconnected so that there could be apparent ‘gaps’ between the tiles, but these are not part of the window.

Tessellations have several uses in spatstat. A good way to conduct an initial analysis and exploration of a spatial object is to cut that object up into pieces, calculate summaries for each piece, and then examine in some way the relationship amongst these calculated quantities. Cutting an object up into pieces is effectively a ‘tessellation’.

4.5.1 Creating a tessellation

In spatstat tessellations are represented as objects of class "tess". Currently spatstat supports three kinds of tessellations:

• rectangular tessellations in which the tiles are rectangles with sides parallel to the coordinate axes;

• tile lists, tessellations consisting of a list of windows, usually polygonal windows;

• pixellated tessellations, in which space is divided into pixels and each tile occupies a subset of the pixel grid.

Figure 4.27.Types of tessellations.Left: rectangular. Middle: tile list. Right: pixellated.

All three types of tessellation can be created by the command tess. To create a rectangular tessellation:

tess(xgrid=xg, ygrid=yg)

where xg and yg are vectors of coordinates of vertical and horizontal lines determining a grid of rectangles. Alternatively, if you want to subdivide a window W (usually but not necessarily rectangular) by rectangles of equal size, you can use quadrats. Type:

quadrats(W, nx, ny)

where nx,ny are the numbers of rectangles in the x and y directions, respectively. A common use of this command is to create quadrats for a quadrat-counting method.

To create a tessellation from a list of windows, tess(tiles=z)

where z is a list of objects of class "owin". The windows should not be overlapping; currently spatstat does not check this. This command is commonly used when the study region is divided into administrative regions (states, départements, postcode regions, counties) and the boundaries of each sub-region are provided by GIS data files. The window that is tessellated by the list z is by default the union of the tiles, i.e. of the windows which constitute the components of z.

By default, the window of the tessellation will be computed as the union of the tiles. For effi-ciency, the tess function has an argument window which specifies the window. The tess function does not check whether this argument equals the union of the tiles; if it does not then the data will be internally inconsistent.

To create a tessellation from a pixel image:

tess(image=Z)

where Z is a pixel image with factor values. The pixels that have a particular value of the factor constitute a tile. For example, a pixel image indicating land cover type could be separated into tiles associated with each land cover type. These ‘tiles’ do not look like ceramic tiles and may even be disconnected.

The function as.tess can also be used to convert other types of data to a tessellation.

There are two commands which directly compute tessellations from point patterns.

The command dirichlet(X) computes the Dirichlet (or Voronoï or Thiessen) tessellation of the point pattern X. The tile associated with a given point of the pattern X is the region of space which is closer to that point than to any other point of X (see Section 8.2.3). The Dirichlet tiles are polygons. The command dirichlet(X) computes these polygons and intersects them with the window of X.

Figure 4.28.A point pattern X, its Dirichlet tessellation dirichlet(X), and its Delaunay triangu-lation delaunay(X).

The Delaunay triangulation of a point pattern X is a network of straight lines connecting the points. Two points of X are joined if their Dirichlet tiles share a common edge. The resulting network defines a set of non-overlapping triangles, which cover the convex hull of X rather than the entire window containing X. The command delaunay(X) computes the Delaunay triangulation and returns it as a tessellation (object of class "tess") which covers the convex hull of X.

4.5.3 Operations involving a tessellation

Tessellations can be plotted using the plot method plot.tess, which produced Figure 4.27. Alter-natively the function textureplot displays each tile of the tessellation as a polygon filled with a different graphical pattern, as shown in the right panel of Figure 4.10.

There is a method for "[" for subsetting tessellations. This can be used to select out a subset of the tiles which make up the tessellation in question. For example, one could create a tessellation B consisting of the first, third, and fifth tiles of a tessellation A by means of B <- A[c(1,3,5)].

Alternatively the subset index can be a window W: the result of A[W] is the restriction of A to W, that is, the tessellation of W formed by intersecting each tile of A with W.

Use the function tiles to extract a list of the tiles in a tessellation. The result is a list of windows ("owin" objects). This can be handy for computing some characteristic of the tiles in a tessellation, such as their areas or diameters:

> X <- runifpoint(10)

> V <- dirichlet(X)

> U <- tiles(V)

> sapply(U, diameter)

1 2 3 4 5 6 7 8 9 10

0.4708 0.5066 0.4539 0.5076 0.6371 0.6763 0.6485 0.2855 0.2574 0.7334 Tile areas can be computed efficiently using tile.areas.

Tessellations are very handy for classifying the points of a pattern, so that the resulting clas-sification can be used by split.ppp, cut.ppp, and by.ppp. If X is a point pattern and V is a tessellation (of the window of X) then

• cut(X,V) attaches marks to the points of X identifying which tile of V each point falls into (Fig-ure 4.29);

• split(X,V) divides the point pattern into sub-patterns according to the tiles of V, and returns a list of the sub-patterns (Figure 4.30);

• by(X,V,FUN) divides the point pattern into sub-patterns according to the tiles of V, applies the function FUN to each sub-pattern, and returns the results as a list.

10 9 8 7 6 5 4 3 2 1

Figure 4.29.A point pattern X, a tessellation Z, and the result of cut(X,Z).

1 2

3 4 5

6

7 8

9 10 11 12

13

14 15

16

Figure 4.30.The result of split(Z,X).

If we superimpose plots of two tessellations on the same spatial domain (using add=TRUE) what we see is another tessellation. The ‘intersection’ (or ‘overlay’ or ‘common refinement’) of two tessellations X and Y is the tessellation whose tiles are the intersections between tiles of X and tiles of Y. The command intersect.tess computes the intersection of two tessellations. The intersection of tessellations is illustrated in Figure 4.31.

Some other operations for tessellations are listed in Table 4.18. These operations are docu-mented in the help files for spatstat.

4.6 FAQs

• How do I remove the white space around the plot of a point pattern?

Graphics code in spatstat uses the base R graphics system (the package graphics). General

Figure 4.31.Intersection of tessellations.

[.tess subset of tessellation

tiles extract list of tiles of tessellation intersect.tess intersect two tessellations

bdist.tiles compute distance from tile to window boundary chop.tess divide tessellation along a line

rpoislinetess generate tessellation based on random lines Table 4.18.Operations on a tessellation.

properties of a plot such as the text margin are controlled by the graphics parameters managed by the function par: see help(par). To reduce the white space, change the parameter mar.

Typically, par(mar=rep(0.5, 4)) is adequate, if there are no annotations or titles outside the window.

In spatstat, spatial objects such as point patterns and pixel images are always plotted using equal scales on the x and y axes. White space is inevitable if the space available for plotting does not have the same shape (aspect ratio) as the spatial object to be plotted. If you are plotting on a computer screen, then you can change the white space by resizing the plot window using the mouse. (Re-issue the plot command to ensure the text scale is correctly updated.) If you are plotting to a file using postscript or pdf, try specifying the width and height parameters to have roughly the same ratio as the width and height of the spatial object to be plotted.

• How do I add coordinate axes or labels to a plot produced by spatstat?

You can use any base R graphics commands to annotate the plot, such as axis to add a coordinate axis (including tick marks if desired), mtext to add a name to the axis or other text in the margins, and text to add text inside the plot region.

It is strongly recommended to start each new plot with a spatstat command, before adding other graphics. This will ensure that the x and y scales are equal, and avoid many other problems.

• Why doesn’t spatstat show a scale bar on a plot of spatial data?

Because scale markings are deprecated in some research fields, and mandatory in other fields. To plot a scale bar, see the help for yardstick.

• My plot looks good on the computer screen, but when I send the same plot commands to a PDF or Postscript file, it looks different. For example the text is too large, or the plot symbols are too small.

The layout of a plot is sensitive to the plot size parameters width and height, which typically have different default values in the graphics window and in the PDF or Postscript driver. To deter-mine appropriate parameter values, draw the plot on the computer screen, adjust par('mar'), and

resize the window using the mouse, to obtain a satisfactory plot. Repeat the plot command with these new settings to ensure the text size is correctly updated. Use a ruler to measure the physical size of the window in inches (one inch is 2.54 cm). Then pass these parameters as the width and height for postscript or pdf. Some graphics drivers also have an argument pointsize which can be used to control the size of text independently.

• How can I see the internal structure of a "ppp" object, and extract some of the components?

To extract components of a "ppp" object, use the functions coords, marks, as.data.frame, Window, or npoints.

We strongly advise against manipulating the internal structure of objects that belong to a class.

This can cause the data to become internally inconsistent, leading to errors that are very hard to fix. You Have Been Warned.

The internal data in an object could also be quite voluminous, filling your screen with a mess. To see a compact description of the internal structure of an object x, type str(x).

To strip away the class structure entirely, use y <- unclass(x), which can then be printed to reveal the entire data structure. If this is too complicated, use names(y) to determine the names of the components of y, and inspect individual components y[[ i ]].

• Which kinds of spatial data processing should be conducted in spatstat, rather than a GIS or other software?

The main strength of spatstat is statistical inference including exploratory statistics, model-fitting, model validation, nonparametric estimation, and hypothesis testing. For these purposes, spatstat typically has greater functionality than other systems, and the statistical procedures have been carefully checked.

The main strength of a typical GIS is its efficient handling of large spatially referenced datasets, including multiple data types, with efficient and flexible display and user interaction. Although many GIS systems include add-on modules for statistical analysis, the correctness of add-on mod-ules is often difficult to verify.

Consequently, large spatial datasets should first be inspected and edited in specialised software appropriate to the application, such as a GIS. We recommend that statistical inference should usually be performed in spatstat.

• Is it possible in spatstat to extract data from a ‘stack’ of multiple pixel images, in a manner analogous to appying extract() to an object of class RasterStack in the raster package?

Currently spatstat has no objects directly analogous to RasterStack objects (although this will change in the future). Multiple pixel images are normally stored in a list-type object. Data can be extracted from such a list using a function of the lapply genre. Given a list L of images, one could extract the pixel values corresponding to the points of a pattern X via LX<-lapply(L,"[",i=X).

The result LX would be a list of vectors (or factors) of pixel values from the corresponding entries of L.

• Do the Dirchlet/Voronoï tessellation facilities of spatstat provide for weighted tessellations?

No.

• Does spatstat make use of alternative graphical systems such as ggplot2 or lattice, or provide facilities so that users can apply these systems?

No. All of the graphical methods in spatstat are written using base R graphics. Users can, of course, extract any data they wish from spatstat objects and plot these data as they choose.

All data are accessible. It is unlikely that spatstat will be converted to depend on lattice or ggplot2 in the foreseeable future.