9.7 Exercises

  • Create two overlapping polygons (poly_1 and poly_2) with the help of the sf-package (see Chapter 2).

  • Union poly_1 and poly_2 using st_union() and qgis:union.What is the difference between the two union operations?How can we use the sf package to obtain the same result as QGIS?

  • Calculate the intersection of poly_1 and poly_2 using:

    • RQGIS, RSAGA and rgrass7
    • sf
  • Attach data(dem, package = "RQGIS") and data(random_points, package = "RQGIS").Select randomly a point from random_points and find all dem pixels that can be seen from this point (hint: viewshed).Visualize your result.For example, plot a hillshade, and on top of it the digital elevation model, your viewshed output and the point.Additionally, give mapview a try.

  • Compute catchment area and catchment slope of data("dem", package = "RQGIS") using RSAGA (see Section 9.3).

  • Use gdalinfo via a system call for a raster file stored on disk of your choice (see Section 9.6.1).

  • Query all Californian highways from the PostgreSQL/PostGIS database living in the QGIS Cloud introduced in this chapter (see Section 9.6.2).

References

Sherman, Gary. 2008. Desktop GIS: Mapping the Planet with Open Source Tools. Pragmatic Bookshelf.

Chambers, John M. 2016. Extending R. CRC Press.

Graser, Anita, and Victor Olaya. 2015. “Processing: A Python Framework for the Seamless Integration of Geoprocessing Tools in QGIS.”

Muenchow, Jannes, Patrick Schratz, and Alexander Brenning. 2017. “RQGIS: Integrating R with QGIS for Statistical Geocomputing.” The R Journal 9 (2): 409–28.

Conrad, O., B. Bechtel, M. Bock, H. Dietrich, E. Fischer, L. Gerlitz, J. Wehberg, V. Wichmann, and J. Böhner. 2015. “System for Automated Geoscientific Analyses (SAGA) V. 2.1.4.” Geosci. Model Dev. 8 (7): 1991–2007. https://doi.org/10.5194/gmd-8-1991-2015.

Muenchow, Jannes, Alexander Brenning, and Michael Richter. 2012. “Geomorphic Process Rates of Landslides Along a Humidity Gradient in the Tropical Andes.” Geomorphology 139-140 (February): 271–84. https://doi.org/10.1016/j.geomorph.2011.10.029.

Neteler, Markus, and Helena Mitasova. 2008. Open Source GIS: A GRASS GIS Approach. Third. New York, NY: Springer.

Bivand, Roger, Edzer J Pebesma, and Virgilio Gómez-Rubio. 2013. Applied Spatial Data Analysis with R. Vol. 747248717. Springer.

Longley, Paul. 2015. Geographic Information Science & Systems. Fourth edition. Hoboken, NJ: Wiley.

Krug, Rainer M., Núria Roura-Pascual, and David M. Richardson. 2010. “Clearing of Invasive Alien Plants Under Different Budget Scenarios: Using a Simulation Model to Test Efficiency.” Biological Invasions 12 (12): 4099–4112.

Obe, Regina O., and Leo S. Hsu. 2015. PostGIS in Action. Second. Shelter Island, NY: Manning.

Bucklin, David, and Mathieu Basille. 2018. “Rpostgis: Linking R with a PostGIS Spatial Database.” The R Journal.

Huang, Zhou, Yiran Chen, Lin Wan, and Xia Peng. 2017. “GeoSpark SQL: An Effective Framework Enabling Spatial Queries on Spark.” ISPRS International Journal of Geo-Information 6 (9): 285. https://doi.org/10.3390/ijgi6090285.


  • Packages that have already been used including spData, spDataLarge and dplyr also need to be installed.

  • Other ‘command-lines’ include terminals for interacting with the operating system and other interpreted languages such as Python.Many GISs originated as a CLI:it was only after the widespread uptake of computer mice and high-resolution screens in the 1990s that GUIs became common.GRASS, one of the longest-standing GIS programs, for example, relied primarily on command-line interaction before it gained a sophisticated GUI (Landa 2008).

  • GRASS GIS and PostGIS are popular in academia and industry and can be seen as products which buck this trend as they are built around the command-line.

  • The mapedit package allows the quick editing of a few spatial features but not professional, large-scale cartographic digitizing.

  • An early use of the term ‘bridge’ referred to the coupling of R with GRASS (Neteler and Mitasova 2008).Roger Bivand elaborated on this in his talk, “Bridges between GIS and R”, delivered at the 2016 GEOSTAT summer school (see slides at: http://spatial.nhh.no/misc/).

  • Note also that the RSAGA package uses the command line interface to use SAGA geoalgorithms from within R (see Section 9.3).

  • SQLite/SpatiaLite are certainly also important but implicitly we have already introduced this approach since GRASS is using SQLite in the background (see Section 9.4).

  • Thanks to Manning Publications, Regina Obe and Leo Hsu for permission to use this example.

  • QGIS Cloud lets you store geographic data and maps in the cloud.In the background, it uses QGIS Server and PostgreSQL/PostGIS.This way, the reader can follow the PostGIS example without the need to have PostgreSQL/PostGIS installed on a local machine.Thanks to the QGIS Cloud team for hosting this example.

  • The prefix st stands for space/time.

  • It is important to close the connection here because QGIS Cloud (free version) allows only ten concurrent connections.