Xem mẫu

Chapter 3 Spatial Nichemodelingoftenusesspatialinformationaboutthedistributionofspecies, so Geographic Information Systems (GIS) are often the tool of choice when faced with managing and presenting large amounts of geographic information. However, when the main interest is analysis of moderate amounts of data, as in the previous chapter when R was used as a relational database, R can be used to perform simple spatial tasks. This both avoids the need for a separate GIS system when not necessary, and helps to build knowledge of advanced use of the R language. On the down side, native R operations are not very efficient for spatial operations on large matrices. Vectors and matrices in R, the form necessary for mathematical operations, use quite a lot of memory, thus limiting the size of the data that can be handled. Another approach is to perform basic niche modeling functions on large sets of data with image processing mod-ules. Examples of the image processing package called netpbm performing fundamental analytical operations for modeling are given. 3.1 Data types The two main types of data representing geographic information are: • surface features, such as temperature and rainfall, called raster, and • linear features, such as roads, streams or areas represented by polygons. A raster is a regular grid of numbers, where each number represents the value of a variable in a regular area, or cell. A raster can be represented in R either as a matrix or a vector. The contents of the cells can be integers, floating point numbers, characters or raw bytes. In Figures 3.1 and 3.2 are examples of two ways we might generate a raster to use in analysis: by simulation or input from a data file. The first is a 31 © 2007 by Taylor and Francis Group, LLC 32 Niche Modeling > palette(gray(seq(0, 0.9, len = 30))) > pts <- seq(-pi, pi, by = 0.1) > z <- sin(pts) + (0+1i) * cos(pts) > points <- cbind(Re(z) * 20 + 62, Im(z) * 10 + 26) > t1 <- matrix(255, 124, 52) > t1[points] <- 0 > image(t1, col = 1:30, labels = F) FIGURE 3.1: Example of a simple raster to use for testing algorithms. © 2007 by Taylor and Francis Group, LLC Spatial 33 > x <- readBin("../ZM/layer06", what = "raw", n = 124 * + 52) > image(matrix(as.numeric(x), 124, 52), ylim = c(1, + 0), col = 1:30, labels = F) FIGURE 3.2: Example of a raster from an image file representing the average annual temperature in the continental USA. © 2007 by Taylor and Francis Group, LLC 34 Niche Modeling matrix generated with a sequence of numbers and displayed with the image command. The second is a raw raster dataset stored as an image. Simulated datasets such as these are essential for verifying that code is working correctly, and should always be used to test algorithms before testing on real data. The format of the image data is often a gray scale image, where the data in each cell, called a pixel in an image, is a single byte. Images are an efficient and convenient format of storing large amounts of data, although they have the disadvantage of not containing geographic coordinates to enable alignment with other maps and geographic data. Below, an example of the portable gray map or pgm format used in netpbm has many similarities to most image formats. The code, ‘P2’, called a magic number that identifies the type of the file and next line contains optional comments. The dimensions of the image follow, then the number of colors in the image, and finally the data in each pixel. The disadvantage of the pgm format is the less efficient format without compression of the image data, and the limitation of the range of values limited from 0 to 255. The advantage of the format is simplicity and ease of use. P2 # feep.pgm 24 7 15 0 0 0 0 0 0 0 0 ... The second main type of data are point locations. Sets of related points can be used to form lines like roads and streams, or polygon shapes representing areas. The ordering of the coordinates defines the connections in the road or shape. These can be represented in R either as a matrix with two columns, one for each x and y coordinate, or as vector of complex numbers. The different forms of data, rasters and points combined together make maps. While basic R operations do not support mapping operations, con-tributed additional modules or extensions do. There are, however, a number of other useful features in the base R distribution for simple presentation graphics. Figure 3.4 also illustrates R’s contour function applied to the pre-vious matrix. 3.2 Operations While many operations in professional GIS’s produce professional looking maps, basic R is devoted to analytical operations. Some mathematical oper- © 2007 by Taylor and Francis Group, LLC Spatial 35 > plot(z, type = "l", labels = F) > points(rnorm(100)/3, rnorm(100)/3, cex = abs(rnorm(100))) Re(z) FIGURE 3.3: Examples of vector data, a circle and points of various sizes. © 2007 by Taylor and Francis Group, LLC ... - tailieumienphi.vn
nguon tai.lieu . vn