Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Learning R for Geospatial Analysis
Learning R for Geospatial Analysis

Learning R for Geospatial Analysis: Leverage the power of R to elegantly manage crucial geospatial analysis tasks

eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Learning R for Geospatial Analysis

Chapter 1. The R Environment

In this chapter, we are going to introduce the R environment, learn how to install and use it, and introduce some of the main concepts related to writing R code. First, the technical issues of setting up the work environment are covered. After that, we will have R running and ready to receive instructions from the user. The basic concepts related to working in the R environment are also introduced.

In this chapter, we'll cover the following topics:

  • Installing R
  • Using R's command line
  • Editing code using text editors
  • Executing simple commands
  • Arithmetic operations
  • Logical operations
  • Calling functions
  • Understanding errors and warning messages
  • Checking which class a given object belongs to

Installing R and using the command line

In this section, we'll cover the installation of R before getting started with the R command line.

Downloading R

The R software can be downloaded from the R Project website at http://www.r-project.org/. The following screenshot shows the main page of this website:

Downloading R

Perform the following steps to download R from the R Project website:

  1. Under the Getting Started section, select the download R link.
  2. Select one of the download sources (it does not matter which one).
  3. Choose the appropriate version for your operating system, such as Linux, Mac OS, or Windows.
  4. If you are using Windows, which is the option we will cover from now on, select install R for the first time.
  5. Finally, click on the download link. This may vary according to the name of the current R version, such as Download R 3.1.0 for Windows.

Installing R

After downloading the file, follow the installation instructions. Note that if you are using a 64-bit version of Windows, you will be asked to select whether to install a 32-bit version, 64-bit version, or both. It is recommended that you use the 64-bit version in this case since it allows a single process to take advantage of more than 4 GB of RAM (this is helpful, for example, when loading a large raster file into memory).

Using R as a calculator

Start R by navigating to Start | All Programs | R and choose the appropriate shortcut from there (such as R x64 3.1.0 when running the 3.1.0 64-bit version of R).

The main screen of the R Graphical User Interface (RGui) looks like the following screenshot:

Using R as a calculator

The window you see when starting the program, R Console, is the command line. The > symbol followed by a flashing cursor indicates that the system is waiting for instructions from the user. When the user types an expression into the command line and presses Enter, that expression is interpreted from the R language into the language that the computer processor understands, and the respective operation that expression entails is performed. As you may have noted, very few point-and-click menu options are found within the R environment as almost all operations are only accessible through code.

First, we will try simple calculations. For example, type the expression 5+5. The result 10 will appear on the next line followed by the > symbol, indicating that all instructions have been executed and the system is waiting for new ones:

> 5+5
[1] 10

What has just happened is that the expression 5+5 was interpreted and the respective instruction (add 5 and 5) was sent to the processor. The processor found the result (which is 10), which was then returned and printed in the command-line window. As we will see later, the result was saved neither in the RAM nor in the long-term computer memory, such as the hard disk. The meaning of the [1] part is that the result is a vector, with the first member being the number 10. Vectors will be covered in the next chapter.

Note that an R expression can be several lines long. For example, if we type 5* and press Enter, the symbol + appears on the next line, indicating that R is waiting for the remaining part of the expression (5 multiplied by ...):

> 5*
+ 2
[1] 10

