-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathspatial-data-introduction.html
224 lines (179 loc) · 15.9 KB
/
spatial-data-introduction.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>1 Spatial Data Introduction | spatial-data-introduction.utf8</title>
<meta name="description" content="" />
<meta name="generator" content="bookdown 0.16 and GitBook 2.6.7" />
<meta property="og:title" content="1 Spatial Data Introduction | spatial-data-introduction.utf8" />
<meta property="og:type" content="book" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="1 Spatial Data Introduction | spatial-data-introduction.utf8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li class="chapter" data-level="1" data-path=""><a href="#spatial-data-introduction"><i class="fa fa-check"></i><b>1</b> Spatial Data Introduction</a><ul>
<li class="chapter" data-level="1.1" data-path=""><a href="#SD-spatial-data"><i class="fa fa-check"></i><b>1.1</b> Defining spatial data</a></li>
<li class="chapter" data-level="1.2" data-path=""><a href="#SD-vector-data"><i class="fa fa-check"></i><b>1.2</b> Spatial data formats</a><ul>
<li class="chapter" data-level="1.2.1" data-path=""><a href="#simple-features"><i class="fa fa-check"></i><b>1.2.1</b> Simple features</a></li>
</ul></li>
<li class="chapter" data-level="1.3" data-path=""><a href="#spatial-data-types"><i class="fa fa-check"></i><b>1.3</b> Spatial data types</a></li>
<li class="chapter" data-level="1.4" data-path=""><a href="#SD-crs"><i class="fa fa-check"></i><b>1.4</b> Coordinate Reference System</a></li>
<li class="chapter" data-level="" data-path=""><a href="#SD-appendix"><i class="fa fa-check"></i>Further resources</a></li>
</ul></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./"></a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<!--bookdown:title:end-->
<!--bookdown:title:start-->
<div id="spatial-data-introduction" class="section level1">
<h1><span class="header-section-number">1</span> Spatial Data Introduction</h1>
<div id="SD-spatial-data" class="section level2">
<h2><span class="header-section-number">1.1</span> Defining spatial data</h2>
<p>Spatial data refers to data that contain information about specific locations, and the information content of the data may change with location. In other words, “information” and “location” are two important elements in spatial data. On some occasions, spatial data may only include “location.” But without “location,” the data is no longer spatial anymore. For example, a spatial data that describes the resource distribution of Medications for Opioid Overuse Disorder (MOUDs) must contain <em>and enable</em> location information of these MOUD resources, otherwise the data becomes a non-spatial list of those resources.</p>
<p>For the purpose of this tutorial, we will only briefly introduce some important concepts in spatial data. See <em>Further Resources</em> if you would like to learn more about these concepts.</p>
</div>
<div id="SD-vector-data" class="section level2">
<h2><span class="header-section-number">1.2</span> Spatial data formats</h2>
<p>Spatial data can be stored in a text file like comma-separated value (CSV) files. However, the text file needs to have essential location columns with latitude and longitude to represent the coordinate location of a spatial object. Furthermore, a CSV file with lat/long columns is only a flat/non-spatial file, until the spatial location context is enabled as a new spatial data format.</p>
<p>A common spatial data format is the shapefile, which comes from ESRI/ArcGIS proprietary software. The shapefile file format (.shp for short) includes a minimum of 4 files, with a common prefix and different filename extensions <code>.shp</code>, <code>.shx</code>, <code>.dbf</code>, and <code>.prj</code>. In order to work with the spatial data, we need all these four components of the shapefile stored in the same directory, so that the software (such as R) can know how to project spatial objects onto a geographic or coordinate space (i.e., spatial location context is enabled). Other common spatial data formats include the GeoJSON, KML, and geopackage.</p>
<div id="simple-features" class="section level3">
<h3><span class="header-section-number">1.2.1</span> Simple features</h3>
<p><a href="https://r-spatial.github.io/sf/articles/sf1.html">Simple features</a> refers to an international standard (ISO 19125-1:2004) that describes how real-world objects, and their spatial geometries, are represented in computers. This standard is enabled in ESRI/ArcGIS architecture, POSTGIS (a spatial extension for PostGresSQL), the GDAL libraries that serve as underpinnings to most GIS work, and GeoJSONs. The <code>sf</code> R ecoystem makes simple features even more accessible within R, so that simple feature objects in spatial data are also stored in a data frame, with one vector/column containing geographic data (usually named “geometry” or “geom”).</p>
<p>Why should you care about these computational components of spatial systems architecture? Spatial analysis often requires troubleshooting, and spatial formats can be complicated.</p>
<p>We recommend using the <code>str</code> function in R to familiarize yourself with data objects as you go, and to explore the data files as well. For example: a <code>shapefile</code> includes (at least) four components, separating the data as a <code>.dbf</code> file and projection information as a <code>.prj</code> file. In contrast, the <code>sf</code> spatial file loaded in your R environment is one unified object, has the spatial information recorded as a geometry field, and projection stored as metadata.</p>
</div>
</div>
<div id="spatial-data-types" class="section level2">
<h2><span class="header-section-number">1.3</span> Spatial data types</h2>
<p>Two common formats of spatial data are vector and raster data. Vector data represents the world surface using <strong>points, lines, and polygons</strong> whereas raster data can be satellite imagery or other pixelated surface. The figure below demonstrates how vector and raster data models represent geographic space differently, where points, lines, and polygons consist of the essential basis of the vector data model.</p>
<div class="figure" style="text-align: center"><span id="fig:unnamed-chunk-1"></span>
<img src="img/Vector-and-raster.pbm" alt="[Vector and raster data model in geographic space](https://www.researchgate.net/figure/2-Vector-and-raster-data-model-in-geographic-space_fig3_330468019) [(Jukil & Al-Hadad, 2017)](https://www.researchgate.net/publication/330468019_Highway_Vertical_Alignment_Optimization_Using_Genetic_Algorithm_GA)" />
<p class="caption">
Figure 1.1: <a href="https://www.researchgate.net/figure/2-Vector-and-raster-data-model-in-geographic-space_fig3_330468019">Vector and raster data model in geographic space</a> <a href="https://www.researchgate.net/publication/330468019_Highway_Vertical_Alignment_Optimization_Using_Genetic_Algorithm_GA">(Jukil & Al-Hadad, 2017)</a>
</p>
</div>
<p>We mainly use vector data for our purpose. For example, a group of clinics can be geocoded and converted to points, whereas zip code boundaries are represented as polygons. Note that spatial data types include the basic attributes <em>in addition to</em> their spatial information. So points on a map correspond to associated details for each clinic provider, and may also include fields like “name”, “services”, and more. For example, each park is represented as a green polygon in the figure below. Linked with each park, we can have information regarding their names, sizes, types of plants, open hours, and other various features. These attributes can be stored in a data table, along with their spatial inforamtion, in a <code>shapefile</code>, or a <code>sf</code> spatial file loaded in your R environment.</p>
<div class="figure" style="text-align: center"><span id="fig:unnamed-chunk-2"></span>
<img src="img/park.jpg" alt="[Glasgow park access network](https://www.flickr.com/photos/29266908@N02/8520851663) by [macrofight](https://www.flickr.com/photos/29266908@N02) is under [CC BY-SA 2.0](https://creativecommons.org/licenses/by-sa/2.0/?ref=ccsearch&atype=rich)" />
<p class="caption">
Figure 1.2: <a href="https://www.flickr.com/photos/29266908@N02/8520851663">Glasgow park access network</a> by <a href="https://www.flickr.com/photos/29266908@N02">macrofight</a> is under <a href="https://creativecommons.org/licenses/by-sa/2.0/?ref=ccsearch&atype=rich">CC BY-SA 2.0</a>
</p>
</div>
<p>Read more regarding vector and raster data from <a href="https://geocompr.robinlovelace.net/spatial-class.html#intro-sf">Chapter 2 Geographic data in R</a> of the Lovelace et al 2019 text, <a href="https://geocompr.robinlovelace.net/">Geocomputation with R</a>. This opensource text is an incredible resource for those who are interested in learning more details regarding geographic data analysis, visualization, and modeling, and represents one of dozens of resources available for learning and honing R & spatial analysis skills.</p>
</div>
<div id="SD-crs" class="section level2">
<h2><span class="header-section-number">1.4</span> Coordinate Reference System</h2>
<p>As noted before, the most fundamental element of a spatial data is “location.” A <strong>Coordinate Reference System (CRS)</strong> communicates what method should be used to flatten or project the Earth’s surface onto a 2-dimensional map.</p>
<p>Importantly, different CRS implies different ways of projections and generates substantially different visualizations. For example, following are some world maps using different projections. (Check out <a href="https://futuremaps.com/blogs/news/top-10-world-map-projections">here</a> for more different world map projections.)</p>
<div class="figure"><span id="fig:unnamed-chunk-3"></span>
<img src="img/worldproject1.jpg" alt="[The whole wide world](https://www.flickr.com/photos/34197995@N02/9514590409) by [PeterFisken](https://www.flickr.com/photos/34197995@N02) is under [CC BY 2.0](https://creativecommons.org/licenses/by/2.0/?ref=ccsearch&atype=rich)" />
<p class="caption">
Figure 1.3: <a href="https://www.flickr.com/photos/34197995@N02/9514590409">The whole wide world</a> by <a href="https://www.flickr.com/photos/34197995@N02">PeterFisken</a> is under <a href="https://creativecommons.org/licenses/by/2.0/?ref=ccsearch&atype=rich">CC BY 2.0</a>
</p>
</div>
<div class="figure" style="text-align: center"><span id="fig:unnamed-chunk-4"></span>
<img src="img/worldproject2.jpg" alt="[Peters Projection World Map (35'x51')](https://www.flickr.com/photos/35468141938@N01/3714559813) by [inju](https://www.flickr.com/photos/35468141938@N01) is under [CC BY-NC-SA 2.0](https://creativecommons.org/licenses/by-nc-sa/2.0/?ref=ccsearch&atype=rich)" />
<p class="caption">
Figure 1.4: <a href="https://www.flickr.com/photos/35468141938@N01/3714559813">Peters Projection World Map (35’x51’)</a> by <a href="https://www.flickr.com/photos/35468141938@N01">inju</a> is under <a href="https://creativecommons.org/licenses/by-nc-sa/2.0/?ref=ccsearch&atype=rich">CC BY-NC-SA 2.0</a>
</p>
</div>
<div class="figure"><span id="fig:unnamed-chunk-5"></span>
<img src="img/worldproject3.jpg" alt="[Hammond Cylindrical Projection World Map 1905](https://www.flickr.com/photos/14277117@N03/4775662240) by [perpetualplum](https://www.flickr.com/photos/14277117@N03) is licensed under [CC BY 2.0](https://creativecommons.org/licenses/by/2.0/?ref=ccsearch&atype=rich)" />
<p class="caption">
Figure 1.5: <a href="https://www.flickr.com/photos/14277117@N03/4775662240">Hammond Cylindrical Projection World Map 1905</a> by <a href="https://www.flickr.com/photos/14277117@N03">perpetualplum</a> is licensed under <a href="https://creativecommons.org/licenses/by/2.0/?ref=ccsearch&atype=rich">CC BY 2.0</a>
</p>
</div>
<p>Because different CRS imply different ways of projections and generates substantially different visualizations, it is important to make sure the CRS accompanied with each spatial data are the same before implementing any advanced spatial analysis or geometric processing. In <code>sf</code>, you can use the function <code>st_crs</code> to check the CRS used in one data, and the function <code>st_transform</code> to project the data to a particular CRS. See this <a href="https://spatialanalysis.github.io/workshop-notes/introduction-to-spatial-data.html#interactive-tutorial">Interactive Tutorial</a> that demonstrates these functions.</p>
<p>The CRS concept can be tricky to comprehend and utilize in practice, so we will come back to this several times in our tutorials.</p>
</div>
<div id="SD-appendix" class="section level2 unnumbered">
<h2>Further resources</h2>
<ul>
<li>See <a href="https://geocompr.robinlovelace.net/spatial-class.html">Chapter 2 Geographic data in R in Geocomputation with R</a> for more info about <a href="https://geocompr.robinlovelace.net/spatial-class.html#vector-data">Vector data</a>, <a href="https://geocompr.robinlovelace.net/spatial-class.html#raster-data">Raster data</a>, and <a href="https://geocompr.robinlovelace.net/spatial-class.html#raster-data">Coordiante Reference Systems</a>.</li>
<li>See this <a href="https://datacarpentry.org/organization-geospatial/03-crs/index.html">Software Carpentry workshop</a> for more explanations to better understand coordinate reference systems.</li>
<li>See this <a href="https://spatialanalysis.github.io/workshop-notes/introduction-to-spatial-data.html#interactive-tutorial">Interactive Tutorial</a> that uses <code>sf</code> package to project spatial data in R.</li>
</ul>
</div>
</div>
</section>
</div>
</div>
</div>
</div>
</div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/clipboard.min.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-clipboard.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": true,
"twitter": true,
"linkedin": false,
"weibo": false,
"instapaper": false,
"vk": false,
"all": ["facebook", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"history": {
"link": null,
"text": null
},
"view": {
"link": null,
"text": null
},
"download": null,
"toc": {
"collapse": "section"
},
"search": false
});
});
</script>
</body>
</html>