install.packages(“sf”) install.packages(“rgbif”) install.packages(“dplyr”) install.packages(“httr”) install.packages(“readr”)
library(sf) library(rgbif) library(dplyr) library(httr) library(readr)
kml_url <- “https://www.needs.ufscar.br/limite_alpa.kml” kml_file <- tempfile(fileext = “.kml”)
GET(kml_url, write_disk(kml_file, overwrite = TRUE))
alpa_poly <- st_read(kml_file, quiet = TRUE)
st_crs(alpa_poly)
alpa_poly_wgs84 <- st_transform(alpa_poly, crs = 4326)
alpa_poly_wgs84 <- st_make_valid(alpa_poly_wgs84)
plot(st_geometry(alpa_poly_wgs84), main = “Limite da ALPA”) axis(1) axis(2)
bbox <- st_bbox(alpa_poly_wgs84) bbox
baixar_ocorrencias <- function(classe, bbox, limite = 2000) { occ_search( classKey = name_backbone(name = classe, rank = “class”)\(usageKey, hasCoordinate = TRUE, limit = limite, decimalLatitude = paste0(bbox["ymin"], ",", bbox["ymax"]), decimalLongitude = paste0(bbox["xmin"], ",", bbox["xmax"]) )\)data }
aves <- baixar_ocorrencias(“Aves”, bbox)
anfibios <- baixar_ocorrencias(“Amphibia”, bbox)
nrow(aves)
nrow(anfibios)
aves_sf <- st_as_sf(aves, coords = c(“decimalLongitude”, “decimalLatitude”), crs = 4326) anfibios_sf <- st_as_sf(anfibios, coords = c(“decimalLongitude”, “decimalLatitude”), crs = 4326)
plot(st_geometry(alpa_poly_wgs84), main = “Registros GBIF em ALPA”, col = NA, border = “black”) plot(aves_sf, col = “blue”, pch = 1, add = TRUE) plot(anfibios_sf, col = “green”, pch = 3, add = TRUE) legend(“bottomleft”, legend = c(“Aves”, “Anfíbios”), col = c(“blue”, “green”), pch = c(1, 3))
aves_lista <- aves %>% filter(!is.na(scientificName)) %>% group_by(scientificName, vernacularName, order, family) %>% summarise(n = n(), .groups = “drop”) %>% arrange(desc(n))
anfibios_lista <- anfibios %>% filter(!is.na(scientificName)) %>% group_by(scientificName, vernacularName, order, family) %>% summarise(n = n(), .groups = “drop”) %>% arrange(desc(n))
dir.create(“dados_gbif_alpa”, showWarnings = FALSE)
write_csv(aves_lista, “dados_gbif_alpa/aves_alpa.csv”) write_csv(anfibios_lista, “dados_gbif_alpa/anfibios_alpa.csv”)