2.6 Exercises

  • Use summary() on the geometry column of the world data object. What does the output tell us about:
    • Its geometry type?
    • The number of countries?
    • Its coordinate reference system (CRS)?
  • Run the code that ‘generated’ the map of the world in Figure 2.5 at the end of Section 2.2.4.Find two similarities and two differences between the image on your computer and that in the book.
    • What does the cex argument do (see ?plot)?
    • Why was cex set to the sqrt(world$pop) / 10000?
    • Bonus: experiment with different ways to visualize the global population.
  • Use plot() to create maps of Nigeria in context (see Section 2.2.4).
    • Adjust the lwd, col and expandBB arguments of plot().
    • Challenge: read the documentation of text() and annotate the map.
  • Create an empty RasterLayer object called my_raster with 10 columns and 10 rows.Assign random values between 0 and 10 to the new raster and plot it.
  • Read-in the raster/nlcd2011.tif file from the spDataLarge package.What kind of information can you get about the properties of this file?
    Reminder: solutions can be found online at https://geocompr.github.io

References

Gillespie, Colin, and Robin Lovelace. 2016. Efficient R Programming: A Practical Guide to Smarter Programming. O’Reilly Media.

Grolemund, Garrett, and Hadley Wickham. 2016. R for Data Science. O’Reilly Media.

Pebesma, Edzer. 2018. “Simple Features for R: Standardized Support for Spatial Vector Data.” The R Journal.

Pebesma, Edzer, and Roger Bivand. 2018. Sp: Classes and Methods for Spatial Data. https://CRAN.R-project.org/package=sp.

Bivand, Roger, Tim Keitt, and Barry Rowlingson. 2018. Rgdal: Bindings for the ’Geospatial’ Data Abstraction Library. https://CRAN.R-project.org/package=rgdal.

Bivand, Roger, and Colin Rundel. 2018. Rgeos: Interface to Geometry Engine - Open Source (’Geos’). https://CRAN.R-project.org/package=rgeos.

Maling, D. H. 1992. Coordinate Systems and Map Projections. Second. Oxford ; New York: Pergamon Press.

Pebesma, Edzer, Thomas Mailund, and James Hiebert. 2016. “Measurement Units in R.” The R Journal 8 (2): 486–94.


  • spDataLarge is not on CRAN, meaning it must be installed via devtools or with the following command: install.packages("spDataLarge", repos = "https://nowosad.github.io/drat/", type = "source").

  • The origin we are referring to, depicted in blue in Figure 2.1, is in fact the ‘false’ origin.The ‘true’ origin, the location at which distortions are at a minimum, is located at 2° W and 49° N.This was selected by the Ordnance Survey to be roughly in the center of the British landmass longitudinally.

  • The full OGC standard includes rather exotic geometry types including ‘surface’ and ‘curve’ geometry types, which currently have limited application in real world applications.All 17 types can be represented with the sf package, although (as of summer 2018) plotting only works for the ‘core 7’.

  • plot()ing of sf objects uses sf:::plot.sf() behind the scenes.plot() is a generic method that behaves differently depending on the class of object being plotted.

  • Note: many plot arguments are ignored in facet maps, when more than one sf column is plotted.

  • By definition, a polygon has one exterior boundary (outer ring) and can have zero or more interior boundaries (inner rings), also known as holes.A polygon with a hole would be, for example, POLYGON ((1 5, 2 2, 4 1, 4 4, 1 5), (2 4, 3 4, 3 3, 2 3, 2 4))

  • Other attributes might include an urbanity category (city or village), or a remark if the measurement was made using an automatic station.

  • Depending on the file format the header is part of the actual image data file, e.g., GeoTIFF, or stored in an extra header or world file, e.g., ASCII grid formats. There is also the headerless (flat) binary raster format which should facilitate the import into various software programs.

  • The degree of compression is often referred to as flattening, defined in terms of the equatorial radius ((a)) and polar radius ((b)) as follows: (f = (a - b) / a). The terms ellipticity and compression can also be used (Maling 1992).Because (f) is a rather small value, digital ellipsoid models use the ‘inverse flattening’ ((rf = 1/f)) to define the Earth’s compression.Values of (a) and (rf) in various ellipsoidal models can be seen by executing st_proj_info(type = "ellps").

  • A complete list of the proj4string parameters can be found at https://proj4.org/.