From e1e584631b1127a4090885e38b3d7f8fcec99262 Mon Sep 17 00:00:00 2001 From: Jakub Nowosad Date: Sat, 14 May 2022 14:20:54 -0400 Subject: [PATCH 1/2] related to #798 --- 05-geometry-operations.Rmd | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/05-geometry-operations.Rmd b/05-geometry-operations.Rmd index 4e66d29a0..335995bc5 100644 --- a/05-geometry-operations.Rmd +++ b/05-geometry-operations.Rmd @@ -463,8 +463,8 @@ plot(us_southhwest) \index{vector!geometry casting} Geometry casting is a powerful operation that enables transformation of the geometry type. -It is implemented in the `st_cast` function from the **sf** package. -Importantly, `st_cast` behaves differently on single simple feature geometry (`sfg`) objects, simple feature geometry column (`sfc`) and simple features objects. +It is implemented in the `st_cast()` function from the **sf** package. +Importantly, `st_cast()` behaves differently on single simple feature geometry (`sfg`) objects, simple feature geometry column (`sfc`) and simple features objects. Let's create a multipoint to illustrate how geometry casting works on simple feature geometry (`sfg`) objects: @@ -472,14 +472,14 @@ Let's create a multipoint to illustrate how geometry casting works on simple fea multipoint = st_multipoint(matrix(c(1, 3, 5, 1, 3, 1), ncol = 2)) ``` -In this case, `st_cast` can be useful to transform the new object into linestring or polygon (Figure \@ref(fig:single-cast)): +In this case, `st_cast()` can be useful to transform the new object into a linestring or a polygon (Figure \@ref(fig:single-cast)): ```{r 05-geometry-operations-29} linestring = st_cast(multipoint, "LINESTRING") polyg = st_cast(multipoint, "POLYGON") ``` -```{r single-cast, echo = FALSE, fig.cap="Examples of linestring and polygon casted from a multipoint geometry.", warning=FALSE, fig.asp=0.3, fig.scap="Examples of casting operations."} +```{r single-cast, echo = FALSE, fig.cap="Examples of a linestring and a polygon casted from a multipoint geometry.", warning=FALSE, fig.asp=0.3, fig.scap="Examples of casting operations."} p_sc1 = tm_shape(st_sfc(multipoint)) + tm_symbols(shape = 1, col = "black", size = 0.5) + tm_layout(main.title = "MULTIPOINT", inner.margins = c(0.05, 0.05, 0.05, 0.05)) p_sc2 = tm_shape(st_sfc(linestring)) + tm_lines() + @@ -490,10 +490,10 @@ tmap_arrange(p_sc1, p_sc2, p_sc3, ncol = 3) ``` Conversion from multipoint to linestring is a common operation that creates a line object from ordered point observations, such as GPS measurements or geotagged media. -This allows spatial operations such as the length of the path traveled. +This, in turn, allows to perform spatial operations such as the calculation of the length of the path traveled. Conversion from multipoint or linestring to polygon is often used to calculate an area, for example from the set of GPS measurements taken around a lake or from the corners of a building lot. -The transformation process can be also reversed using `st_cast`: +The transformation process can be also reversed using `st_cast()`: ```{r 05-geometry-operations-30} multipoint_2 = st_cast(linestring, "MULTIPOINT") @@ -503,8 +503,8 @@ all.equal(multipoint, multipoint_3) ``` ```{block2 05-geometry-operations-31, type='rmdnote'} -For single simple feature geometries (`sfg`), `st_cast` also provides geometry casting from non-multi-types to multi-types (e.g., `POINT` to `MULTIPOINT`) and from multi-types to non-multi-types. -However, only the first element of the old object would remain in the second group of cases. +For single simple feature geometries (`sfg`), `st_cast()` also provides geometry casting from non-multi-types to multi-types (e.g., `POINT` to `MULTIPOINT`) and from multi-types to non-multi-types. +However, when casting from multi-types to non-multi-types only the first element of the old object would remain in the output object. ``` ```{r 05-geometry-operations-32, include=FALSE} @@ -516,9 +516,9 @@ t = cast_all(multipoint) t2 = cast_all(polyg) ``` -Geometry casting of simple features geometry column (`sfc`) and simple features objects works the same as for single geometries in most of the cases. +Geometry casting of simple features geometry column (`sfc`) and simple features objects works the same as for `sfg` in most of the cases. One important difference is the conversion between multi-types to non-multi-types. -As a result of this process, multi-objects are split into many non-multi-objects. +As a result of this process, multi-objects of `sfc` or `sf` are split into many non-multi-objects. Table \@ref(tab:sfs-st-cast) shows possible geometry type transformations on simple feature objects. Each input simple feature object with only one element (first column) is transformed directly into another geometry type. @@ -562,7 +562,7 @@ multilinestring_sf You can imagine it as a road or river network. The new object has only one row that defines all the lines. This restricts the number of operations that can be done, for example it prevents adding names to each line segment or calculating lengths of single lines. -The `st_cast` function can be used in this situation, as it separates one mutlilinestring into three linestrings: +The `st_cast()` function can be used in this situation, as it separates one mutlilinestring into three linestrings: ```{r 05-geometry-operations-34} linestring_sf2 = st_cast(multilinestring_sf, "LINESTRING") From 2ec4d671e5ffeaaf0bb111292b3a47499360a743 Mon Sep 17 00:00:00 2001 From: Robin Lovelace Date: Sat, 14 May 2022 20:23:14 +0100 Subject: [PATCH 2/2] Update 05-geometry-operations.Rmd --- 05-geometry-operations.Rmd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/05-geometry-operations.Rmd b/05-geometry-operations.Rmd index 335995bc5..300c17a45 100644 --- a/05-geometry-operations.Rmd +++ b/05-geometry-operations.Rmd @@ -521,10 +521,10 @@ One important difference is the conversion between multi-types to non-multi-type As a result of this process, multi-objects of `sfc` or `sf` are split into many non-multi-objects. Table \@ref(tab:sfs-st-cast) shows possible geometry type transformations on simple feature objects. -Each input simple feature object with only one element (first column) is transformed directly into another geometry type. -Several of the transformations are not possible, for example, you cannot convert a single point into a multilinestring or a polygon (so the cells `[1, 4:5]` in the table are NA). -On the other hand, some of the transformations are splitting the single element input object into a multi-element object. -You can see that, for example, when you cast a multipoint consisting of five pairs of coordinates into a point. +Single simple feature geometries (represented by the first column in the table) can be transformed into multiple geometry types, represented by the columns in Table \@ref(tab:sfs-st-cast). +Some transformations are not possible: you cannot convert a single point into a multilinestring or a polygon, for example, explaining why the cells `[1, 4:5]` in the table contain NA. +Some transformations split single features input into multiple sub-features, 'expanding' `sf` objects (adding new rows with duplicate attribute values). +When a multipoint geometry consisting of five pairs of coordinates is tranformed into a 'POINT' geometry, for example, the output will contain five features. ```{r sfs-st-cast, echo=FALSE} sfs_st_cast = read.csv("extdata/sfs-st-cast.csv")