Skip to content

Commit 850ba5d

Browse files
committed
starts updating the grass section
1 parent 22164c6 commit 850ba5d

File tree

1 file changed

+30
-36
lines changed

1 file changed

+30
-36
lines changed

10-gis.Rmd

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -400,48 +400,43 @@ The U.S. Army - Construction Engineering Research Laboratory (USA-CERL) created
400400
Academia continued this work since 1997.
401401
Similar to SAGA\index{SAGA}, GRASS focused on raster processing in the beginning while only later, since GRASS 6.0, adding advanced vector functionality [@bivand_applied_2013].
402402

403-
<!-- We will introduce **rgrass7**\index{rgrass7 (package)} with one of the most interesting problems in GIScience - the traveling salesman problem\index{traveling salesman}. -->
404-
<!-- Suppose a traveling salesman would like to visit 24 customers. -->
405-
<!-- Additionally, he would like to start and finish his journey at home which makes a total of 25 locations while covering the shortest distance possible. -->
406-
<!-- There is a single best solution to this problem; however, to find it is even for modern computers (mostly) impossible [@longley_geographic_2015]. -->
407-
<!-- In our case, the number of possible solutions correspond to `(25 - 1)! / 2`, i.e., the factorial of 24 divided by 2 (since we do not differentiate between forward or backward direction). -->
408-
<!-- Even if one iteration can be done in a nanosecond, this still corresponds to `r format(factorial(25 - 1) / (2 * 10^9 * 3600 * 24 * 365))` years. -->
409-
<!-- Luckily, there are clever, almost optimal solutions which run in a tiny fraction of this inconceivable amount of time. -->
410-
<!-- GRASS GIS\index{GRASS} provides one of these solutions (for more details, see [v.net.salesman](https://grass.osgeo.org/grass77/manuals/v.net.salesman.html)). -->
411-
<!-- In our use case, we would like to find the shortest path\index{shortest route} between the first 25 bicycle stations (instead of customers) on London's streets (and we simply assume that the first bike station corresponds to the home of our traveling salesman\index{traveling salesman}). -->
412-
413-
<!-- ```{r 09-gis-24} -->
414-
<!-- data("cycle_hire", package = "spData") -->
415-
<!-- points = cycle_hire[1:25, ] -->
416-
<!-- ``` -->
417-
418-
<!-- Aside from the cycle hire points data, we will need the OpenStreetMap\index{OpenStreetMap} data of London. -->
419-
<!-- We download it with the help of the **osmdata**\index{osmdata (package)} package (see also Section \@ref(retrieving-data)). -->
420-
<!-- We constrain the download of the street network (in OSM language called "highway") to the bounding box\index{bounding box} of the cycle hire data, and attach the corresponding data as an `sf`-object\index{sf}. -->
421-
<!-- `osmdata_sf()` returns a list with several spatial objects (points, lines, polygons, etc.). -->
422-
<!-- Here, we will only keep the line objects. -->
403+
Here, we introduce **rgrass**\index{rgrass (package)} with one of the most interesting problems in GIScience - the traveling salesman problem\index{traveling salesman}.
404+
Suppose a traveling salesman would like to visit 24 customers.
405+
Additionally, he would like to start and finish his journey at home which makes a total of 25 locations while covering the shortest distance possible.
406+
There is a single best solution to this problem; however, to check all of the possible solutions it is (mostly) impossible for modern computers [@longley_geographic_2015].
407+
In our case, the number of possible solutions correspond to `(25 - 1)! / 2`, i.e., the factorial of 24 divided by 2 (since we do not differentiate between forward or backward direction).
408+
Even if one iteration can be done in a nanosecond, this still corresponds to `r format(factorial(25 - 1) / (2 * 10^9 * 3600 * 24 * 365))` years.
409+
Luckily, there are clever, almost optimal solutions which run in a tiny fraction of this inconceivable amount of time.
410+
GRASS GIS\index{GRASS} provides one of these solutions (for more details, see [v.net.salesman](https://grass.osgeo.org/grass80/manuals/v.net.salesman.html)).
411+
In our use case, we would like to find the shortest path\index{shortest route} between the first 25 bicycle stations (instead of customers) on London's streets (and we simply assume that the first bike station corresponds to the home of our traveling salesman\index{traveling salesman}).
412+
413+
```{r 09-gis-24}
414+
data("cycle_hire", package = "spData")
415+
points = cycle_hire[1:25, ]
416+
```
417+
418+
Aside from the cycle hire points data, we need a street network for this area.
419+
We can download it with from OpenStreetMap\index{OpenStreetMap} with the help of the **osmdata** \index{osmdata (package)} package (see also Section \@ref(retrieving-data)).
420+
To do this, we constrain the query of the street network (in OSM language called "highway") to the bounding box\index{bounding box} of `points`, and attach the corresponding data as an `sf`-object\index{sf}.
421+
`osmdata_sf()` returns a list with several spatial objects (points, lines, polygons, etc.), but here, we only keep the line objects with their related ids.
423422
<!-- OpenStreetMap\index{OpenStreetMap} objects come with a lot of columns, `streets` features almost 500. -->
424423
<!-- In fact, we are only interested in the geometry column. -->
425424
<!-- Nevertheless, we are keeping one attribute column; otherwise, we will run into trouble when trying to provide `writeVECT()` only with a geometry object (see further below and `?writeVECT` for more details). -->
426425
<!-- Remember that the geometry column is sticky, hence, even though we are just selecting one attribute, the geometry column will be also returned (see Section \@ref(intro-sf)). -->
427426

428-
<!-- ```{r 09-gis-25, eval=FALSE} -->
429-
<!-- library(osmdata) -->
430-
<!-- b_box = st_bbox(points) -->
431-
<!-- london_streets = opq(b_box) %>% -->
432-
<!-- add_osm_feature(key = "highway") %>% -->
433-
<!-- osmdata_sf() %>% -->
434-
<!-- `[[`("osm_lines") -->
435-
<!-- london_streets = dplyr::select(london_streets, osm_id) -->
436-
<!-- ``` -->
437-
438-
<!-- As a convenience to the reader, one can attach `london_streets` to the global environment using `data("london_streets", package = "spDataLarge")`. -->
427+
```{r 09-gis-25, eval=FALSE}
428+
library(osmdata)
429+
b_box = st_bbox(points)
430+
london_streets = opq(b_box) %>%
431+
add_osm_feature(key = "highway") %>%
432+
osmdata_sf()
433+
london_streets = london_streets[["osm_lines"]]
434+
london_streets = dplyr::select(london_streets, osm_id)
435+
```
439436

440-
<!-- ```{r 09-gis-26, eval=FALSE, echo=FALSE} -->
441-
<!-- data("london_streets", package = "spDataLarge") -->
442-
<!-- ``` -->
437+
As a convenience to the reader, one can attach `london_streets` to the global environment using `data("london_streets", package = "spDataLarge")`.
443438

444-
<!-- Now that we have the data, we can go on and initiate a GRASS\index{GRASS} session, i.e., we have to create a GRASS spatial database. -->
439+
Now that we have the data, we can go on and initiate a GRASS\index{GRASS} session, i.e., we have to create a GRASS spatial database.
445440
<!-- The GRASS geodatabase \index{spatial database} system is based on SQLite. -->
446441
<!-- Consequently, different users can easily work on the same project, possibly with different read/write permissions. -->
447442
<!-- However, one has to set up this spatial database\index{spatial database} (also from within R), and users used to a GIS GUI\index{graphical user interface} popping up by one click might find this process a bit intimidating in the beginning. -->
@@ -642,7 +637,6 @@ It has [geoprocessing tools](https://gdal.org/programs/index.html) for vector an
642637
<!--toDo:jn-->
643638
<!--expand a list of what is possible-->
644639

645-
646640
The code chunk below demonstrates this functionality:
647641
`linkGDAL()` searches the computer for a working GDAL\index{GDAL} installation and adds the location of the executable files to the PATH variable, allowing GDAL to be called.
648642

0 commit comments

Comments
 (0)