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.
This exercise is part of the course
Visualizing Geospatial Data in R
Exercise instructions
- Call
str()
oncountries_sp
. This won't be very helpful, except to convince you this is a complicated stucture! - Call
str()
oncountries_sp
, settingmax.level
to 2. What is at the highest level of this object? Can you see where things might be stored?
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Call str() on countries_sp
# Call str() on countries_sp with max.level = 2