title: Retain only two-dimensional components in sf data.frame
body: <p>I have a similar setup as in <a href="https://stackoverflow.com/questions/45723775/how-to-select-certain-geometries-from-a-geometrycollection-after-st-intersect">this question</a>. In my case, however, I've got an <code>sf</code> data.frame that contains a mix of different geometry types, some <code>POLYGON</code>s, some <code>GEOMETRYCOLLECTION</code>s like so:</p>
  
  <pre><code>a &lt;- st_polygon(list(cbind(c(0,0,7.5,7.5,0),c(0,-1,-1,0,0))))
  b &lt;- st_polygon(list(cbind(c(0,1,2,3,4,5,6,7,7,0),c(1,0,.5,0,0,0.5,-0.5,-0.5,1,1))))
  i &lt;- st_intersection(a,b)
  
  a1 &lt;- st_sf(a=1, geom = st_sfc(i))
  a2 &lt;- st_sf(a=2, geom = st_sfc(a))
  
  ii &lt;- rbind(a1, a2)
  </code></pre>
  
  <p>As in the question referenced above, what I would like is to retain only those parts of the <code>GEOMETRYCOLLECTION</code> that are two-dimensional as ultimately I'm interested in the areas of these geometries and <code>st_area()</code> won't work on <code>GEOMETRYCOLLECTION</code>s.</p>
  
  <p>In the case of mixed geometries, however, the answer given</p>
  
  <pre><code>st_cast(ii)[which(st_is(st_cast(ii), c("POLYGON", "MULTIPOLYGON"))),]
  </code></pre>
  
  <p>doesn't work as the <code>st_cast()</code> leaves the <code>GEOMETRYCOLLECTION</code> untouched.</p>