# Calculation of fractional cover for each vegetation class at 30-m resolution matching MODIS swath in R

Currently I have a Landsat land cover map with 30-m resolution and I want to calculate the fractional cover for each vegetation class (forests, grasslands and croplands etc.) matching MODIS swath and do a linear regression analysis linking land cover percentage with the corresponding MODIS LST for each 1-km resolution pixel. Therefore, the fractional changes will be calculated by computing at 30m the proportion of each vegetation class (e.g. forest) that occupy each MODIS 1km grid cell.

I hardly found any practical tutorial using R to achieve this.

• Please, edit your question and add what have you tried at the moment. You can achieve this with `extract()` using `weights=T`... But, without your code and file samples we can't do more – aldo_tapia Nov 16 '17 at 10:23

Fractional cover re-sampling can be achieved with the aggregate function. For this you need to make a raster of the relevant class, then aggregate to the sum of these pixels, divided by the total cell count.

The below example is for slightly more than 1km resolution, as 30 m does not divide into 1000 perfectly. If you have many classes this would be more clean as a loop.

``````#load raster
land.cover <-raster("land_cover_map.tif")

#make copy
land.cover.crop <- land.cover

# set the non-target classes to NA
land.cover.crop[land.cover.crop != 1] <- NA

# if the non-target class is not 1, remember to change to value to 1

# sum all values that equal 1, and divide by the total number of pixels that are being aggregated (34*34)
land.cover.crop.cover <- aggregate(x = land.cover.crop,
fact = 34,
fun = function(x, ...)
{ (sum(x == 1, ...)/1156)*100})
``````
• What if I do not have the liberty of changing the resolution from 1km to more or less? How should I proceed then? – Dark_Knight Sep 18 '18 at 5:25