Skip to content

Commit

Permalink
fix #385 - handle missing bos&natuur ha
Browse files Browse the repository at this point in the history
  • Loading branch information
mvarewyck committed Jun 6, 2024
1 parent 9186c0a commit a9d6da8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
14 changes: 9 additions & 5 deletions reporting-grofwild/R/mapFlanders.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ createSpaceData <- function(data, allSpatialData, biotoopData,
tmpData <- biotoopData[, c("regio", areaVariable)]

colnames(tmpData) <- c("NAAM", "AREA")

if (unit == "relativeDekking")
# cut-off at 100ha bos&natuur #385
tmpData$AREA[tmpData$AREA < 1] <- NA

fullData$AREA <- NULL
fullData <- merge(fullData, tmpData)
}
Expand Down Expand Up @@ -210,7 +215,7 @@ createSpaceData <- function(data, allSpatialData, biotoopData,

# unit taken into account
if (grepl("relative", unit))
summaryData2$freq <- summaryData2$freq/summaryData2$AREA
summaryData2$freq <- ifelse(summaryData2$freq == 0, 0, summaryData2$freq/summaryData2$AREA)


# Create group variable
Expand Down Expand Up @@ -366,9 +371,6 @@ mapFlanders <- function(

}


palette <- colorFactor(palette = colorScheme, levels = levels(summaryData$group))

myMap <- leaflet(spatialData) %>%

addPolygons(
Expand All @@ -390,6 +392,7 @@ mapFlanders <- function(
values = if (regionLevel == "WBE_buitengrenzen")
valuesPalette[!is.na(valuesPalette)] else
valuesPalette,
na.label = "bos & natuur < 100ha",
opacity = 0.8,
title = legendText,
layerId = "legend"
Expand Down Expand Up @@ -724,7 +727,7 @@ mapFlandersServer <- function(id, defaultYear, species, currentWbe = reactive(NU
data = geoData(),
allSpatialData = allSpatialData,
biotoopData = if (is.list(biotoopData))
biotoopData[[results$regionLevelLocal()]] else
biotoopData[[regionLevelLocal()]] else
biotoopData,
year = input$year,
species = species(),
Expand Down Expand Up @@ -994,6 +997,7 @@ mapFlandersServer <- function(id, defaultYear, species, currentWbe = reactive(NU
position = input$legend,
pal = palette,
values = valuesPalette,
na.label = "bos & natuur < 100ha",
opacity = 0.8,
title = simpleCap(unitText(), keepNames = FALSE),
layerId = "legend"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ mapFlandersServer(id = "schade",
type = "wildschade",
species = reactive(req(input$schade_species)),
geoData = results$schade_data,
biotoopData = biotoopData,
allSpatialData = spatialData,
sourceChoices = loadMetaSchade()$sources
)
Expand Down
4 changes: 2 additions & 2 deletions reporting-grofwild/tests/testthat/testGrofwild.R
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,10 @@ test_that("The interactive map", {
data = geoData,
allSpatialData = spatialData,
biotoopData = biotoopData[[regionLevel]],
year = 2016,
year = 2007,
species = iSpecies,
regionLevel = regionLevel,
unit = c("absolute", "relative")[2]
unit = c("absolute", "relative", "relativeDekking")[3]
)

if (doPrint) {
Expand Down
7 changes: 5 additions & 2 deletions reporting-grofwild/tests/testthat/testWildschade.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ schadeData <- loadRawData(type = "wildschade")
wildSchadeData <- subset(sf::st_drop_geometry(schadeData),
wildsoort %in% c("Wild zwijn", "Edelhert", "Ree", "Smient")[1])

biotoopData <- loadHabitats()

species <- sort(unique(schadeData$wildsoort))


Expand Down Expand Up @@ -40,11 +42,12 @@ test_that("Number of cases per region level", {
spaceData <- createSpaceData(
data = schadeData,
allSpatialData = spatialData,
biotoopData = biotoopData[[regionLevel]],
year = 2020,
species = iSpecies,
regionLevel = regionLevel,
unit = "absolute",
sourceIndicator = "HVV_Wilder"
unit = c("absolute", "relative", "relativeDekking")[2],
sourceIndicator = c("Hist_PZ_CARMA", "Natuurpunt")
)

if (doPrint) {
Expand Down

0 comments on commit a9d6da8

Please sign in to comment.