Spatial Data Science With Applications in R 1st Edition All Chapters Included
Spatial Data Science With Applications in R 1st Edition All Chapters Included
Visit the link below to download the full version of this book:
https://medipdf.com/product/spatial-data-science-with-applications-in-r-1st-edit
ion/
Reasonable efforts have been made to publish reliable data and information, but the author and pub-
lisher cannot assume responsibility for the validity of all materials or the consequences of their use.
The authors and publishers have attempted to trace the copyright holders of all material reproduced
in this publication and apologize to copyright holders if permission to publish in this form has not
been obtained. If any copyright material has not been acknowledged please write and let us know so
we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced,
transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or
hereafter invented, including photocopying, microfilming, and recording, or in any information stor-
age or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, access www.copyright.com
or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923,
978-750-8400. For works that are not available on CCC please contact [email protected]
Trademark notice: Product or corporate names may be trademarks or registered trademarks and are
used only for identification and explanation without intent to infringe.
DOI: 10.1201/9780429459016
Publisher’s note: This book has been prepared from camera-ready copy provided by the authors.
Preface xi
I Spatial Data 1
1 Getting Started 5
1.1 A first map . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Coordinate reference systems . . . . . . . . . . . . . . . . . . . 7
1.3 Raster and vector data . . . . . . . . . . . . . . . . . . . . . 8
1.4 Raster types . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.5 Time series, arrays, data cubes . . . . . . . . . . . . . . . . . . 11
1.6 Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.7 Spatial data science software . . . . . . . . . . . . . . . . . . 13
1.7.1 GDAL . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.7.2 PROJ . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.7.3 GEOS and s2geometry . . . . . . . . . . . . . . . . . . 14
1.7.4 NetCDF, udunits2, liblwgeom . . . . . . . . . . . . . . 14
1.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2 Coordinates 17
2.1 Quantities, units, datum . . . . . . . . . . . . . . . . . . . . . 17
2.2 Ellipsoidal coordinates . . . . . . . . . . . . . . . . . . . . . 18
2.2.1 Spherical or ellipsoidal coordinates . . . . . . . . . . . 19
2.2.2 Projected coordinates, distances . . . . . . . . . . . . . 21
2.2.3 Bounded and unbounded spaces . . . . . . . . . . . . 22
2.3 Coordinate reference systems . . . . . . . . . . . . . . . . . . 22
2.4 PROJ and mapping accuracy . . . . . . . . . . . . . . . . . . 23
2.5 WKT-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3 Geometries 29
3.1 Simple feature geometries . . . . . . . . . . . . . . . . . . . . 29
3.1.1 The big seven . . . . . . . . . . . . . . . . . . . . . . . 29
3.1.2 Simple and valid geometries, ring direction . . . . . . . 31
3.1.3 Z and M coordinates . . . . . . . . . . . . . . . . . . . . 31
3.1.4 Empty geometries . . . . . . . . . . . . . . . . . . . . 32
3.1.5 Ten further geometry types . . . . . . . . . . . . . . . 32
3.1.6 Text and binary encodings . . . . . . . . . . . . . . . 33
v
vi Contents
4 Spherical Geometries 45
4.1 Straight lines . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.2 Ring direction and full polygon . . . . . . . . . . . . . . . . . 45
4.3 Bounding box, rectangle, and cap . . . . . . . . . . . . . . . 46
4.4 Validity on the sphere . . . . . . . . . . . . . . . . . . . . . . . 47
4.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
6 Data Cubes 59
6.1 A four-dimensional data cube . . . . . . . . . . . . . . . . . 59
6.2 Dimensions, attributes, and support . . . . . . . . . . . . . . 60
6.2.1 Regular dimensions, GDAL’s geotransform . . . . . . 62
6.2.2 Support along cube dimensions . . . . . . . . . . . . . 62
6.3 Operations on data cubes . . . . . . . . . . . . . . . . . . . . 63
6.3.1 Slicing a cube: filter . . . . . . . . . . . . . . . . . . . 63
6.3.2 Applying functions to dimensions . . . . . . . . . . . . 64
6.3.3 Reducing dimensions . . . . . . . . . . . . . . . . . . . 64
6.4 Aggregating raster to vector cubes . . . . . . . . . . . . . . . 65
6.5 Switching dimension with attributes . . . . . . . . . . . . . . . 67
6.6 Other dynamic spatial data . . . . . . . . . . . . . . . . . . . . 67
6.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Contents vii
B R Basics 263
B.1 Pipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
B.2 Data structures . . . . . . . . . . . . . . . . . . . . . . . . . 264
B.2.1 Homogeneous vectors . . . . . . . . . . . . . . . . . . 264
B.2.2 Heterogeneous vectors: list . . . . . . . . . . . . . . . 265
B.2.3 NULL and removing list elements . . . . . . . . . . . . 267
B.2.4 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . 267
B.2.5 The names attributes . . . . . . . . . . . . . . . . . . . 270
B.2.6 Using structure . . . . . . . . . . . . . . . . . . . . . . 271
B.3 Dissecting a MULTIPOLYGON . . . . . . . . . . . . . . . . . . . 272
References 277
Index 291
Index of functions 299
Preface
xi
xii Preface
Acknowledgements
We are grateful to the entire r-spatial community, especially those who
• developed r-spatial packages or contributed to their development
• contributed to discussions on twitter #rspatial or GitHub
• brought comments or asked questions in courses, summer schools, or
conferences.
We are in particular grateful to Dewey Dunnington for implementing the s2
package, and for active contributions from Sahil Bhandari, Jonathan Bahlmann
for preparing the figures in Chapter 6, Claus Wilke, Jakub Nowosad, the
“Spatial Data Science with R” classes of 2021 and 2022, and to those who
actively contributed with GitHub issues, pull requests, or discussions:
Preface xiii
Spatial Data
3
The first part of this book introduces concepts of spatial data science: maps,
projections, vector and raster data structures, software, attributes and support,
and data cubes. This part uses R only to generate text output or figures. The R
code for this is not shown or explained, as it would distract from the message:
Part II focuses on the use of R. The online version of this book, found at
https://r-spatial.org/book/ contains the R code at the place where it is used in
hidden sections that can be unfolded on demand and copied to the clipboard
for execution and experimenting. Output from R code uses code font and has
lines starting with a #, as in
# Linking to GEOS 3.11.1, GDAL 3.6.2, PROJ 9.1.1; sf_use_s2()
# is TRUE
More detailed explanation of R code to solve spatial data science problems
starts in the second part of this book. Appendix B contains a short, elementary
explanation of R data structures, Wickham (2014a) gives a more extensive
treatment on this.
1
Getting Started
BIR74
37°N
36°N
35°N
34°N
Figure 1.1: A first map: birth counts 1974-78, North Carolina counties