library(stringr)
# Define paths
<- paste0(prefix,"Greenness/2024_NDVI/KI_Leverans/Sverige/")
path_to_tif <- paste0(prefix,"Greenness/2024_NDVI/KI_Leverans/Sverige/clipped")
path_to_cropped <- '267423.03 6572635.216 483482.1955 6243554.671'
cropped_coordinates <-seq(2018,2023)
target_year
# List all .tif files in the directory
<- list.files(path_to_tif, pattern = "\\.tif$", full.names = TRUE)
all_tif_files
# Extract years from filenames
<- unique(str_extract(basename(all_tif_files), "\\d{4}"))
years <- na.omit(as.numeric(years)) # Ensure numeric values
years
#keep only years overlapping with target years
<-years[years %in% target_year]
years
for (year in years) {
# year<-2018
# Filter files for the specific year as "2018-median"
<- all_tif_files[str_detect(basename(all_tif_files), paste0(year, "-median"))]
year_files
for (file in year_files) {
# file<-year_files[1]
# Define output file path as original file and _clipped as postfix
<- file.path(path_to_cropped, str_replace(basename(file), ".tif", "_clipped.tif"))
output_file
<- paste0(
cmd "cmd.exe /c \"C:\\OSGeo4W\\OSGeo4W.bat && gdal_calc.bat ",
paste0(" --overwrit -A ", shQuote(file), " --A_band 1"),
" --calc=\"A\"",
" --format=GTiff",
" --projwin ", cropped_coordinates,
" --type=Int16",
" --NoDataValue=-9999",
" --outfile=\"", output_file, "\""
)
system(cmd, intern = TRUE)
} }
GIND-VGH NDVI/EVI Assessment
Overview
GIND-VGH – Greenness INdex for DVI in Västra Götaland & Halland
GIND-VGH is a regional study aimed at assessing NDVI/EVI greenness data for Västra Götaland and Halland to support environmental and epidemiological research. The project involves processing geospatial data, extracting vegetation indices, and integrating them into various analytical frameworks. The assessment leverages Normalized Difference Vegetation Index (NDVI) data to quantify greenness at multiple spatial levels and ensure consistency in exposure metrics over time.
Data Processing and Preparation
The study utilizes NDVI/EVI raster data spanning multiple years, with processing conducted using QGIS and GDAL commands. The data is extracted for relevant regions, clipped to specific extents, and aggregated over multi-year periods to provide stable exposure estimates.
Each raster is processed within its respective folder, and the clipped outputs are saved in a designated subfolder corresponding to the project title.
Batch Processing of Multiple Raster Files
To process NDVI data across multiple years and generate aggregated outputs within R: