afredston / spatial_analysis2_R

Focusing on shapefiles and polygons, modifying data attribute tables, and doing simple spatial analysis in R

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

R Spatial Analysis Workshop: Vectors (Polygons and Shapefiles)

Spatial R workshop focusing on reading and using shapefiles and polygon objects directly in R. Examples based on Ocean Health Index - British Columbia.

View the HTML (knitted from the .Rmd): http://eco-data-science.github.io/spatial_analysis2_R/

Setup for workshop

  1. Get the workshop materials: Go to the repository and click on the "fork" button to create an independent copy within your own GitHub account. Alternately, click on the "clone or download" button. https://github.com/eco-data-science/spatial_analysis2_R.
  2. Install the necessary packages:
### Eco-data-science faves! If you don't already have these, get them, they will make your life easier.
  install.packages('dplyr'); install.packages('tidyr'); install.packages('stringr'); install.packages('readr')

### We will do some visualization of maps toward the end with `ggplot2` and `tmap` packages.
  install.packages('ggplot2')
  install.packages('tmap')
  install.packages('RColorBrewer') ### to go along with ggplot - getting better color selection into your plots

### Spatial packages: If you did Jamie's raster workshop, you probably have most of these already, but can't hurt to update.
  install.packages('sp')       ### spatial classes and basic spatial functionality
  install.packages('rgdal')    ### GDAL functionality in R
  install.packages('rgeos')    ### vector spatial analysis tools
  install.packages('raster')   ### raster stuff, but some handy tools that work great for vector spatial data as well
  install.packages('maptools') ### an alternate package with good spatial analysis tools

### Optional: These are for some of the extensions to the workshop - not necessary, but install them if you want to try them out
  install.packages('gdalUtils')    ### this one adds some good GIS-like geospatial processing functionality
  install.packages('cleangeo')     ### this one has functions for checking and cleaning faulty vector spatial data

Note: If you get an error trying to install the rgdal or rgeos packages, you may need to install some libraries outside of R. For the rgdal package (and some of the others) to work properly, you need GDAL (Geospatial Data Abstraction Library) and Proj.4 (projection management) libraries already installed on your laptop. For the rgeos package, you need the GEOS (Geometry Engine Open Source) library installed.

If you don't already have these on your laptop, install them, then go back and do the install.packages('rgdal'), install.packages('rgeos'), etc at your R command line afterward, just to make sure the R packages can access the info from these external libraries.

I'll also show a super-fast demo with QGIS, a free GIS application that works on Mac and does most of the stuff that ArcGIS does. Here's more info on QGIS We will not spend any time on it in the workshop though.

Here's a link to a more in-depth tutorial on using spatial data in R: https://cran.r-project.org/doc/contrib/intro-spatial-rl.pdf

About

Focusing on shapefiles and polygons, modifying data attribute tables, and doing simple spatial analysis in R


Languages

Language:HTML 100.0%