If you change your mind and do not wish to complete the expression, you can press Esc to cancel the + mode and return to the command line. Pressing Esc can also be used to terminate the current process that is being executed. (We didn't get a chance to try that out yet since simple operations such as 5+5 are executed very quickly.)

Note

While using the command line, you can scroll through the history of previously executed expressions with the Using R as a calculator and Using R as a calculator keys. For example, this can be useful to modify a previously executed expression and run it once more.

You can clear all text from the command-line window by pressing Ctrl + L.

Throughout this book, code sections display both the expressions that the user enters (following the > symbol) and the resulting output. Reading both the inputs and the outputs will make it easier to follow the code examples. If you wish to execute the code examples in R and to investigate what happens when modifying them (which is highly recommended), only the input expressions should be entered into the R interpreter (these are the expressions followed by the >, or + if the expression spans several lines, symbols). Therefore, copying and pasting the entire content of code sections directly from the book into the interpreter will result in errors, since R will try to execute the output lines. The input, in fact, will not be correctly interpreted either since input expressions include > and + symbols that are not part of the code. To make things easier, all code sections from this book are provided on the book's website as plain R code files.

Coding with R beyond the command line

Working in R exclusively through the command line is rarely appropriate in practice, except when running short and simple commands (such as those introduced in this chapter) or when experimenting with new functions. For more complicated operations, we will save our code to a file in order to have the capability, for example, to work on it on several instances or to share it with other users. This section introduces approaches to editing and saving R code.

Approaches to editing R code

Typing the expression 5+5 into the command line was easy enough. However, if we perform more complicated operations, we'll have to edit and save our code for later use. There are three main approaches to edit R code:

  • Using R's built-in editor
  • Using a text editor
  • Using an Integrated Development Environment (IDE)

Using R's built-in editor is the simplest way to edit R code. In this case, you don't need to use any software other than R. To open the code editor, simply navigate to File | New script from R's menu. A blank text window will open. You can type code in this window and execute it by clicking on Ctrl + R, either after selecting the code section that you want to execute (the selected section will be sent to the interpreter) or by placing the cursor on the line that you want to execute (that line will be sent to the interpreter).

The following screenshot shows the way RGui appears with both a command-line window and a code editor window:

Approaches to editing R code

You can save the R code that you have written to a file at any time (File | Save as...) in order to be able to work on it another day. An R code file is a plain text file, usually with the suffix .R. To open an existing R code file, simply select it after navigating to the File | Open script... menu.

It is sometimes easier to use other text editors since they provide more options than R's basic text editor. For example, one can edit R code in the all-purpose Notepad++ text editor, which is available for free at http://notepad-plus-plus.org/. Notepad++ can be customized to edit code written in different programming languages (including R). By selecting the appropriate language, the specific function names and operators of that language will be highlighted in different colors for easier interpretation by the user.

The following screenshot shows Notepad++ with the menus used to select the R programming language:

Approaches to editing R code

A code section can be transferred to the R interpreter simply by copying it from the text editor and then pasting into the R command line. To automatically pass code into the R interpreter (such as by clicking Ctrl + R), it might be necessary to install an add-on component such as the NppToR software for Notepad++ (which is freely available at http://sourceforge.net/projects/npptor/), or use a text editor such as Tinn-R (which is freely available at http://sourceforge.net/projects/tinn-r/) that has this capability built in.

The most sophisticated way of editing R code is to use an IDE, where an advanced text editor and the R interpreter portions are combined within a single window (much like in RGui itself), in addition to many other advanced functions that may be of help in programming and are not found in RGui. These can include automatic code completion, listings of libraries and functions, automatic syntax highlighting (to read code and output more easily), debugging tools, and much more.

Note

Note that word processors such as Microsoft Word or OpenOffice Writer are not appropriate to edit computer code. The reason is that they include many styles and symbols that will not be recognized by R (or by any programming language for that matter), and this may cause problems. For example, the quote symbol Approaches to editing R code (into which the word processor may automatically convert to the symbol ") will not be recognized by R, resulting in an error.

Installation of RStudio

RStudio is an IDE designed specifically for R, and it is the recommended way of editing R code. You will quickly discover that even without using any of the advanced options, code editing in RStudio is more convenient than the previously mentioned alternatives. RStudio can be freely downloaded from www.rstudio.com.

Using RStudio

When you open RStudio, you will see the R command-line window and several additional utility panes that can display the code editor, help files, graphic output, and so on, during the course of working in R. To open a new R code file, navigate to File | New File | R Script. A code editing window, such as the one shown in the following screenshot, will appear:

Using RStudio

In RStudio, code can be sent from the editor window into the command-line window in the same way as in RGui, that is, by pressing Ctrl + R either on a code section or on a single line of code. You can quickly switch to the code editor or to the command-line pane by clicking on it with the mouse or by pressing Ctrl + 1 or Ctrl + 2, respectively. You can also have several R code files open in different tabs within the code editor pane.

More details can be found on the RStudio website (www.rstudio.com) or in other resources such as Mark P.J. van der Loo and Edwin de Jonge's book Learning RStudio for R Statistical Computing, Packt Publishing (2012).

Note

All references mentioned in this book are collectively provided in Appendix B, Cited References.

Evaluating expressions

We now know how to enter code for R to interpret, whether directly entering it into R's command line or sending it to the command line from a code editor. Our next step will be to see how to use the simplest operations: arithmetic and logical operators and functions.

Using arithmetic and logical operators

The standard arithmetic operators in R are as follows:

  • +: Addition
  • -: Subtraction
  • *: Multiplication
  • /: Division
  • ^: Power

The following examples demonstrate the usage of these operators:

> 5+3
[1] 8
> 4-5
[1] -1
> 1*10
[1] 10
> 1/10
[1] 0.1
> 2^3
[1] 8

Parentheses can be used to construct more elaborate expressions, as follows:

> 2*(3+1)
[1] 8
> 5^(1+1)
[1] 25

It is better to use parentheses even when it is not required to make the code clearer.

Another very useful symbol is #. All code to the right of this symbol is not interpreted. Let's take a look at the following example:

> 1*2 # *3
[1] 2

The # symbol is helpful for adding comments within the code to explain what each code segment does, for other people (or oneself, at a later time of reference) to understand it:

> 5+5 # Adding 5 and 5
[1] 10

Note that R ignores spaces between the components of an expression:

> 1+  1
[1] 2

Conditions are expressions that have a yes/no answer (the statement can be either true or false). When interpreting a conditional expression, R returns a logical value, either TRUE for a true expression or FALSE for a false expression. A third option, NA, which stands for Not Available, is used when there is not enough information to determine whether the expression is true or false (NA values will be discussed in the next chapter).

The logical operators in R are summarized as follows:

  • ==: Equal to
  • >: Greater than
  • >=: Greater than or equal to
  • <: Smaller than
  • <=: Smaller than or equal to
  • !=: Not equal to
  • &: and
  • |: or
  • !: not

For example, we can use condition operators to compare between two numbers as follows:

> 1<2
[1] TRUE
> 1>2
[1] FALSE
> 2>2
[1] FALSE
> 2>=2
[1] TRUE
> 2!=2
[1] FALSE

The and (&) and or (|) operators can be used to construct more complex expressions as follows:

> (1<10) & (10<100)
[1] TRUE
> (1<10) & (10>100)
[1] FALSE
> (1<10) | (10<100)
[1] TRUE
> (1<10) | (10>100)
[1] TRUE

As you can see in the preceding examples, when the expressions at both the sides of the & operator are true, TRUE is returned; otherwise, FALSE is returned (refer to the first two expressions). When at least one of the expressions at either side of the | operator is true, TRUE is returned; otherwise, FALSE is returned (refer to the last two expressions).

Two other useful conditional operators (== and !=) are used for testing equality and inequality, respectively. These operators are opposites from one another since a pair of objects can be either equal or non-equal to each other.

> 1 == 1
[1] TRUE
> 1 == 2
[1] FALSE
> 1 != 1
[1] FALSE
> 1 != 2
[1] TRUE

As you can see in the preceding examples, when using the == operator, TRUE is returned if the compared objects are equal; otherwise FALSE is returned (refer to expressions 1 and 2). With != it is the other way around (refer to expressions 3 and 4).

The last operator that we are going to cover is the not operator (!). This operator reverses the resulting logical value, from TRUE to FALSE or from FALSE to TRUE. This is used in cases when it is more convenient to ask whether a condition is not satisfied. Let's take a look at the following example:

> 1 == 1
[1] TRUE
> !(1 == 1)
[1] FALSE
> (1 == 1) & (2 == 2)
[1] TRUE
> (1 == 1) & !(2 == 2)
[1] FALSE

Using functions

In mathematics, a function is a relation between a set of inputs and a set of outputs with the property that each input is related to exactly one output. For example, the function y=2*x relates every input x with the output y, which is equal to x multiplied by 2. The function concept in R (and in programming in general) is very similar:

  • The function is composed of a code section that knows how to perform a certain operation.
  • Employing the function is done by calling the function.
  • The function receives one object, or several objects, as input (for example, the number 9).
  • The function returns a single object as output (for example, the number 18). Optionally, it can perform other operations called side effects in addition to returning the output.
  • The type and quantity of the objects that a function receives as input has to be defined in advance. These are called the function's parameters (for example, a single number).
  • The objects that a function receives in reality, at a given function call, are called the function's arguments (for example, the number 9).

The most common (and the most useful) expressions in R are function calls. In fact, we have been using function calls all along, since the arithmetic operators are functions as well, which becomes apparent when using a different notation:

> 3*3
[1] 9
> "*"(3,3)
[1] 9

A function is essentially a predefined set of instructions. There are plenty of built-in functions in R (functions that are automatically loaded into memory when starting R). Later, you will also learn how to use functions that are not automatically loaded, and how to define your own functions.

As you might have guessed from the previous example, a function call is composed of the function name, followed by the function's arguments within parentheses and separated by commas. For example, the function sqrt returns the square root of its argument:

> sqrt(16)
[1] 4

Note

R is case sensitive. For example, Sqrt and sqrt are treated as two different names:

> Sqrt(16)
Error: could not find function "Sqrt"

When trying the first option, we receive an error message stating that there is no function named Sqrt in memory.

Dealing with warning and error messages

Error messages are printed when for some reason it is impossible to execute the expression that we have sent to the interpreter. For example, this can happen when one of the objects we refer to does not exist (refer to the preceding information box). Another example is trying to pass an inappropriate argument to a function. In R, character values are delimited by quotes. Trying to call a mathematical function on a character understandably produces an error:

> "oranges" + "apples"
Error in "oranges" + "apples" : non-numeric argument to binary op$

Note

The $ symbol at the end of the text message indicates that we need to scroll rightwards in the command-line window to see the whole message.

Warning messages are returned when an expression can be interpreted but the system suspects that the respective employed method is inappropriate. For example, the square root of a negative number does not yield a number within the real number system. A Not a Number (NaN) value is returned in such a case, along with a warning:

> sqrt(-2)
[1] NaN
Warning message:
In sqrt(-2) : NaNs produced

R has a set of predefined symbols to represent special constant values, most of which we already mentioned:

  • NaN: Not a number
  • NA: Not available
  • NULL: An empty object
  • TRUE and FALSE: Logical values
  • Inf: Infinity (for example, try typing 1/0)

Note

Unnecessary warnings and information messages, such as an indication that a given operation has been successfully carried out, are omitted from the code sections in this book to save space. However, readers who reproduce the examples will occasionally see such messages on the screen.

Getting help

A help page on every function in R can be reached by using the ? operator (or the help function). For example, the following expression opens the help page for the sqrt function:

> ?sqrt

The same result is achieved by typing help(sqrt).

Note

On the other hand, the ?? operator searches the available help pages for a given keyword (corresponding to the help.search function).

Another useful expression regarding the official R help pages is help.start() that opens a page with links to R's official introductory manuals.

The structure of all help files on functions is similar, usually including a short description of what the function does, the list of its arguments, usage details, a description of the returned object, references, and examples. The help pages can seem intimidating at first, but with time they become clearer and more helpful for reminding oneself of the functions' usage details.

Another important source of information on R is the Internet. Entering a question or a task that we would like to perform (such as Googling r read raster file) into a web search engine usually yields a surprising amount of information from forums, blogs, and articles. Using these resources is inevitable when investigating new ways to utilize R.

Exploring the basic object types in R

So far, we have encountered two types of objects in R: numeric values (numeric vectors, to be precise, as we will see in Chapter 2, Working with Vectors and Time Series) and functions. In this section, we are going to introduce the key concept that an object is an instance of a certain class. Then, we will distinguish between, for operational purposes, the classes that are used to store data (data structures) and classes that are used to perform operations (functions). Finally, a short sample code that performs a simple GIS operation in R will be presented to demonstrate the way themes introduced in this chapter (and those that will be introduced in Chapter 2, Working with Vectors and Time Series, and Chapter 3, Working with Tables) will be applied for spatial data analysis in the later chapters of this book.

Everything is an object

R is an object-oriented language; accordingly, everything in R is an object. Objects belong to classes, with each class characterized by certain properties. The class to which an object belongs to determines the object's properties and the actions we can do with that object. To use an analogy, a gray Mitsubishi Super-Lancer model 1996 object belongs to the class car. It has specific attributes (such as color, model, and manufacturer) for each of the data fields a car object has. It satisfies all criteria that the car class entails; thus, the actions that are applicable to cars (such as igniting the engine and accelerating or using the breaks) are also meaningful with that particular object. In much the same way, a multi-band raster object in R will obligatorily have certain properties (such as the number of rows and columns, and resolution) and applicable actions (such as creating a subset of only the first band or calculating an overlay based on all bands).

All objects that are stored in memory can be accessed using their names, which begin with a character (without quotes; some functions, such as all arithmetic and logical operators can be called using their respective symbol within quotes, such as in "*" as we saw earlier). For example, sqrt is the name of the square root function object; the class to which this object belongs is function. When starting R, a predefined set of objects is loaded into memory, for example, the sqrt function and logical constant values TRUE and FALSE. Another example of a preloaded object is the number Everything is an object:

> pi
[1] 3.141593

The class function returns the class name of the object that it receives as an argument:

> class(TRUE)
[1] "logical"
> class(1)
[1] "numeric"
> class(pi)
[1] "numeric"
> class("a")
[1] "character"
> class(sqrt)
[1] "function"

Storing data in data structures

From the point of view of a typical R user, all objects we handle in R can be divided into two groups: data structures (which hold data) and functions (which are used to perform operations on the data).

The basic components of all data structures are constant values, usually numeric, character, or logical (the last code section shows examples of all three). The simplest data structure in R is a vector, which is covered in Chapter 2, Working with Vectors and Time Series. Later, we'll see how more complex data structures are essentially collections of the simpler data structures. For example, a raster object in R may include two numeric vectors (holding the raster values and its dimensions) and a character vector (holding the Coordinate Reference System (CRS) information). The object-oriented nature of the language makes things easier both for the people who define the data structure classes (since they can build upon predefined simpler classes, rather than starting from the beginning) and for the users (since they can utilize their previous knowledge of the simpler data structure components to quickly understand more complex ones).

Calling functions to perform operations

Objects of the second type—functions—are typically used to perform operations on data structures. A function may have its influence limited to the R environment, or it may invoke side effects affecting the environment outside of R. All functions we have used until now affect only the R environment; a function to save a raster file, for example, has an external effect—it influences the data content of the hard drive.

A short sample session

Finally, let's take a look at a complete code section that performs a simple spatial analysis operation:

> library(raster)
> r = raster("C:\\Data\\rainfall.tif")
> r[120, 120] = 1000
> writeRaster(r, "C:\\Data\\rainfall2.tif")

The task that this code performs is to read a raster file, rainfall.tif, from the disk (look at the following screenshot to see its visualization in QGIS), change one of its values (the one at row 120 line 120, into 1000) and write the resulting raster to a different file.

A short sample session

Note

The rainfall.tif file, as well as all other external data files used in this book, is provided on the book's website so that the reader can reproduce the examples and experiment with them. Refer to Appendix A, External Datasets Used in Examples, for a summary of all data files encountered throughout the book. R code files, containing all code sections that appear in the book, are also provided on the book's website for convenience.

Do not worry if you do not understand all the lines of code given in the beginning of this section. They will become clear by the time you finish reading Chapter 4, Working with Rasters. Briefly, the first line of code tells R to load the set of functions that are used to work with rasters (called the raster package), such as the raster and writeRaster functions that we use here to read and write raster files. In the second line, we read the requested file and load it into memory. In the third line of code, we assign the value 1000 to the specified pixel of that raster. The fourth line of code writes the new (modified) raster to the disk.

The task indeed sounds simple, but when we use desktop GIS software, it may not be easy to perform through the menus and dialog box system (where direct access to raster values may be unavailable). For example, we may have to create a new point feature over the pixel that we want to change (120,120) in raster A, convert it to a raster B (with the value of 1 at the (120,120) pixel and 0 in all other pixels), and then use an overlay tool to say that we want the pixel in raster A that overlays the value of 1 in raster B to have the value of 1000, while all other pixels retain their original values. Finally, we might need to use an additional toolbox to export the new raster. However, what if we need to perform this operation on several files or repeatedly on a given file as new information comes in?

Generally speaking, when we use programming rather than menu-based interfaces, the steps we have to take may seem less intuitive (writing code rather than scrolling, clicking with the mouse, and filling out dialog boxes). However, we have much more power with giving the computer specific instructions. The beauty of using programming for data analysis, and using R for geospatial analysis in particular, is not only that we gain greater efficiency through automation, but also that we get closer to the data and discover a wide range of new possibilities to analyze it, some of which may not even come to mind when we use a predefined set of tools or menus.

Summary

In this chapter, we covered the basics of using R. At this point, you should have R installed and you should be able to write and execute several basic commands from the command line or from the text editor of your preference. The concepts of classes and objects were also introduced, which are both important for the rest of the topics that you will learn in this book. We are now ready to proceed to more complex data structures and operations used in spatial data analysis.

The next chapter will be devoted to vectors, the basic data structures in R. Then, we will introduce more complex data structures to represent nonspatial data in Chapter 3, Working with Tables, and spatial data in Chapter 4, Working with Rasters, and Chapter 5, Working with Points, Lines, and Polygons.

Left arrow icon Right arrow icon

Description

This book is intended for anyone who wants to learn how to efficiently analyze geospatial data with R, including GIS analysts, researchers, educators, and students who work with spatial data and who are interested in expanding their capabilities through programming. The book assumes familiarity with the basic geographic information concepts (such as spatial coordinates), but no prior experience with R and/or programming is required. By focusing on R exclusively, you will not need to depend on any external software—a working installation of R is all that is necessary to begin.

What you will learn

  • Make inferences from tables by joining, reshaping, and aggregating
  • Familiarize yourself with the R geospatial data analysis ecosystem
  • Prepare reproducible, publicationquality 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
Estimated delivery fee Deliver to Spain

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 26, 2014
Length: 364 pages
Edition : 1st
Language : English
ISBN-13 : 9781783984367
Category :
Languages :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Spain

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

Product Details

Publication date : Dec 26, 2014
Length: 364 pages
Edition : 1st
Language : English
ISBN-13 : 9781783984367
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 120.97
R for Data Science
€41.99
Learning R for Geospatial Analysis
€41.99
R Object-oriented Programming
€36.99
Total 120.97 Stars icon
Banner background image

Table of Contents

12 Chapters
1. The R Environment Chevron down icon Chevron up icon
2. Working with Vectors and Time Series Chevron down icon Chevron up icon
3. Working with Tables Chevron down icon Chevron up icon
4. Working with Rasters Chevron down icon Chevron up icon
5. Working with Points, Lines, and Polygons Chevron down icon Chevron up icon
6. Modifying Rasters and Analyzing Raster Time Series Chevron down icon Chevron up icon
7. Combining Vector and Raster Datasets Chevron down icon Chevron up icon
8. Spatial Interpolation of Point Data Chevron down icon Chevron up icon
9. Advanced Visualization of Spatial Data Chevron down icon Chevron up icon
A. External Datasets Used in Examples Chevron down icon Chevron up icon
B. Cited References Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9
(7 Ratings)
5 star 42.9%
4 star 28.6%
3 star 14.3%
2 star 0%
1 star 14.3%
Filter icon Filter
Top Reviews

Filter reviews by




R N Thornton Jan 02, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is clearly written and comprehensive, containing many tips about use of R in addition to its core spatial content. Code is available through the internet - essential really. I can hardly recommend this book too much for developing skills in spatial analysis.
Amazon Verified review Amazon
DARKO KRALIK Aug 10, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is an extraordinary introduction to geospatial analysis.At first You could get feeling that this book is so good mostly because of inate expressiveness of R.But real truth is that it's excellent selection of examples and it's methodical approach reveals R, it's geo libraries, and geospatial analysis as such in clear and simple way.And I am saying that after browsing thru dozens and dozens other geospatial books and environments.
Amazon Verified review Amazon
Alvaro Neto Oct 28, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very straightforward. Although I had a rudimentary understanding of R beforehand, I believe anyone with interest in the topic can pick this up.
Amazon Verified review Amazon
Kim G Mar 31, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This book will likely be a great resource for new users to R who hope to perform geospatial analyses. The first three chapters of the book provide a very basic level introduction to the R language and environment that will be useful to new readers, but may be found extraneous and unnecessary for those familiar with using R and only seeking further information on geospatial analysis. There are small instances of when the code supplied in the text is specific to a Windows PC environment, so new users on a different operating system will be left on their own to figure this step out; though it is not a difficult step. Advanced R users may also find the repeated instances throughout the chapters of how to load and look at your data to be tedious. Though I have not assessed this book in its entirety, I found the discussion on working with layers of data very useful to tasks I have tried implementing in the past. The book does a good job of describing many of the existing mapping tools that R is capable of, and should be useful to future researchers and data scientists.
Amazon Verified review Amazon
Christian S. Mar 19, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This is a great intro for geospatial analysis. The book is self contained and gives you a brief practical intro to R. The first three chapters give you the basics of the data structures and libraries you need to understand to follow the remaining chapters of the book.In chapter 4 is where the fun part starts. The intro to each chapter is clear and concise and the examples are nice to work with. The visualizations are great.The ebook has the images in full color, not sure about the printed version.Even though the author uses Windows file paths in their examples, it was easy to adjust them to work on a Mac using RStudio. The book provides a complete set of images and raster files as part of the source code.I wish the author had included examples of least-cost paths. It was just mentioned briefly.In summary I would recommend this book as a great intro to R and geospatial analysis and visualization.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela