title: Any efficient way to obtain area estimation with pixel counting approach for land cover raster in R?
body: <p>I want to get area estimation for each polygon by using pixel counting method. The original landcover map was raster data that come with a distinctive class assigned to each pixel (<a href="http://jmp.sh/F6x5pcJhttp://jmp.sh/F6x5pcJ" rel="nofollow noreferrer">landcover map legend</a>). However, to get area estimation by using pixel counting is not intuitive to me. Perhaps, the first things I can do is extract all the pixels for each polygon which present information about the distribution of land cover classes within each polygon. After that, I need to use pixel counting method to get area estimation and aggregate all land/soil coverage for the city, agriculture area for each polygon. For me, using pixel counting to obtain area estimation is not straightforward and don't have a solid idea how to get this done in R.</p>
  
  <p>Note that original landcover map is rather big (about 92<code>mb</code>) and it is difficult to produce reproducible example for landcover raster, so forgive me for such inconveniece. Here is the <code>R</code> script to acquire landcover raster:</p>
  
  <pre><code>library(raster)
  library(R.utils)
  
  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))
  rname &lt;- list.files(getwd(), "tif$")
  land_cover &lt;- raster::raster("~/LUISA_CLC_land_coverage/clc06_r.tif")
  </code></pre>
  
  <p>I want to aggregate all land/soil coverage information for each polygon (total 403 polygon that land cover information to be aggregated); Here are polygons I am gonna use for area estimation:  <a href="http://jmp.sh/Cc3po8v" rel="nofollow noreferrer">shapefile with polygons are available on the fly</a>:</p>
  
  <p><a href="https://i.stack.imgur.com/1E06C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1E06C.png" alt="enter image description here"></a></p>
  
  <p>I cropped original landcover raster as follow:</p>
  
  <pre><code>deu_shp = maptools::readShapePoly("~/adm2.shp",
                                    proj4string=crswgs84,verbose=TRUE)
  deu_proj &lt;- spTransform(deu_shp, CRSobj = land_cover@crs)
  land_cover_deu &lt;- crop(land_cover, deu_proj )
  </code></pre>
  
  <p>To understand area estimation with pixel counting, I googled related article and found this : <a href="https://www.unodc.org/documents/crop-monitoring/Workshop_coca_leaves/Javier_Gallego3.pdf" rel="nofollow noreferrer"> Using remote sensing for crop area estimation</a> and idea that presented in this article is closely match with my interest, but to implement presented method is purely theoretical and hard for me to do it in <code>R</code>. I am quite okay if there is any quick and dirty way to get area estimation with pixel counting where land/soil coverage information (such as city, forest, agricultural land) must be aggregated to each polygon (<a href="http://jmp.sh/Cc3po8v" rel="nofollow noreferrer">shapefile with polygons are available on the fly</a>). </p>
  
  <p>for pixel extraction, I could simply use <code>raster::extract</code> as follow (the code down below is trial):</p>
  
  <pre><code>lapply(deu_proj, function(x) {
      pixel_extract = raster::extract(land_cover_deu, deu_proj[x,])
      pixel_extract= as.data.frame(pixel_extract)
  })
  </code></pre>
  
  <p>and above simple pixel extraction is not very efficient for original land cover raster. I don't know how to make pixel counting for the extracted pixel in each polygon and get corresponding area estimation (such as land coverage of the city, forest, agriculture area and so on).</p>
  
  <p>Any idea to make this happen in R? How can I get area estimation with pixel counting approach for given land cover raster? Is that possible to aggregate land/soil coverage information to each polygon? Thanks in advance</p>