---
title: "Anthromes map"
output: html_document
---

# Anthromes and Myers hotspots {.tabset}

## Anthromes

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,warning = FALSE,message = FALSE)
library(tidyverse)
library(mapview)
library(giscourse)
library(leaflet)
library(leaflet.extras)
countries<-rnaturalearth::ne_countries(returnclass = "sf")[,18]
library(sf)
hotspots<-st_read("hotspots.shp")
# hotspots[st_is_valid(hotspots),] -> hotspots
# hotspots<-st_simplify(hotspots,dT=0.2)
# mapview(hotspots)
# st_write(hotspots,"hotspots.shp")
hp<-mapview(hotspots,zcol="NAME", alpha.regions = 0.2,legend=FALSE)
realm<-st_read("realm.shp")
realm<-st_simplify(realm, dT=1)
ecos<-st_read("Ecoregions2017.shp")
ecos<-st_simplify(ecos,dT=0.06)
```

![](legend3.png){ width=40% }

```{r,fig.width=9}


mapview(countries, alpha.regions = 0,legend=FALSE)@map %>% addFullscreenControl() %>% 
    addWMSTiles(group="Forest 2000",
                "http://r.bournemouth.ac.uk:8083/gis_course/wms",
                layers = "gis_course:forest2000",
                options = WMSTileOptions(format = "image/png", transparent = TRUE)) %>%
    addWMSTiles(group="Forest loss",
                "http://r.bournemouth.ac.uk:8083/gis_course/wms",
                layers = "gis_course:loss",
                options = WMSTileOptions(format = "image/png", transparent = TRUE)) %>%
    addWMSTiles(group="Forest gain",
                "http://r.bournemouth.ac.uk:8083/gis_course/wms",
                layers = "gis_course:gain",
                options = WMSTileOptions(format = "image/png", transparent = TRUE)) %>%      
       addWMSTiles(group="Population Density",
                "https://sedac.ciesin.columbia.edu/geoserver/wms",
                layers = "gpw-v3:gpw-v3-population-density_2000",
                options = WMSTileOptions(format = "image/png", transparent = TRUE)) %>%
  addWMSTiles(group="Anthromes 1700",
                "https://sedac.ciesin.columbia.edu/geoserver/wms",
                layers = "anthromes:anthromes-anthropogenic-biomes-world-v2-1700",
                options = WMSTileOptions(format = "image/png", transparent = TRUE)) %>%
   addWMSTiles(group="Anthromes 2000",
                "https://sedac.ciesin.columbia.edu/geoserver/wms",
                layers = "anthromes:anthromes-anthropogenic-biomes-world-v2-2000",
                options = WMSTileOptions(format = "image/png", transparent = TRUE)) %>%
  addWMSTiles(group="Anthromes 1900",
                "https://sedac.ciesin.columbia.edu/geoserver/wms",
                layers = "anthromes:anthromes-anthropogenic-biomes-world-v2-1900",
                options = WMSTileOptions(format = "image/png", transparent = TRUE)) %>%
   addWMSTiles(group="Anthromes 1800",
                "https://sedac.ciesin.columbia.edu/geoserver/wms",
                layers = "anthromes:anthromes-anthropogenic-biomes-world-v2-1800",
                options = WMSTileOptions(format = "image/png", transparent = TRUE)) %>%
      mapview:::mapViewLayersControl (names = c("Forest 2000",
                                                "Forest loss", 
                                                "Forest gain", 
                                                "Population Density",
                                                "Anthromes 1700",
                                                "Anthromes 1800",
                                                "Anthromes 1900",
                                                "Anthromes 2000")) %>%
                                             hideGroup(c("Forest 2000",
                                                "Forest loss", 
                                                "Forest gain", 
                                                "Population Density",
                                                "Anthromes 1700",
                                                "Anthromes 1800",
                                                "Anthromes 1900"))


```

## Myers hotspots

```{r,fig.width=9}


hp@map %>% addFullscreenControl() %>% addWMSTiles(group="Anthromes 2000",
                "https://sedac.ciesin.columbia.edu/geoserver/wms",
                layers = "anthromes:anthromes-anthropogenic-biomes-world-v2-1800",
                options = WMSTileOptions(format = "image/png", transparent = TRUE)) %>%
  addWMSTiles(group="Ecoregions",
                "http://r.bournemouth.ac.uk:8083/AG/wms",
                layers = "AG:tnc_eco",
                options = WMSTileOptions(format = "image/png", transparent = TRUE)) %>%
      mapview:::mapViewLayersControl (names = c("Anthromes 2000", "Ecoregions")) %>% hideGroup("Ecoregions")
```

## Realms

```{r}
#ecos<-st_read("ecos.shp")
#biomes<-st_read("biomes.shp")

mapview(realm,zol ="REALM", legend=FALSE, alpha.regions = 0.2) 
```

## Biomes

```{r}
#ecos<-st_read("ecos.shp")
#biomes<-st_read("biomes.shp")
#biomes<-st_buffer(biomes,0.01)
#realm<-st_read("realm.shp")
#realm<-st_simplify(realm, dT=1)
#mapview(biomes,zol ="BIOME_NAME", legend=FALSE, alpha.regions = 0.2) 
```




```{r}

#st_write(ecos,"ecos.shp",delete_dsn=TRUE)
# ecos<-st_read("ecos.shp")
#ecos %>% group_by(BIOME_NAME,REALM) %>% summarise(geom=st_union(st_combine(geometry))) -> biome
#biome %>% group_by(REALM) %>% summarise(geom=st_union(geom)) -> realm
# st_write(realm,"realm.shp",delete_dsn=TRUE)
mapview(ecos,zcol="BIOME_NAME",col.regions=unique(ecos$COLOR),legend=FALSE)
```


