3

I have land coverage raster data that downloaded from JRC data catalogue (JRC website and JRC land coverage data download link), where data file like shapefiles at a very high degree of resolution, with information of land/soil coverage, for example, information on agricultural land coverage, information about mountain, city coverage and so on. I want to extract all information on agricultural and city land coverage only for Germany and render them in my final output as csv or xlsx format.

However, I tried to read those data in R by using raster::stack function and I intend to crop the raster of only Germany. I got some idea from SO community (useful post), Using Jeffrey Evans' solution, here is runnable R code down below:

url = "https://cidportal.jrc.ec.europa.eu/ftp/jrc-opendata/LUISA/PrimaryOutput/Europe/REF-2014/JRC_LUISA_Input_Corine_land_cover_2006_r_ref_2014.zip"
download.file(url, basename(url))
gunzip(basename(url))    # got some problem to unzip the file in R; better to use decompress the file in local site
tifDat <- list.files(getwd(), "tif$")     # tif file was located in two nested folder
land_cover = raster::stack(tifDat[1])

I plotted this tif format raster in R down below:

plot(land_cover)

enter image description here

My goal is I want to crop this raster only for land coverage of Germany, so I did approximate projection in R, here is the possible R code I could give it try down below:

germany_territory <- readOGR("germany_landCover",layer="germany_landCover")     # read Germany NUTS3 level polygon (by district level)
proj <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84  +towgs84=0,0,0"
proj_raster_landcover <- projectRaster(land_cover, crs =  proj)

germany_landCover_city <- extract(x = proj_raster_landcover,                         y = germany_territory)

but these don't work for me, so I also tried something like this down below:

data(wrld_simpl)
germany <- wrld_simpl[wrld_simpl@data$NAME == "Germany",]
ex_deu <- extent(raster::area(land_cover))
germany_land <- crop(land_cover, ex_deu)

still can't achieve what I want.

desired output:

in cropped raster, I want a plot something like this down below:

enter image description here

I want to extract all information on agricultural and city land coverage only for Germany and render them in my final output as csv or xlsx format.

How can I easily deal with TIFF format raster in R?

How can I correctly crop the land coverage for Germany?

Any way to make this happen easily?

How can I correct my implementation on above?

Any more thoughts?

  • I don't recommend you to project raster. Is better to project shapefile to raster CRS. – aldo_tapia Apr 26 '18 at 18:00
  • @aldo_tapia Thanks for your help. For extracted raster grid, I want to extract all information on agricultural and city land coverage only for Germany in tabular data (csv or xlsx). How can I make this extraction easily in R? – datageek Apr 26 '18 at 19:12
  • @aldo_tapia you mean something like this: as.data.frame(germany_land, xy=TRUE) ? I intend extract all information of agricultural and city land coverage in csv or xlsx. Could you correct me please? How can I get extraction that I specified above? Thank you very much – datageek Apr 26 '18 at 20:30
  • Yes, convert raster to data.frame and then select only values related to desired classes (check LUISA_legend.xlsx) with something like df[df$value %in% c(1,2,3....),] and write it in a .csv file – aldo_tapia Apr 27 '18 at 11:09
4

As I mentioned you in commentaries, project shapefile:

data(wrld_simpl)
germany <- wrld_simpl[wrld_simpl@data$NAME == "Germany",]
germany <- spTransform(germany, CRSobj = land_cover@crs)
germany_land <- crop(land_cover, germany)

plot(germany_land)
plot(germany, add=T)

enter image description here

You can also mask pixels outside Germany with germany_land <- mask(crop(land_cover, germany), germany), but with wrld_simpl data is not recommended (is a very coarse scale).

  • Use as.data.frame(germany_land), you can add xy = TRUE as argument to get coordinates – aldo_tapia Apr 26 '18 at 19:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.