You are previewing Learning R for Geospatial Analysis.
O'Reilly logo
Learning R for Geospatial Analysis

Book Description

Leverage the power of R to elegantly manage crucial geospatial analysis tasks

In Detail

R is a simple, effective, and comprehensive programming language and environment that is gaining ever-increasing popularity among data analysts.

This book provides you with the necessary skills to successfully carry out complete geospatial data analyses, from data import to presentation of results.

Learning R for Geospatial Analysis is composed of step-by-step tutorials, starting with the language basics before proceeding to cover the main GIS operations and data types. Visualization of spatial data is vital either during the various analysis steps and/or as the final product, and this book shows you how to get the most out of R's visualization capabilities. The book culminates with examples of cutting-edge applications utilizing R's strengths as a statistical and graphical tool.

What You Will Learn

  • Make inferences from tables by joining, reshaping, and aggregating
  • Familiarize yourself with the R geospatial data analysis ecosystem
  • Prepare reproducible, publication-quality plots and maps
  • Efficiently process numeric data, characters, and dates
  • Reshape tabular data into the necessary form for the specific task at hand
  • Write R scripts to automate the handling of raster and vector spatial layers
  • Process elevation rasters and time series visualizations of satellite images
  • Perform GIS operations such as overlays and spatial queries between layers
  • Spatially interpolate meteorological data to produce climate maps
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. Learning R for Geospatial Analysis
      1. Table of Contents
      2. Learning R for Geospatial Analysis
      3. Credits
      4. About the Author
      5. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code and data
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. The R Environment
        1. Installing R and using the command line
          1. Downloading R
          2. Installing R
          3. Using R as a calculator
        2. Coding with R beyond the command line
          1. Approaches to editing R code
          2. Installation of RStudio
          3. Using RStudio
        3. Evaluating expressions
          1. Using arithmetic and logical operators
          2. Using functions
          3. Dealing with warning and error messages
          4. Getting help
        4. Exploring the basic object types in R
          1. Everything is an object
          2. Storing data in data structures
          3. Calling functions to perform operations
          4. A short sample session
        5. Summary
      9. 2. Working with Vectors and Time Series
        1. Vectors – the basic data structures in R
          1. Different types of vectors
          2. Using the assignment operator to save an object
          3. Removing objects from memory
          4. Summarizing vector properties
          5. Element-by-element operations on vectors
          6. The recycling principle
        2. Using functions with several parameters
          1. Supplying more than one argument in a function call
          2. Creating default vectors
          3. Creating repetitive vectors
          4. Substrings
        3. Creating subsets of vectors
          1. Subsetting with numeric vectors of indices
          2. Subsetting with logical vectors
        4. Dealing with missing values
          1. Missing values and their effect on data
          2. Detecting missing values in vectors
          3. Performing calculations on vectors with missing values
        5. Writing new functions
          1. Defining our own functions
          2. Setting default values for the arguments
        6. Working with dates and time series
          1. Specialized time series classes in R
          2. Reading climatic data from a CSV file
          3. Converting character values to dates
          4. Examining our time series
          5. Creating subsets based on dates
        7. Introducing graphical functions
          1. Displaying vectors using base graphics
          2. Saving graphical output
          3. The main graphical systems in R
        8. Summary
      10. 3. Working with Tables
        1. Using the data.frame class to represent tabular data
          1. Creating a table from separate vectors
          2. Creating a table from a CSV file
          3. Examining the structure of a data.frame object
          4. Subsetting data.frame objects
          5. Calculating new data fields
          6. Writing a data.frame object to a CSV file
        2. Controlling code execution
          1. Conditioning execution with conditional statements
          2. Repeatedly executing code sections with loops
        3. Automated calculations using the apply family of functions
          1. Applying a function on separate parts of a vector
          2. Applying a function on rows or columns of a table
        4. Inference from tables by joining, reshaping, and aggregating
          1. Using contributed packages
          2. Shifting between long and wide formats using melt and dcast
          3. Aggregating with ddply
          4. Joining tables with join
        5. Summary
      11. 4. Working with Rasters
        1. Using the matrix and array classes
          1. Representing two-dimensional data with a matrix
          2. Representing more than two dimensions with an array
        2. Data structures for rasters in the raster package
          1. Creating single band rasters
          2. Creating multiband rasters
          3. Writing raster files
          4. Exploring a raster's properties
        3. Subsetting rasters
          1. Accessing raster values as a vector
          2. Accessing raster values with the matrix notation
          3. Subsets involving more than one layer
          4. Transforming a raster into a matrix or an array
        4. Overlay and reclassification of rasters
          1. Raster algebra and overlay operations
          2. Reclassifying raster values
        5. Summary
      12. 5. Working with Points, Lines, and Polygons
        1. Data structures for vector layers in R
          1. Points
          2. Lines
          3. Polygons
        2. Exploring vector layer properties and subsetting
          1. Examining vector layer properties
          2. Accessing the attribute table of vector layers
          3. Subsetting vector layers
        3. Geometrical calculations on vector layers
          1. Reprojecting vector layers
          2. Working with the geometrical properties of vector layers
        4. Spatial relations between vector layers
          1. Querying relations between vector layers
          2. Creating new geometries
          3. Calculating distances between geometries
        5. Joining geometries with tabular data
        6. Summary
      13. 6. Modifying Rasters and Analyzing Raster Time Series
        1. Changing the spatial extent or resolution of rasters
          1. Merging rasters
          2. Cropping and trimming
          3. Aggregating and disaggregating
        2. Raster resampling and reprojection
          1. Raster resampling
          2. Raster reprojection
        3. Filtering and clumping
        4. Topography-related calculations with elevation data
          1. Slope and aspect calculation
          2. Hillshade
        5. Aggregating spatio-temporal raster data
          1. The time dimension
          2. Spatial dimensions
        6. Summary
      14. 7. Combining Vector and Raster Datasets
        1. Creating rasters from vector layers
          1. Rasterizing vector layers
          2. Masking values in a raster
        2. Creating vector layers from a raster
          1. Raster-to-points conversion
          2. Raster-to-contours conversion
          3. Raster-to-polygons conversion
        3. Extracting raster values based on vector layers
          1. Extracting by points
          2. Extracting by polygons
        4. Summary
      15. 8. Spatial Interpolation of Point Data
        1. Spatially interpolating point data
          1. Nearest-neighbor interpolation
          2. IDW interpolation
          3. Interpolation using Ordinary Kriging
          4. Using covariates in Universal Kriging interpolation
        2. Mapping the annual temperature in Spain
        3. Summary
      16. 9. Advanced Visualization of Spatial Data
        1. Plotting with ggplot2 and ggmap
          1. An overview of ggplot2
          2. Plotting nonspatial data
          3. Saving the ggplot2 plots
          4. Plotting spatial data
          5. Adding static maps from the Web
        2. Making 3D plots with lattice
        3. Summary
      17. A. External Datasets Used in Examples
      18. B. Cited References
      19. Index