Book Image

Learning R for Geospatial Analysis

By : Michael Dorman
Book Image

Learning R for Geospatial Analysis

By: Michael Dorman

Overview of this book

Table of Contents (18 chapters)
Learning R for Geospatial Analysis
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
External Datasets Used in Examples
Cited References
Index

Preface

The defining feature of spatial data analysis is the reference within the data being analyzed to locations on the surface of the earth. This is a very broad subject encompassing distinct areas of expertise such as spatial statistics, geometric computation, and image processing.

In practice, spatial data is commonly stored, viewed, and analyzed in Geographic Information System (GIS) software, of which the most well-known example is ArcGIS. However, most often, menu-based interfaces of GIS software are too narrow in scope to meet specialized demands or too inflexible to feasibly accomplish customized repetitive tasks. Writing scripts rather than using menus or working in combination with external software are two commonly used paths to solve such problems. However, what if we can use a single environment, combining the advantages of programming and spatial data analysis capabilities with a comprehensive ecosystem of computational tools that are readily implementable in customized procedures?

This book will demonstrate that the R programming language is indeed such an environment and teach you how to use it in order to perform various spatial data analysis tasks.

Most currently available books on this subject are focused on advanced applications such as spatial statistics, assuming you have prior knowledge of R and the respective scientific domains. Yet, introductory material on R from the point of view of a spatial data analyst, which is focused on introductory topics such as spatial data handling, computation, and visualization, is scarce. This book aims to fill that gap.

What this book covers

Chapter 1, The R Environment, introduces the R environment, shows how to install R, and how to use it. Some of the basic concepts related to writing R code are introduced.

Chapter 2, Working with Vectors and Time Series, covers the basic data structure in R, which is vector. The main types of vectors (numeric, character, and logical) as well as basic operations on vectors (such as subsetting and summarizing vector properties) are reviewed. Working with dates and displaying a graphical output, two highly relevant abilities commonly applied later in the book, are also introduced in this chapter.

Chapter 3, Working with Tables, focuses on tables and automated calculations in R. This chapter teaches you how tabular data can be handled and how calculations of a repetitive nature based on tabular data can be carried out using loops and conditional statements. Reshaping and joining tables (vital skills for any data analysis) are also covered.

Chapter 4, Working with Rasters, brings the reader into the realm of spatial data analysis in R, starting with the raster data structure. Basic operations such as import and export, visualization and summary, and subsetting and extraction of raster values are covered here. Simple manipulations of raster values, including assignment, raster algebra, and reclassification are also presented.

Chapter 5, Working with Points, Lines, and Polygons, covers the second type of spatial data structures—vector layers. The basic methodology of working with point, line, and polygon layers is reviewed, followed by the coverage of more advanced operations, including reprojection, geometric calculations, spatial querying, and joining new data to existing layers.

Chapter 6, Modifying Rasters and Analyzing Raster Time Series, covers several advanced themes associated with raster data analysis in R. Geometric modifications of raster data, such as cropping, mosaicking, and aggregating are reviewed. Operations related to cell neighborhoods, including focal filtering, clumping, and topography-related calculations are covered next. Additional themes include resampling, reprojection, and handling of spatio-temporal raster data.

Chapter 7, Combining Vector and Raster Datasets, integrates the material presented in Chapter 5, Working with Points, Lines, and Polygons, and Chapter 6, Modifying Rasters and Analyzing Raster Time Series, by demonstrating how rasters and vector layers can be combined in a single analysis. Transformation between raster and vector data structures as well as data extraction from a raster based on vector layers are covered in this chapter.

Chapter 8, Spatial Interpolation of Point Data, presents the subject of spatial interpolation in R from a practical point of view. Using a real-world case study, several common interpolation methods are applied and evaluated. An automated interpolation procedure is then constructed in order to create a series of interpolated maps from point data.

Chapter 9, Advanced Visualization of Spatial Data, shows readers how to produce publication-quality maps mainly using the popular ggplot2 R package.

Appendix A, External Datasets Used in Examples, provides a summary of the datasets used in the examples.

Appendix B, Cited References, lists the cited resources.

What you need for this book

To follow through the examples in this book, all you need to do is install R (which is available for free) and download the example datasets from the book's website. Some of the examples also require you to have an Internet connection to download additional datasets and R packages from the R environment.

Who this book is for

This book is intended for anyone who wants to learn how to efficiently analyze geospatial data with R. This book primarily targets GIS analysts, researchers, educators, and students who are working with spatial data and are interested in expanding their capabilities through programming. The book assumes familiarity with basic geographic information concepts (such as spatial coordinates) and no prior experience with R and/or programming.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, folder names, filenames, file extensions, and pathnames are shown as follows: "Here, we created a data.frame object named df by combining the vectors num, lower, and upper."

A block of code is set as follows:

> num = 1:4
> lower = c("a","b","c","d")
> upper = c("A","B","C","D")
> df = data.frame(num, lower, upper)
> df
  num lower upper
1   1     a     A
2   2     b     B
3   3     c     C
4   4     d     D

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Under the Getting Started section, select the download R link."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code and data

You can download the example code and data files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/4367OS_ColoredImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.