Commit 593aed9d authored by Facundo Muñoz's avatar Facundo Muñoz ®️
Browse files

Merge branch 'adopt-geonetwork'

parents 7b9e99f1 720f98bb
Package: mapMCDA
Title: Produce an epidemiological risk map by weighting multiple risk factors
Version: 0.3.2.9000
Version: 0.3.3
Date: 2018-06-27
Authors@R: c(
person("Elena", "Arsevska", email = "elena.arsevska@cirad.fr", role = c("ctb")),
......@@ -22,6 +22,7 @@ Imports:
deldir,
geojsonio,
geojsonlint,
geonetwork,
igraph,
methods,
maps,
......
......@@ -39,6 +39,7 @@ importFrom(igraph,edge_attr_names)
importFrom(igraph,gorder)
importFrom(igraph,graph_from_data_frame)
importFrom(igraph,is.weighted)
importFrom(igraph,vertex.attributes)
importFrom(raster,intersect)
importFrom(rgeos,gUnaryUnion)
importFrom(stats,setNames)
......
# mapMCDA 0.3.0.9000
* Plot geographic networks (#13)
* Export CSV with units and risk categories (#10)
* Animal mobility data as a specific input type (#9)
......
......@@ -113,7 +113,7 @@ must be respected:",
stop("Node(s) ", idx.nodes, " have inconsistent coordinates in the dataset.")
}
ans <- igraph::graph_from_data_frame(e_list, vertices = v_coord, directed = TRUE)
ans <- geonetwork::geonetwork(e_list, v_coord, directed = TRUE)
## If there are edge attributes, it must be only one, and must be
## the weight.
......@@ -125,8 +125,8 @@ must be respected:",
return(ans)
}
# ' @import igraph
setOldClass("igraph")
# ' @import geonetwork
setOldClass("geonetwork")
#' Rasterize a geographic network
......@@ -140,7 +140,7 @@ setOldClass("igraph")
#' If you want the unweighted importance, remove the weight attribute
#' from the graph with \code{igraph::delete_edge_attr(x, "weight")}.
#'
#' @param x a geographic network (a igraph object with node attributes
#' @param x a geographic network (a geonetwork object with node attributes
#' "Lon" and "Lat" in the WGS84 reference system)
#' @param y a Raster* or a SpatialPolygons* object.
#' @param field character. The attribute of the network nodes to be
......@@ -152,13 +152,14 @@ setOldClass("igraph")
#' @param ... Other arguments passed on to
#' \code{\link[raster]{rasterize}}.
#' @importMethodsFrom raster rasterize
#' @importFrom igraph vertex.attributes
#' @importFrom stats setNames
#' @export
#' @name rasterize_geonetwork
#' @rdname rasterize_geonetwork
#' @aliases rasterize,igraph,Raster-method
#' @aliases rasterize,geonetwork,Raster-method
setMethod(
rasterize, c("igraph", "Raster"),
rasterize, c("geonetwork", "Raster"),
{
function(
x, y, field = "importance", ...) {
......@@ -177,7 +178,13 @@ setMethod(
c("name", "importance")
)
nodes <- as.data.frame(igraph::vertex.attributes(x))
nodes <- cbind(
as.data.frame(igraph::vertex.attributes(x)),
setNames(
data.frame(sf::st_coordinates(attr(x, "geom_node"))),
c("Lon", "Lat")
)
)
nodes <- merge(nodes, node_importance, by = "name", all.y=FALSE)
......@@ -198,10 +205,10 @@ setMethod(
#' @param res numeric vector of length 2. Resolution in Lon/Lat of
#' rasterisation.
#' @rdname rasterize_geonetwork
#' @aliases rasterize,igraph,SpatialPolygons-method
#' @aliases rasterize,geonetwork,SpatialPolygons-method
#' @export
setMethod(
rasterize, c("igraph", "SpatialPolygons"),
rasterize, c("geonetwork", "SpatialPolygons"),
{
function (x, y, res = resolution(y, min_ncells = 100), ...) {
......
......@@ -447,8 +447,17 @@ server <- function(input, output, session) {
}
plot(finalLayer[[indRawLay]])
## Plot the epidemiological units lightly in the background
epidUnitLayer <- isolate(curEpidUnitLayer())
if(is.null(epidUnitLayer)) {
addsetting = FALSE
} else {
plot(epidUnitLayer[[indRawLay]], border = "lightgray")
addsetting = TRUE
}
plot(finalLayer[[indRawLay]], add = addsetting)
})
......@@ -715,7 +724,7 @@ server <- function(input, output, session) {
})
##### Render for display of final unit raster ####
##### Render for display of final unit vector ####
output$resultUnitDisplay <- renderPlot({
......
......@@ -3,17 +3,17 @@
\docType{methods}
\name{rasterize_geonetwork}
\alias{rasterize_geonetwork}
\alias{rasterize,igraph,Raster-method}
\alias{rasterize,igraph,SpatialPolygons-method}
\alias{rasterize,geonetwork,Raster-method}
\alias{rasterize,geonetwork,SpatialPolygons-method}
\title{Rasterize a geographic network}
\usage{
\S4method{rasterize}{igraph,Raster}(x, y, field = "importance", ...)
\S4method{rasterize}{geonetwork,Raster}(x, y, field = "importance", ...)
\S4method{rasterize}{igraph,SpatialPolygons}(x, y, res = resolution(y,
min_ncells = 100), ...)
\S4method{rasterize}{geonetwork,SpatialPolygons}(x, y,
res = resolution(y, min_ncells = 100), ...)
}
\arguments{
\item{x}{a geographic network (a igraph object with node attributes
\item{x}{a geographic network (a geonetwork object with node attributes
"Lon" and "Lat" in the WGS84 reference system)}
\item{y}{a Raster* or a SpatialPolygons* object.}
......
......@@ -35,17 +35,12 @@ test_that("load_dir() skips unknnown file formats", {
res <- load_dir(testdata)
test_files <- c("mobility", "points", "points", "raster")
exp_classes <- c("geonetwork", "SpatialPointsDataFrame", "SpatialPointsDataFrame", "RasterLayer")
expect_is(res, "list")
expect_identical(names(res), test_files)
expect_identical(
vapply(res, class, "char")[test_files],
setNames(
c("igraph", "SpatialPointsDataFrame", "SpatialPointsDataFrame", "RasterLayer"),
test_files
)
)
expect_true(all(mapply(inherits, res, exp_classes)))
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment