# Quick tour of giscourse R functions

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE, message = FALSE,warning = FALSE,
  comment = "#>"
)
```

## Introduction

The giscourse package contains some quickly typed functions based on the material in the introduction to open source gis course. The package implements a few examples in the course as R functions.

[link to package documentation](http://r.bournemouth.ac.uk:82/books/GIS_course/giscourse/docs/)

The package saves typing out all the lines of code needed to produce some useful maps and allows the functions to be re-run quickly for different sites. 

However, these are all high level functions, with preset defaults. They may not do **exactly** what you want. In this case you can edit and adapt the functions by applying the concepts that are explained throughout  the course. The functions are aimed mainly at simplifying the task of setting up an R GIS environment with some commonly used data layers. 

## Quick map

The simplest way to form a web map is just to type qmap() into the console, or into a code chunk within a markdown document. This will map the bounding box of Bournemouth as a default area. If you type some other text as the input then the function will attempt to geocode the text and zoom to the appropriate place. 

```{r}
library(giscourse)
qmap()

```

Notice that the map can be taken full screen and contains a geocoding serach control. You can use that to test a search for another place name that could be used as the focus for a map.

As you move the mouse over the map you will see the latitude and longitude of the point shown at the top. This is very useful if you want to focus on a point that does not have name. Write down the longitude and latitude for use in a query.

## Adding a WMS

The local geoserver can be used to visualise some layers in WMS format. These layers are only for visualisation and cannot be analysed directly. However WMS layers can be zoomed to any extent without putting strain on the system.

```{r}
qmap("Arne, Dorset") %>% uk_wms()
```

## WMS with query

The geoserver has been set up with sql queries on the priority habitat and landcover layers. So if two key words are provided to the hab_wms() function two wms layers will be added to the quick map.


```{r}
qmap() %>% hab_wms(hab="calc",bhab="Grass")
```


## Deforestation mapping

The package provides quick access to Hansen's analysis of global deforestation.

https://earthenginepartners.appspot.com/science-2013-global-forest

The raw data can be clipped to a site for analysis. The WMS layer provide a visual representation of the raster layer.. 

```{r}
qmap("Sumatra") %>% hansen_wms()
```

## Capturing a polygon or set of points

The package has a function for quickly digitising some geometries from within an interactive R sesssion. Type emap into the console. The results are saved in the database and also returned as an object.

```{r}
conn<-connect()
#mp<-emap()
st_read(conn,"emap") %>% mapview()
disconnect()
```

## More examples from the package

Check the second vignette in the package documentation for more examples.

[link to package documentation](http://r.bournemouth.ac.uk:82/books/GIS_course/giscourse/docs/)

```{r,message=FALSE,results='hide',warning=FALSE,echo=FALSE}
if(exists("conn"))dbDisconnect(conn)
lapply(paste('package:',names(sessionInfo()$otherPkgs),sep=""),detach,character.only=TRUE,unload=TRUE)
rm(list=ls())
```


