1. Learn
  2. /
  3. Courses
  4. /
  5. Visualizing Geospatial Data in R

Exercise

What's inside a spatial object?

What did you learn about the methods in the previous exercise? print() gives a printed form of the object, but it is often too long and not very helpful. summary() provides a much more concise description of the object, including its class (in this case SpatialPolygons), the extent of the spatial data, and the coordinate reference system information (you'll learn more about this in Chapter 4). plot() displays the contents, in this case drawing a map of the world.

But, how is that information stored in the SpatialPolygons object? In this exercise you'll explore the structure of this object. You already know about using str() to look at R objects, but what you might not know is that it takes an optional argument max.level that restricts how far down the hierarchy of the object str() prints. This can be useful to limit how much information you have to handle.

Let's see if you can get a handle on how this object is structured.

Instructions

100 XP
  • Call str() on countries_sp. This won't be very helpful, except to convince you this is a complicated stucture!
  • Call str() on countries_sp, setting max.level to 2. What is at the highest level of this object? Can you see where things might be stored?