-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,82 @@ | ||
## Import Data | ||
|
||
In ArcGIS, you add a new dataset to your project using the "Add Data" button in the "Map" Pane. | ||
In ArcGIS, you add a new dataset to your project using the "Add Data" button in the "Map" Pane. ArcGIS then helps you in various ways that `R` will not. For example, Arc GIS: | ||
|
||
- ... only displays files with extensions that can contain geodata (e.g. `.tif`, `.shp` etc) | ||
- ... recognizes files that come in a multifile format with a common prefix (e.g. shapefiles) and displays it as a single dataset | ||
- ... let's you visually examine the content of .gdb-files | ||
- ... displays the datatype / geometrytype of a dataset as a little icon | ||
- ... automatically uses the correct mechanims to import a dataset <!-- (so you dont have to care whether it is raster, vector, multiband or singleband format) --> | ||
|
||
`R` provides less help when importing a dataset which can be seen as a disadvantage, but in many cases is much more preferable. `R` interferes less and asssums that you have good knowledge of the data you want to import. You probabbly know how to import datasets in `R` using `read.csv`, `read.delim` and so on. | ||
|
||
Similarly, importing geodata into R requires specific functions depending on the dataset, and sometimes specific arguments depending on the characteristics of you dataset. For example, if you want to import a shapefile into R, you need to load the `sf` package and then use the function `read_sf()`: | ||
|
||
```{r} | ||
library(sf) | ||
ARE_waedenswil <- read_sf("sample_data/Entsorgung_Waedenswil/ARE_waedenswil.shp") | ||
ARE_waedenswil | ||
``` | ||
|
||
The `sf` package is a fairly new but amazing package to help us work with vector data. It goes far beyond importing shapefiles, as you will see in later chapters of this book. Much of the beauty in `sf` comes from it's simplicity: As you see from importing the shapefile, it is very much like a `data.frame`, a structure that you are probabbly know very well. In fact, it *is* a data.frame, as you can see here: | ||
|
||
```{r} | ||
is.data.frame(ARE_waedenswil) | ||
``` | ||
|
||
`sf` provides methods for various generics, e.g. you can use `plot()` on the object for a simple visualisation. | ||
|
||
```{r} | ||
plot(ARE_waedenswil) | ||
``` | ||
|
||
|
||
|
||
To import raster data, we need a different packge. The package `raster` is in the process of being replaced by a successor "`terra`". | ||
|
||
```{r} | ||
library(raster) | ||
dhm_200 <- raster("sample_data/Raster/dhm_200.tif") | ||
dhm_200 | ||
``` | ||
|
||
|
||
```{r} | ||
class(dhm_200) | ||
``` | ||
|
||
`RaysterLayer`s also come with a plot method to visualize the dataset spatially: | ||
|
||
```{r} | ||
plot(dhm_200) | ||
``` | ||
|
||
|
||
|
||
@todo add terra method to import rasters | ||
|
||
@todo add method for rasters with multiple layers | ||
|
||
```{r} | ||
# path_1b <- "sample_data/SMR_Musterdaten/SMR50_LV95_KOMB_Mosaic.tif" | ||
# path_3b <- "sample_data/SMR_Musterdaten/SMR50_LV95_KREL_10L_Mosaic.tif" | ||
# | ||
# raster(path_1b) | ||
# raster(path_3b) | ||
``` | ||
|
||
|
||
|
||
As you can see in the output of `raster(path_3b)`, only one of the 3 bands was imported with `raster::raster`. In the case of multiband rasters, it's better to use `raster::brick`: | ||
|
||
```{r} | ||
# smr50_komb_mosaic <- raster(path_1b) | ||
# smr50_krel_mosaic <- brick(path_3b) | ||
``` |