title: extract raster values with a shapefile in R
body: <p>I am trying to extract the pixel cells of a raster in a shapefile using R.</p>
  <p>I am using the function <code>extract</code> from the package <code>raster</code>.</p>
  <p>The raster is a raster in format .tiff and the shape file is a shapefile with four polygons.</p>
  <p><code>r.vals &lt;- extract(raster,sdata[1,])</code></p>
  <p>I am getting an empty list in <code>r.vals</code></p>
  <p>I think is a problem on projection.</p>
  <p>This is the projection of the raster:</p>
  <pre><code>&gt; show(raster)
  class      : RasterLayer 
  dimensions : 1801, 3600, 6483600  (nrow, ncol, ncell)
  resolution : 0.1, 0.1  (x, y)
  extent     : -0.05, 359.95, -90.05, 90.05  (xmin, xmax, ymin, ymax)
  crs        : +proj=longlat +datum=WGS84 +no_defs 
  source     : 1950_01.tif 
  names      : X1950_01 
  values     : -1.387779e-17, 0.0448938  (min, max)
  </code></pre>
  <p>and this is the projection of the shape:</p>
  <pre><code>&gt; show(sdata)
  Simple feature collection with 4 features and 2 fields
  Geometry type: MULTIPOLYGON
  Dimension:     XY
  Bounding box:  xmin: -113.2154 ymin: 33.26956 xmax: -109.1728 ymax: 35.87181
  Geodetic CRS:  WGS 84
  # A tibble: 4 x 3
    Station      Area_m2                                                                                geometry
      &lt;dbl&gt;        &lt;dbl&gt;                                                                      &lt;MULTIPOLYGON [°]&gt;
  1 9502000 16087018587. (((-109.653 34.10926, -109.6533 34.10926, -109.6533 34.10871, -109.653 34.10871, -10...
  2 9510000 16004291893. (((-112.0876 34.57458, -112.0876 34.57431, -112.0879 34.57431, -112.0879 34.57458, -...
  3 9498500 11107332300. (((-109.653 34.10927, -109.6533 34.10927, -109.6533 34.10871, -109.653 34.10871, -10...
  4 9508500 15216249842. (((-112.0876 34.57459, -112.0876 34.57431, -112.0879 34.57431, -112.0879 34.57459, -...
  </code></pre>
  <p>I tried using the <code>st_transform</code> function from <code>rgdal</code></p>
  <p><code>st_transform(sdata, CRS(projection(raster)))</code></p>
  <p>with the following result</p>
  <pre><code>Simple feature collection with 4 features and 2 fields
  Geometry type: MULTIPOLYGON
  Dimension:     XY
  Bounding box:  xmin: -110 ymin: 33 xmax: -110 ymax: 36
  CRS:           GEOGCRS[&quot;unknown&quot;,
      DATUM[&quot;World Geodetic System 1984&quot;,
          ELLIPSOID[&quot;WGS 84&quot;,6378137,298.257223563,
              LENGTHUNIT[&quot;metre&quot;,1]],
          ID[&quot;EPSG&quot;,6326]],
      PRIMEM[&quot;Greenwich&quot;,0,
          ANGLEUNIT[&quot;degree&quot;,0.0174532925199433],
          ID[&quot;EPSG&quot;,8901]],
      CS[ellipsoidal,2],
          AXIS[&quot;longitude&quot;,east,
              ORDER[1],
              ANGLEUNIT[&quot;degree&quot;,0.0174532925199433,
                  ID[&quot;EPSG&quot;,9122]]],
          AXIS[&quot;latitude&quot;,north,
              ORDER[2],
              ANGLEUNIT[&quot;degree&quot;,0.0174532925199433,
                  ID[&quot;EPSG&quot;,9122]]]]
  # A tibble: 4 x 3
    Station      Area_m2                                                                                geometry
  *   &lt;dbl&gt;        &lt;dbl&gt;                                                                      &lt;MULTIPOLYGON [°]&gt;
  1 9502000 16087018587. (((-110 34, -110 34, -110 34, -110 34, -110 34, -110 34, -110 34, -110 34, -110 34, ...
  2 9510000 16004291893. (((-112 35, -112 35, -112 35, -112 35, -112 35)), ((-112 35, -112 35, -112 35, -112 ...
  3 9498500 11107332300. (((-110 34, -110 34, -110 34, -110 34, -110 34, -110 34, -110 34, -110 34, -110 34, ...
  4 9508500 15216249842. (((-112 35, -112 35, -112 35, -112 35, -112 35)), ((-112 35, -112 35, -112 35, -112 ...
  </code></pre>
  <p>but still <code>r.vals</code> is empty.</p>
  <p>Any idea about what I am doing wrong?</p>