Skip to content

Commit d412b80

Browse files
committed
Merge branch 'main' of https://github.com/geocompx/geocompr
2 parents 523a5d5 + f72e44e commit d412b80

28 files changed

+231
-229
lines changed

01-introduction.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ There are many ways to handle geographic data in R, with dozens of packages\inde
249249
An overview of R's spatial ecosystem can be found in the CRAN\index{CRAN} Task View on the Analysis of Spatial Data
250250
(see https://cran.r-project.org/view=Spatial).
251251
]
252-
In this book we endeavor to teach the state-of-the-art in the field whilst ensuring that the methods are future-proof.
252+
In this book, we endeavor to teach the state-of-the-art in the field whilst ensuring that the methods are future-proof.
253253
Like many areas of software development, R's spatial ecosystem is rapidly evolving (Figure \@ref(fig:cranlogs)).
254254
Because R is open source, these developments can easily build on previous work, by 'standing on the shoulders of giants', as Isaac Newton put it in [1675](https://digitallibrary.hsp.org/index.php/Detail/objects/9792).
255255
This approach is advantageous because it encourages collaboration and avoids 'reinventing the wheel'.
@@ -312,7 +312,7 @@ R's spatial capabilities have evolved substantially since then, but they still b
312312
Interfaces to GDAL\index{GDAL} and PROJ\index{PROJ}, for example, still power R's high-performance geographic data I/O and CRS\index{CRS} transformation capabilities, as outlined in Chapters \@ref(reproj-geo-data) and \@ref(read-write), respectively.
313313

314314
**rgdal**, released in 2003, provided GDAL\index{GDAL} bindings for R which greatly enhanced its ability to import data from previously unavailable geographic data formats.
315-
The initial release supported only raster drivers, but subsequent enhancements provided support for coordinate reference systems (via the PROJ library), reprojections and import of vector file formats.
315+
The initial release supported only raster drivers, but subsequent enhancements provided support for CRSs (via the PROJ library), reprojections and import of vector file formats.
316316
Many of these additional capabilities were developed by Barry Rowlingson and released in the **rgdal** codebase in 2006, as described in @rowlingson_rasp:_2003 and the [R-help](https://stat.ethz.ch/pipermail/r-help/2003-January/028413.html) email list.
317317

318318
The **sp** package, released in 2005, was a significant advancement in R's spatial capabilities.
@@ -367,7 +367,7 @@ Additional ways of representing and working with geographic data in R since 2018
367367
\index{lidR (package)}
368368

369369
Such developments have been motivated by the emergence of new technologies, standards and software outside of the R environment [@bivand_progress_2021].
370-
Major updates to the PROJ library\index{PROJ} beginning in 2018 forced the replacement of 'proj-string' representations of coordinate reference systems with 'Well Known Text', as described in Section \@ref(crs-intro) and Chapter \@ref(reproj-geo-data).
370+
Major updates to the PROJ library\index{PROJ} beginning in 2018 forced the replacement of 'proj-string' representations of CRSs with 'Well Known Text', as described in Section \@ref(crs-intro) and Chapter \@ref(reproj-geo-data).
371371

372372
\index{rayshader (package)}
373373
Since the publication of the first version of Geocomputation with R in 2018, several packages for spatial data visualization have been developed and improved.

02-spatial-data.Rmd

Lines changed: 85 additions & 84 deletions
Large diffs are not rendered by default.

03-attribute-operations.Rmd

Lines changed: 29 additions & 29 deletions
Large diffs are not rendered by default.

04-spatial-operations.Rmd

Lines changed: 53 additions & 52 deletions
Large diffs are not rendered by default.

05-geometry-operations.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Importantly it also shows how to 'polygonize' rasters and 'rasterize' vector dat
4040
## Geometric operations on vector data {#geo-vec}
4141

4242
This section is about operations that in some way change the geometry of vector (`sf`) objects.
43-
It is more advanced than the spatial data operations presented in the previous chapter (in Section \@ref(spatial-vec)), because here we drill down into the geometry:
43+
It is more advanced than the spatial data operations presented in the previous chapter (Section \@ref(spatial-vec)), because here we drill down into the geometry:
4444
the functions discussed in this section work on objects of class `sfc` in addition to objects of class `sf`.
4545

4646
### Simplification
@@ -876,7 +876,7 @@ The main resampling methods include:
876876
- Nearest neighbor: assigns the value of the nearest cell of the original raster to the cell of the target one. This is a fast simple technique that is usually suitable for resampling categorical rasters.
877877
- Bilinear interpolation: assigns a weighted average of the four nearest cells from the original raster to the cell of the target one (Figure \@ref(fig:bilinear)). This is the fastest method that is appropriate for continuous rasters.
878878
- Cubic interpolation: uses values of the 16 nearest cells of the original raster to determine the output cell value, applying third-order polynomial functions. Used for continuous rasters and results in a smoother surface compared to bilinear interpolation but is computationally more demanding.
879-
- Cubic spline interpolation: also uses values of the 16 nearest cells of the original raster to determine the output cell value but applies cubic splines (piece-wise third-order polynomial functions). Used for continuous rasters.
879+
- Cubic spline interpolation: also uses values of the 16 nearest cells of the original raster to determine the output cell value, but applies cubic splines (piece-wise third-order polynomial functions). Used for continuous rasters.
880880
- Lanczos windowed sinc resampling: uses values of the 36 nearest cells of the original raster to determine the output cell value. Used for continuous rasters.^[
881881
More detailed explanation of this method can be found at https://gis.stackexchange.com/a/14361/20955.
882882
]

06-raster-vector.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ srtm_cropped = crop(srtm, zion)
5656

5757
\index{raster!masking}
5858
Related to `crop()` is the **terra** function `mask()`, which sets values outside of the bounds of the object passed to its second argument to `NA`.
59-
The following command therefore masks every cell outside of the Zion National Park boundaries (Figure \@ref(fig:cropmask)(C)).
59+
The following command therefore masks every cell outside of Zion National Park boundaries (Figure \@ref(fig:cropmask)(C)).
6060

6161
```{r 06-raster-vector-4 }
6262
srtm_masked = mask(srtm, zion)
@@ -119,7 +119,7 @@ The reverse of raster extraction --- assigning raster cell values based on vecto
119119

120120
\index{raster!extraction points}
121121
The basic example is of extracting the value of a raster cell at specific **points**.
122-
For this purpose, we will use `zion_points`, which contain a sample of 30 locations within the Zion National Park (Figure \@ref(fig:pointextr)).
122+
For this purpose, we will use `zion_points`, which contain a sample of 30 locations within Zion National Park (Figure \@ref(fig:pointextr)).
123123
The following command extracts elevation values from `srtm` and creates a data frame with points' IDs (one value per vector's row) and related `srtm` values for each point.
124124
Now, we can add the resulting object to our `zion_points` dataset with the `cbind()` function:
125125

@@ -483,7 +483,7 @@ grain_poly = as.polygons(grain) |>
483483
st_as_sf()
484484
```
485485

486-
```{r 06-raster-vector-40, echo=FALSE, fig.cap="Vectorization of (A) raster into (B) polygons (dissolve = FALSE) and aggregated polygons (dissolve = TRUE).", warning=FALSE, message=FALSE, fig.asp=0.4, fig.scap="Illustration of vectorization."}
486+
```{r 06-raster-vector-40, echo=FALSE, fig.cap="Vectorization of (A) raster into (B) polygons (dissolve = FALSE) and aggregated polygons (dissolve = TRUE).", warning=FALSE, message=FALSE, fig.asp=0.4, fig.scap="Vectorization."}
487487
source("code/06-raster-vectorization2.R", print.eval = TRUE)
488488
```
489489

07-reproj.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ It demonstrates how to set and *transform* geographic data from one CRS to anoth
2525
\index{CRS!projected}
2626

2727
In many projects there is no need to worry about, let alone convert between, different CRSs.
28-
Nonetheless, it is important to know if your data is in a projected or geographic coordinate reference system, and the consequences of this for geometry operations.
28+
Nonetheless, it is important to know if your data is in a projected or geographic CRS, and the consequences of this for geometry operations.
2929
If you know this information, CRSs should *just work* behind the scenes: people often suddenly need to learn about CRSs when things go wrong.
3030
Having a clearly defined CRS that all project data is in, and understanding how and why to use different CRSs, can ensure that things don't go wrong.
3131
Furthermore, learning about coordinate systems will deepen your knowledge of geographic datasets and how to use them effectively.
@@ -518,7 +518,7 @@ london2 = st_transform(london_geo, "EPSG:27700")
518518

519519
Now that a transformed version of `london` has been created, using the **sf** function `st_transform()`, the distance between the two representations of London can be found.^[
520520
An alternative to `st_transform()` is `st_transform_proj()` from the **lwgeom**, which enables transformations and which bypasses GDAL and can support projections not supported by GDAL.
521-
However, at the time of writing (2022) we could not find any projections supported by `st_transform_proj()` but not supported by `st_transform()`.
521+
However, at the time of writing (2024) we could not find any projections supported by `st_transform_proj()` but not supported by `st_transform()`.
522522
]
523523
It may come as a surprise that `london` and `london2` are over 2 km apart!^[
524524
The difference in location between the two points is not due to imperfections in the transforming operation (which is in fact very accurate) but the low precision of the manually-created coordinates that created `london` and `london_proj`.

08-read-write-plot.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,15 @@ It is fast and flexible, but it may be worth looking at other packages such as *
271271
### Raster data {#raster-data-read}
272272

273273
\index{raster!data input}
274-
Similar to vector data, raster data comes in many file formats with some supporting multilayer files.
274+
Similar to vector data, raster data comes in many file formats with some supporting multi-layerfiles.
275275
**terra**'s `rast()` command reads in a single layer when a file with just one layer is provided.
276276

277277
```{r 07-read-write-plot-24, message=FALSE}
278278
raster_filepath = system.file("raster/srtm.tif", package = "spDataLarge")
279279
single_layer = rast(raster_filepath)
280280
```
281281

282-
It also works in case you want to read a multilayer file.
282+
It also works in case you want to read a multi-layerfile.
283283

284284
```{r 07-read-write-plot-25}
285285
multilayer_filepath = system.file("raster/landsat.tif", package = "spDataLarge")
@@ -519,7 +519,7 @@ usa_sf = ne_countries(country = "United States of America", returnclass = "sf")
519519
Country borders can be also accessed with other packages, such as **geodata**, **giscoR**, or **rgeoboundaries**.
520520

521521
A second example downloads a series of rasters containing global monthly precipitation sums with spatial resolution of 10 minutes (~18.5 km at the equator) using the **geodata** package [@R-geodata].
522-
The result is a multilayer object of class `SpatRaster`.
522+
The result is a multi-layerobject of class `SpatRaster`.
523523

524524
```{r 07-read-write-plot-5, eval=FALSE}
525525
library(geodata)
@@ -632,7 +632,7 @@ Map image representations, such as tiles, can be accessed with the Web Map Servi
632632
Metadata is also covered by means of the Catalogue Service for the Web (CSW)\index{geographic web services!CSW}.
633633
Finally, standard processing is handled through the Web Processing Service (WPS)\index{geographic web services!WPS} or the the Web Coverage Processing Service (WCPS)\index{geographic web services!WCPS}.
634634

635-
Various open-source projects have adopted these protocols, such as [GeoServer](https://geoserver.org/) and [MapServer](https://mapserver.org/) for data handling, or [GeoNetwork](https://geonetwork-opensource.org/) and [PyCSW](https://pycsw.org/) for metadata handling, leading to standardization of queries.
635+
Various open-source projects have adopted these protocols, such as [GeoServer](https://geoserver.org/) and [MapServer](https://mapserver.org/) for data-handling, or [GeoNetwork](https://geonetwork-opensource.org/) and [PyCSW](https://pycsw.org/) for metadata-handling, leading to standardization of queries.
636636
Integrated tools for Spatial Data Infrastructures (SDI), such as [GeoNode](https://geonode.org/), [GeOrchestra](https://www.georchestra.org/) or [Examind](https://www.examind.com/) have also adopted these standard webservices, either directly or by using previously mentioned open-source tools.
637637

638638
Like other web APIs, OWS APIs use a 'base URL', an 'endpoint' and 'URL query arguments' following a `?` to request data (see the [`best-practices-api-packages`](https://httr.r-lib.org/articles/api-packages.html) vignette in the **httr** package).

09-mapping.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ tm_shape(nz) + tm_polygons(fill = "Median_income",
285285
fill.scale = tm_scale(values = "BuGn"))
286286
```
287287

288-
```{r tmpal, message=FALSE, fig.cap="Illustration of color settings. The results show (from left to right): default settings, manual breaks, n breaks, and the impact of changing the palette.", fig.scap="Illustration of color settings.", echo=FALSE, fig.asp=0.56, warning=FALSE}
288+
```{r tmpal, message=FALSE, fig.cap="Color settings. The results show (from left to right): default settings, manual breaks, n breaks, and the impact of changing the palette.", fig.scap="Color settings.", echo=FALSE, fig.asp=0.56, warning=FALSE}
289289
source("https://github.com/geocompx/geocompr/raw/main/code/09-tmpal.R", print.eval = TRUE)
290290
```
291291

@@ -328,7 +328,7 @@ Other options are listed below and presented in Figure \@ref(fig:break-styles).
328328
Although `style` is an argument of **tmap** functions, in fact it originates as an argument in `classInt::classIntervals()` --- see the help page of this function for details.
329329
```
330330

331-
```{r break-styles, message=FALSE, fig.cap="Different interval scale methods set using the style argument in tmap.", fig.scap="Illustration of different binning methods using tmap.", echo=FALSE, warning=FALSE, fig.width=8}
331+
```{r break-styles, message=FALSE, fig.cap="Different interval scale methods set using the style argument in tmap.", fig.scap="Different binning methods using tmap.", echo=FALSE, warning=FALSE, fig.width=8}
332332
source("code/09-break-styles.R", print.eval = TRUE)
333333
```
334334

11-algorithms.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ source("code/before_script.R")
66

77
## Prerequisites {-}
88

9-
This chapter has minimal software prerequisites as it primarily uses base R.
9+
This chapter has minimal software prerequisites, as it primarily uses base R.
1010
Only, the **sf**\index{sf} package is used to check the results of an algorithm we will develop to calculate the area of polygons.
1111
In terms of prior knowledge, this chapter assumes you have an understanding of the geographic classes introduced in Chapter \@ref(spatial-class) and how they can be used to represent a wide range of input file formats (see Chapter \@ref(read-write)).
1212

@@ -199,7 +199,7 @@ C1 = (T1[1,] + T1[2,] + T1[3,]) / 3
199199
C1_alternative = (T1[1, , drop = FALSE] + T1[2, , drop = FALSE] + T1[3, , drop = FALSE]) / 3
200200
```
201201

202-
```{r polymat, echo=FALSE, fig.cap="Illustration of polygon centroid calculation problem.", fig.height="100", warning=FALSE}
202+
```{r polymat, echo=FALSE, fig.cap="Polygon centroid calculation problem.", fig.height="100", warning=FALSE}
203203
# initial plot: can probably delete this:
204204
old_par = par(pty = "s")
205205
plot(poly_mat, cex = 3)
@@ -282,7 +282,7 @@ Algorithm\index{algorithm} development is hard.
282282
This should be apparent from the amount of work that has gone into developing a centroid\index{centroid} algorithm\index{algorithm} in base R\index{R} that is just one, rather inefficient, approach to the problem with limited real-world applications (convex polygons are uncommon in practice).
283283
The experience should lead to an appreciation of low-level geographic libraries such as GEOS\index{GEOS} and CGAL\index{CGAL} (the Computational Geometry Algorithms Library) which not only run fast but work on a wide range of input geometry types.
284284
A great advantage of the open source nature of such libraries is that their source code\index{source code} is readily available for study, comprehension and (for those with the skills and confidence) modification.^[
285-
The CGAL\index{CGAL} function `CGAL::centroid()` is in fact composed of 7 sub-functions as described at https://doc.cgal.org/latest/Kernel_23/group__centroid__grp.html allowing it to work on a wide range of input data types, whereas the solution we created works only on a very specific input data type.
285+
The CGAL\index{CGAL} function `CGAL::centroid()` is in fact composed of seven sub-functions as described at https://doc.cgal.org/latest/Kernel_23/group__centroid__grp.html allowing it to work on a wide range of input data types, whereas the solution we created works only on a very specific input data type.
286286
The source code underlying GEOS\index{GEOS} function `Centroid::getCentroid()` can be found at https://github.com/libgeos/geos/search?q=getCentroid.
287287
]
288288

13-transport.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ View(cw0103)
119119

120120
Like many cities, Bristol has major congestion, air quality and physical inactivity problems.
121121
Cycling can tackle all of these issues efficiently: it has a greater potential to replace car trips than walking, with typical [speeds](https://en.wikipedia.org/wiki/Bicycle_performance) of 15-20 km/h vs 4-6 km/h for walking.
122-
For this reason Bristol's [Transport Strategy](https://www.bristol.gov.uk/council-and-mayor/policies-plans-and-strategies/bristol-transport-strategy) has ambitious plans for cycling.
122+
For this reason, Bristol's [Transport Strategy](https://www.bristol.gov.uk/council-and-mayor/policies-plans-and-strategies/bristol-transport-strategy) has ambitious plans for cycling.
123123

124124
To highlight the importance of policy considerations in transportation research, this chapter is guided by the need to provide evidence for people (transport planners, politicians and other stakeholders) tasked with getting people out of cars and onto more sustainable modes --- walking and cycling in particular.
125125
The broader aim is to demonstrate how geocomputation can support evidence-based transport planning.
@@ -505,8 +505,8 @@ While R users can access CycleStreets routes via the package [**cyclestreets**](
505505
### Contraction hierarchies and traffic assigment
506506

507507
Contraction hierarchies and traffic assignment are advanced but important topics in transport modeling worth being aware of, especially if you want your code to scale to large networks.
508-
Calculating many routes is computationally resource intensive and can take hours, leading to the development of several algorithms to speed-up routing calculations.
509-
**Contraction hierarchies** is a well-known algorithm that can lead to a substantial (1000x+ in some cases) speed-up in routing tasks, depending on network size.
508+
Calculating many routes is computationally resource intensive and can take hours, leading to the development of several algorithms to speed up routing calculations.
509+
**Contraction hierarchies** is a well-known algorithm that can lead to a substantial (1000x+ in some cases) speed up in routing tasks, depending on network size.
510510
Contraction hierarchies are used behind the scenes in the routing engines mentioned in the previous sections.
511511

512512
Traffic assignment is a problem that is closely related to routing: in practice, the shortest path between two points is not always the fastest, especially if there is congestion.
@@ -691,7 +691,7 @@ ways_centrality = ways_sfn |>
691691
mutate(betweenness = tidygraph::centrality_edge_betweenness(lengths))
692692
```
693693

694-
```{r wayssln, fig.cap="Illustration of route network datasets. The grey lines represent a simplified road network, with segment thickness proportional to betweenness. The green lines represent potential cycling flows (one way) calculated with the code above.", fig.scap="Illustration of a small route network.", echo=FALSE}
694+
```{r wayssln, fig.cap="Illustration of route network datasets. The grey lines represent a simplified road network, with segment thickness proportional to betweenness. The green lines represent potential cycling flows (one way) calculated with the code above.", fig.scap="A small route network.", echo=FALSE}
695695
bb_wayssln = tmaptools::bb(route_network_scenario, xlim = c(0.1, 0.9), ylim = c(0.1, 0.6), relative = TRUE)
696696
tm_shape(zones_od) +
697697
tm_fill(fill_alpha = 0.2, lwd = 0.1) +

0 commit comments

Comments
 (0)