References
https://www.amazon.com/Learning-Geospatial-Analysis-Michael-Dorman/dp/1783984368↩︎
Comprehensive R Archive Network↩︎
https://cran.r-project.org/web/packages/sf/vignettes/sf2.html#reading_and_writing_directly_to_and_from_spatial_databases↩︎
https://cran.r-project.org/web/packages/sf/vignettes/sf5.html#ggplot2↩︎
https://cran.r-project.org/web/packages/stars/vignettes/stars3.html#geom_stars↩︎
Prefixing code output with
#
makes the interpreter ignore it (Section 1.3.3). That way, the entire code output can be safely copied and pasted into the interpretor.↩︎“To understand computations in R, two slogans are helpful: (1) Everything that exists is an object. (2) Everything that happens is a function call.” (Chambers, 2014, Statistical Science, https://arxiv.org/pdf/1409.3531.pdf)↩︎
The full list of date format symbols can be found in
?strptime
↩︎When typing
value < -213
, make sure there is a space between<
and-
. Otherwise the combination is interpreted as an assignment operator<-
!↩︎Note that, when comparing rates of change, which is what we inmlicitly do with
which.min(d_value)
andwhich.max(d_value)
, we need to divide the differences (diff(value)
) by the time differences (diff(time)
). In this particular dataset, this does not matter, because the time differences between measurements are fixed at ~6 months.↩︎In R versions <4.0.0, the additional
stringAsFactors=FALSE
argument was required to prevent the conversion of text columns tofactor
, which is what we usually want. Afactor
is a special type of a categorical vector. It is less relevant for our purposes and therefore we will not be usingfactor
objects in this book. In R ≥4.0.0, we do not need to worry about that sincestringAsFactors=FALSE
became the default in functionsdata.frame
,read.csv
(Section 4.4.1) andst_read
(Section 7.7).↩︎R has other functions for reading tables in other formats, such as the
read.xlsx
function, from theopenxlsx
package, for reading Excel (.xlsx
) files.↩︎If there are numerous matches, the corresponding rows of
x
are duplicated to accomodate all matching values. This is usually an undesired situation. Therefore, we want to make sure that all values in the key column ofy
are unique, before doing a left join. That way, we make sure that no duplication takes place, and the join result contains exactly the same number of rows asx
.↩︎Population in 2019, based on Wikipedia.↩︎
Since R 4.0.0 (https://cran.r-project.org/doc/manuals/r-devel/NEWS.html).↩︎
Due to the conventions of
image
, amatrix
image is actually reversed in 90 degrees compared to the textual representation of amatrix
. To get the same orientation as in the textual representation, useimage(t(apply(volcano,2,rev)))
↩︎There are similar functions named
rowSums
andcolSums
for calculating row and column sums, respectively.↩︎Note that there are no data structure for zero-dimensional data structures (i.e., scalars) in R.↩︎
Unless a new version of a package was released and we want to update it, in which case we need to re-install the package.↩︎
GeoTIFF files can come with both
*.tif
and*.tiff
file extension, so if one of them does not work you should try the other.↩︎Note that
offset
anddelta
should be set together, since setting one of them resets the other toNA
.↩︎https://landsat.usgs.gov/what-are-band-designations-landsat-satellites↩︎
This type of a false color image mapping emphasizes green vegetation (in red).↩︎
We can also do the above reclassification with a single expression, using
cut(ndvi, breaks = c(-Inf, 0.2, Inf))
. This becomes especially convenient if we have numerous categories or classes. The result consists of values of typefactor
, which we don’t go into in this book.↩︎st_apply
also accepts vector of (fixed) length n larger than 1, in which casest_apply
returns a multi-band raster with n layers.↩︎in Windows.↩︎
For a complete list of vector formats that can be read with
st_read
, runst_drivers(what="vector")
.↩︎Use
valid_udunits()
to see the list of available units.↩︎To avoid these “patches”, we can reduce the precision of the calculation using function
st_set_precision
. For example, compare the plot ofst_union(st_set_precision(nm, units::set_units(1, "m")))
with the plot ofst_union(nm)
(Figure 8.10) (https://keen-swartz-3146c4.netlify.app/geommanip.html#precision).↩︎Alternatively, the
group_by
andsummarize
functions from packagedplyr
can also be used for aggregation:s2 = s %>% group_by(NAME_1) %>% summarize(area = sum(area))
.↩︎For example, when the resolution of the new grid is coarser than the resolution of the original raster.↩︎
The
raster
package does have such a function, namedfocal
.↩︎The
st_as_sf
function is used to transform fromstars
tosf
, which we learn about in Section 10.3.↩︎If necessary, we can convert those pixels that have
NA
in all layers to polygons, too, by specifyingna.rm=FALSE
.↩︎If necessary, we can convert those pixels that have
NA
in all layers to points, too, by specifyingna.rm=FALSE
.↩︎Recall that we already used
aggregate
for a different use case: dissolving vector layers by attribute (Section 8.4).↩︎Note that using
aggregate
to extract raster values by polygons is only appropriate for non-overlapping polygons. For polygons that are potentially overlapping, useraster::extract
.↩︎The
~ 1
part means there are no independent variables other than the intercept.↩︎