filmov
tv
R Tutorial: Reading vector and raster data into R

Показать описание
Welcome to the DataCamp course on Spatial Analysis in R with the SF and raster packages. I am Zev Ross and I am looking forward to introducing you to some powerful and exciting functionality available in R to help you get spatial analysis done smoothly and efficiently.
In this course we will be introducing you to two key packages for spatial analysis, the new sf package for working with vector data and the great raster package for working with grids.
You will learn how to read data, prepare your data for spatial analysis and conduct key spatial tasks for both vector and raster data.
In the last lesson of the course, you will use all of your new skills to perform a mini-analysis looking at trees and greenspace in New York City.
So let's get started with task number 1 in any spatial analysis, reading in data.
For reading data into R I’m going to introduce you to three functions. For vector data all you need is st_read(). For raster data we will talk about the raster() and brick() functions. All three of these functions are flexible in the sense that they can read in a wide range of different data types and they guess the input based on the input data suffix.
For vectors, the st_read() function from the sf package has dramatically simplified reading vector data in R compared with previous approaches. With st_read(), you simply feed a path and the function guesses the type based on the suffix.
With this example you can see how simple it can be. In this case we feed the function the path to a shapefile.
And as I mentioned, st_read() can be used to read in a wide range of spatial types including shapefiles, geojson, gps, netcdf and others.
Examples in this course will focus on reading in shapefiles since they're still the most common vector spatial format. In particular, we'll be using NYC data on trees, neighborhoods and parks.
For raster data, the raster() and brick() functions perform almost identically but are designed to read in different types of rasters. The raster() function reads single-band rasters and brick() reads in multi-band rasters.
So a single-band, also referred to as a single-layer, raster is one that has just a single set of values for each grid cell. Examples would be something like elevation or land use.
Here you can see that for a single-band raster you would use the raster() function.
With multi-band rasters, on the other hand, there may be multiple layers, meaning each grid cell might have multiple values. Examples include satellite images where each band represents ranges of frequencies along the electromagnetic spectrum.
In a "true color" satellite image, an image that looks like a photo, you would have three bands, one each for the red, green and blue bands of light. In order to read in this type of raster you would use the brick function.
Like st_read(), the raster() and brick() functions can read in a wide range of data types and they guess type based on the suffix, in this course you will be reading in geotiffs of NYC, one for tree canopy and one satellite image.
Time to try our reading vector and raster data.