-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmap_biomes.Rmd
More file actions
107 lines (84 loc) · 3.41 KB
/
Copy pathmap_biomes.Rmd
File metadata and controls
107 lines (84 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
title: "Mapping to biomes"
author: "Beni Stocker"
date: "5/14/2020"
output: html_document
---
```{r setup, include=FALSE}
library(sf)
library(rgdal)
library(sp)
library(raster)
library(rgeos)
library(XML)
source("R/get_ecoregions.R")
```
## Read Ecoregions
Following https://stackoverflow.com/questions/34272309/extract-shapefile-value-to-point-with-r
```{r}
shape <- shapefile("~/data/biomes/wwf_ecoregions/data/commondata/data0/wwf_terr_ecos.shp")
head(shape)
plot(shape[shape$BIOME == 10, ], axes = TRUE)
pts <- SpatialPoints(cbind(7, 46),
proj4string = CRS(proj4string(shape)))
over(pts, shape)
```
Using nice function found on internet ;-)
```{r}
out <- get_ecoregions(8.561630, 47.394666, var.extract = 'eco_code')
```
Or some other code I found: (https://github.com/azizka/speciesgeocodeR/blob/master/R/WwfLoad.R)
```{r}
x <- "~/data/biomes/"
download.file("http://assets.worldwildlife.org/publications/15/files/original/official_teow.zip",
destfile = file.path(x, "wwf_ecoregions.zip"))
unzip(file.path(x, "wwf_ecoregions.zip"), exdir = file.path(x, "WWF_ecoregions"))
file.remove(file.path(x, "wwf_ecoregions.zip"))
## this works too
wwf <- readOGR(dsn = "~/data/biomes/wwf_ecoregions/official/",
layer = "wwf_terr_ecos")
geo.proj <- proj4string(wwf)
# create SpatialPoints object for plots
pts <- sp::SpatialPoints(cbind(c(8.561630, 9.561630), c(47.394666, 47.394666)), proj4string = CRS(geo.proj))
# creates object that assigns each plot index to an ecoregion
out_ecoregion <- over(pts, wwf)
print(out_ecoregion)
## get meta info (can't make sense of it)
result <- xmlParse(file = "~/data/biomes/wwf_ecoregions/metadata/metadata1.xml")
result # For a description of each Global 200 biome (1-14), see BIOME.</attrdef>
xmldataframe <- xmlToDataFrame("~/data/biomes/wwf_ecoregions/metadata/metadata1.xml")
## biome description is given here: http://omap.africanmarineatlas.org/BIOSPHERE/data/note_areas_sp/Ecoregions_Ecosystems/WWF_Ecoregions/WWFecoregions.htm
# BIOME (Formally known as Major Habitat Types or MHTs) - Broad kinds of ecoregions that:
# a) Experience comparable climatic regimes;
# b) Have similar vegetation structure;
# c) Display similar spatial patterns of biodiversity; and
# d) Contain flora and fauna with similar guild structures and life histories.
# e) Similar minimum requirements and thresholds for maintaining certain biodiversity features.
# f) Have similar sensitivities to human disturbance.
#
# There are 14 terrestrial biomes. Each biome is given a number (1-14) shown below:
# 1 = Tropical & Subtropical Moist Broadleaf Forests
# 2 = Tropical & Subtropical Dry Broadleaf Forests
# 3 = Tropical & Subtropical Coniferous Forests
# 4 = Temperate Broadleaf & Mixed Forests
# 5 = Temperate Conifer Forests
# 6 = Boreal Forests/Taiga
# 7 = Tropical & Subtropical Grasslands, Savannas & Shrublands
# 8 = Temperate Grasslands, Savannas & Shrublands
# 9 = Flooded Grasslands & Savannas
# 10 = Montane Grasslands & Shrublands
# 11 = Tundra
# 12 = Mediterranean Forests, Woodlands & Scrub
# 13 = Deserts & Xeric Shrublands
# 14 = Mangroves
```
Using sf library:
```{r}
shp_biome_wwf <- st_read('~/data/biomes/wwf_ecoregions/data/commondata/data0/')
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.