Here it is described how to calculate the size of the distribution areas of the species available in the IUCN database.
First the shapefiles of each order must be downloaded from the IUCN page. Here they will be allocated in the “IUCN_range_data” folder.
library(tidyverse)
library(rgdal)
library(rgeos)
library(geosphere)To optimize the effort, we will calculate distribution areas only for the species for which we have the traits we are investigating.
spp<-read.csv("C:/Users/raque/OneDrive - ufpr.br/Doutorado/3ºCap/Data/COMBINE_trait_data_imputed.csv")setwd("C:/Users/raque/OneDrive - ufpr.br/Doutorado/3ºCap/")
dir()
for (i in 1:23){
sf<-readOGR(paste(dir()[13], sep="/",(paste(dir("IUCN_range_data")[i], sep="/", "data_0.shp"))))
n<-paste(dir("IUCN_range_data")[i], sep="_", "data_shape.csv")
write.csv(sf@data, paste("IUCN_range_data_info", sep="/", n))}These 4 orders without species range data have been removed: - Litopterna - Notoryctemorphia - Notoungulata - Sirenia
#Combining all info data in the IUCN shapefile
folder<- "C:/Users/raque/OneDrive - ufpr.br/Doutorado/3ºCap/IUCN_range_data_info"
## csv's must all have identical column names.
filenames <- list.files(folder)
# setwd("C:/Users/raque/OneDrive - ufpr.br/Doutorado/3ºCapIUCN_range_data_info")
# all_files <- Reduce(rbind, lapply(filenames, read.csv))
# write.csv(all_files, "all_IUCN_mamm_information.csv")
### opening it
all_files<- read.csv("C:/Users/raque/OneDrive - ufpr.br/Doutorado/3ºCap/IUCN_range_data_info/all_IUCN_mamm_information.csv")#This are all range type classifications from IUCN:
leg<-as.data.frame(table(all_files$LEGEND))
length(all_files$BINOMIAL)
length(unique(all_files$BINOMIAL))
#we have 5328 species and 11938 features of range.We will take a count the classifications with more than 50 feature between all the species ranges to optimize the codes. After we can calculate the specific species ranges for this specific classifications.
leg<- leg %>% filter (Freq>50)
leg<-data.frame(as.character(leg$Var1))
leg<-rbind("Binomial", leg)
colnames(leg)<-"range_IUCN"We have to be in mind that the range have to be contabilized by each type. So we will bild a table with this 27 columns to calculate the area of all type for all specie.
So, let’s use our table of species names. Once the shapefiles are by order, our function has to calculate ranges by all species in each order using a two steps looping:
## save in: IUCN_range_tables
ord<-data.frame(table(spp$order))
# remove the follow orders (without range data):
ord<- list(ord[-c(13,17,18,28), ]$Var1)
for (j in 25) {
o<- as.character(ord[[1]][j])
spec<- spp %>% filter(order==o)
spec<- as.character(spec$iucn2020_binomial)
#read the shape of the order:
setwd("C:/Users/raque/OneDrive - ufpr.br/Doutorado/3ºCap/IUCN_range_data")
path<-paste(o, "_2021", sep = "")
sha<-readOGR(paste(path, "data_0.shp", sep="/", collapse=NULL))
proj4string(sha) <- "+proj=longlat +datum=WGS84 +no_defs"
rangeSize<-data.frame(matrix(nrow=length(spec), ncol=10))
leg$range_IUCN<- as.character(gsub(' ', '_', leg$range_IUCN))
colnames(rangeSize) <- leg$range_IUCN
for(i in 1:length(spec)){
x <- sha[sha$BINOMIAL == spec[i], ]
rangeSize$Binomial[i]<-spec[i]
try({rangeSize$'Extant_(resident)'[i]<-as.integer(round(gArea(x[x$LEGEND== "Extant (resident)", ])*10000))})
try({rangeSize$'Possibly_Extinct'[i]<-as.integer(round(gArea(x[x$LEGEND== "Possibly Extinct", ])*10000))})
try({rangeSize$'Extinct'[i]<-as.integer(round(gArea(x[x$LEGEND== "Extinct", ])*10000))})
try({rangeSize$'Presence_Uncertain'[i]<-as.integer(round(gArea(x[x$LEGEND== "Presence Uncertain", ])*10000))})
try({rangeSize$'Extant_&_Introduced_(resident)'[i]<-as.integer(round(gArea(x[x$LEGEND== "Extant & Introduced (resident)", ])*10000))})
try({rangeSize$'Extant_&_Origin_Uncertain_(resident)'[i]<-as.integer(round(gArea(x[x$LEGEND== "Extant & Origin Uncertain (resident)", ])*10000))})
try({rangeSize$'Extant_&_Reintroduced_(resident)'[i]<-as.integer(round(gArea(x[x$LEGEND== "Extant & Reintroduced (resident)", ])*10000))})
try({rangeSize$'Possibly_Extant_(resident)'[i]<-as.integer(round(gArea(x[x$LEGEND== "Possibly Extant (resident)", ])*10000))})
try({rangeSize$'Probably_Extant_(resident)'[i]<-as.integer(round(gArea(x[x$LEGEND== "Probably Extant (resident)", ])*10000))})
v<-paste(o, ".csv", sep="")
p<-paste("C:/Users/raque/OneDrive - ufpr.br/Doutorado/3ºCap/IUCN_range_tables", v, sep="/")
write.csv(rangeSize,p)}
}Done.