5.5 Exercises

Some of the exercises use a vector (random_points) and raster dataset (ndvi) from the RQGIS package.They also use a polygonal ‘convex hull’ derived from the vector dataset (ch) to represent the area of interest:

  1. library(RQGIS)
  2. data(random_points)
  3. data(ndvi)
  4. ch = st_combine(random_points) %>%
  5. st_convex_hull()
  • Generate and plot simplified versions of the nz dataset.Experiment with different values of keep (ranging from 0.5 to 0.00005) for ms_simplify() and dTolerance (from 100 to 100,000) st_simplify() .
    • At what value does the form of the result start to break down for each method, making New Zealand unrecognizable?
    • Advanced: What is different about the geometry type of the results from st_simplify() compared with the geometry type of ms_simplify()? What problems does this create and how can this be resolved?
  • In the first exercise in Chapter 4 it was established that Canterbury region had 70 of the 101 highest points in New Zealand.Using st_buffer(), how many points in nz_height are within 100 km of Canterbury?

  • Find the geographic centroid of New Zealand.How far is it from the geographic centroid of Canterbury?

  • Most world maps have a north-up orientation.A world map with a south-up orientation could be created by a reflection (one of the affine transformations not mentioned in Section 5.2.4) of the world object’s geometry.Write code to do so.Hint: you need to use a two-element vector for this transformation.

    • Bonus: create an upside-down map of your country.
  • Subset the point in p that is contained within x and y (see Section 5.2.5 and Figure 5.8).
    • Using base subsetting operators.
    • Using an intermediary object created with st_intersection().
  • Calculate the length of the boundary lines of US states in meters.Which state has the longest border and which has the shortest?Hint: The st_length function computes the length of a LINESTRING or MULTILINESTRING geometry.

  • Crop the ndvi raster using (1) the random_points dataset and (2) the ch dataset.Are there any differences in the output maps?Next, mask ndvi using these two datasets.Can you see any difference now?How can you explain that?

  • Firstly, extract values from ndvi at the points represented in random_points.Next, extract average values of ndvi using a 90 buffer around each point from random_points and compare these two sets of values.When would extracting values by buffers be more suitable than by points alone?

  • Subset points higher than 3100 meters in New Zealand (the nz_height object) and create a template raster with a resolution of 3 km.Using these objects:

    • Count numbers of the highest points in each grid cell.
    • Find the maximum elevation in each grid cell.
  • Aggregate the raster counting high points in New Zealand (created in the previous exercise), reduce its geographic resolution by half (so cells are 6 by 6 km) and plot the result.
    • Resample the lower resolution raster back to a resolution of 3 km. How have the results changed?
    • Name two advantages and disadvantages of reducing raster resolution.
  • Polygonize the grain dataset and filter all squares representing clay.
    • Name two advantages and disadvantages of vector data over raster data.
    • At which points would it be useful to convert rasters to vectors in your work?

References

Douglas, David H, and Thomas K Peucker. 1973. “Algorithms for the Reduction of the Number of Points Required to Represent a Digitized Line or Its Caricature.” Cartographica: The International Journal for Geographic Information and Geovisualization 10 (2): 112–22.

Visvalingam, M., and J. D. Whyatt. 1993. “Line Generalisation by Repeated Elimination of Points.” The Cartographic Journal 30 (1): 46–51. https://doi.org/10.1179/000870493786962263.

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

Liu, Jian-Guo, and Philippa J. Mason. 2009. Essential Image Processing and GIS for Remote Sensing. Chichester, West Sussex, UK, Hoboken, NJ: Wiley-Blackwell.

Hunziker, Philipp. 2017. Velox: Fast Raster Manipulation and Extraction.

Wickham, Hadley. 2014a. Advanced R. CRC Press.


  • Simplification of multipolygon objects can remove small internal polygons, even if the keep_shapes argument is set to TRUE. To prevent this, you need to set explode = TRUE. This option converts all mutlipolygons into separate polygons before its simplification.

  • A description of how st_point_on_surface() works is provided at https://gis.stackexchange.com/q/76498.

  • If the origins of two raster datasets are just marginally apart, it sometimes is sufficient to simply increase the tolerance argument of raster::rasterOptions().

  • Here we refer to spatial resolution.In remote sensing the spectral (spectral bands), temporal (observations through time of the same area) and radiometric (color depth) resolution are also important.Check out the stackApply() example in the documentation for getting an idea on how to do temporal raster aggregation.

  • See more at http://gdal.org/gdal_rasterize.html.