[R-sig-Geo] How to avoid that st_intersection drop the empty polygons that do not intersect the other layer?

Manuel Spínola m@p|no|@10 @end|ng |rom gm@||@com
Wed Jun 23 23:03:34 CEST 2021


Dear list members,

I am trying to calculate the road density in a grid of hexagons.

roads_hex <- st_intersection(vias, hex_cr_dm) %>%
  dplyr::mutate(len_m = sf::st_length(geom)) %>% # Find the length of each
line
  dplyr::group_by(hexagono) %>% # Here you need to insert all the columns
from your shapes
  dplyr::summarize(len_m = sum(len_m))

but the grid has 613 features and the final object has 556 because some of
the hexagons do not have roads inside.

How can I keep the 615 hexagons in the final object even those one having a
value of 0 road?


-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola using una.cr <mspinola using una.ac.cr>
mspinola10 using gmail.com
Teléfono: (506) 8706 - 4662
Personal website: Lobito de río <https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list