comparison map_geographical_coverage.R @ 0:4a468c0c2260 draft default tip

planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/main/tools-ecology/tools/make_data_paper_sketches commit 34f4e0604adc2a2ba4902ce6b8e6df2460eda292
author ecology
date Tue, 15 Oct 2024 20:33:32 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4a468c0c2260
1 #From https://github.com/TanguyGen/metaCure/blob/main/R/eml_down.R
2 #Modified by Seguineau Pauline (2024-10-15)
3 library(dplyr)
4 library(xslt)
5 library(xml2)
6 library(mapview)
7 library(leaflet)
8
9 args = commandArgs(trailingOnly=TRUE)
10 if (length(args)==0)
11 {
12 stop("This tool needs at least one argument")
13 }else{
14 data <- args[1]
15 }
16
17 #' map_geographical_coverage
18 #'Make a map from EML
19 #' @param eml Metadata using EML standard in XML format
20 #'
21 #' @return A map
22 #' @export
23
24 map_geographical_coverage <- function(eml){
25 name <- xml2::xml_find_all(eml, "//geographicCoverage/geographicDescription")
26 name <- unlist(xml2::as_list(name))
27
28 west <- xml2::xml_find_all(eml, "//geographicCoverage/boundingCoordinates/westBoundingCoordinate")
29 west <- as.numeric(unlist(xml2::as_list(west)))
30
31 east <- xml2::xml_find_all(eml, "//geographicCoverage/boundingCoordinates/eastBoundingCoordinate")
32 east <- as.numeric(unlist(xml2::as_list(east)))
33
34 north <- xml2::xml_find_all(eml, "//geographicCoverage/boundingCoordinates/northBoundingCoordinate")
35 north <- as.numeric(unlist(xml2::as_list(north)))
36
37 south <- xml2::xml_find_all(eml, "//geographicCoverage/boundingCoordinates/southBoundingCoordinate")
38 south <- as.numeric(unlist(xml2::as_list(south)))
39
40 geo_info <- data.frame(name = name, west = west, east = east, south = south, north = north)
41
42 map <- leaflet(geo_info) %>%
43 addProviderTiles("CartoDB.Positron")
44
45 for (i in 1:nrow(geo_info)) {
46 if (geo_info$west[i]==geo_info$east[i] && geo_info$south[i]==geo_info$north[i]){
47 map <- map %>% addCircles(lng = geo_info$west[i] , lat= geo_info$south[i], fillColor = "transparent" ) %>% addScaleBar()}
48
49 else if(geo_info$west[i]!=geo_info$east[i] && geo_info$south[i]!=geo_info$north[i]){
50 map <- map %>% addRectangles(lng1 = geo_info$west[i], lat1 = geo_info$south[i],
51 lng2 = geo_info$east[i], lat2 = geo_info$north[i], fillColor = "transparent") %>% addScaleBar()}
52 }
53 mapview::mapshot(map, file = "map.png",remove_controls = c("zoomControl", "layersControl", "homeButton","drawToolbar", "easyButton"))
54 }
55
56 doc <- read_xml(data)
57
58 if (is.na(xml2::xml_find_first(doc, "//geographicCoverage"))){
59 mes = "No geographic coverage found, skipping geographic coverage step."
60 mes
61 }else{
62 map_geographical_coverage(doc)
63 }
64