[R-sig-Geo] How to filter a spatial object in sf

Manuel Spínola m@p|no|@10 @end|ng |rom gm@||@com
Wed Jun 30 18:59:36 CEST 2021


Thank you very much Matt.

Manuel

El mié, 30 jun 2021 a las 9:08, Matt Lewis (<ml807 using cam.ac.uk>) escribió:

> Dear Manuel,
>
> st_filter by default takes .predicate = st_intersects. The 3 polygons you
> filter to are adjacent to five others, so st_filter returns the 3 you want
> and the 5 others which touch too. To avoid this behaviour you can specify
> the .predicate argument to another option like st_within as in:
>
> nc_filter <- st_filter(nc, nc_smaller, .predicate = st_within)
>
> Hope this helps.
>
> All the best,
>
> Matt
>
> On 2021-06-30 16:52, Manuel Spínola wrote:
>
> I would like to retain the information stored in a larger spatial object
> for a subset of features from a smaller spatial object.  I tried a
> st_filter but I cannot achieve my goal.
>
> nc = st_read(system.file("shape/nc.shp", package="sf"))
>
> nc_smaller <- nc %>% filter(CNTY_ID %in% c(1825, 1827, 1828))
>
> nc_filter <- st_filter(nc, nc_smaller)
>
> The nc_smaller has 3 features, but the nc_filter ended with 8 features.  I
> was expecting to have on 3 features in the nc_filter.
>
>
>
> Manuel
>
>
>
>
>
> --
> *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]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>


-- 
*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