Message-ID: <CABkCotRqNx3X8C2x=znQm7yX67=0dwn6LogZ8ttDzZyWUPtUbg@mail.gmail.com>
Date: 2023-02-10T21:17:40Z
From: Manuel SpĂnola
Subject: st_intersection produce Geometry type: GEOMETRY instead of Geometry type: POLYGON
In-Reply-To: <8b6e4af8-0fd0-8e33-c352-506d868c8e4c@urjc.es>
Thank you very much Marcelino.
That works.
I also find that this works (with terra):
g_25000_c <- crop(vect(g_25000), vect(g_50000_d))
g_25000_c <- st_as_sf(g_25000_c)
El vie, 10 feb 2023 a las 15:06, Marcelino de la Cruz Rot (<
marcelino.delacruz at urjc.es>) escribi?:
>
> g_25000_c_polygons_only <- g_25000_c[st_is(x = g_25000_c, type =
> "POLYGON"),] # with a comma
>
>
> El 10/02/2023 a las 21:33, Manuel Sp?nola escribi?:
> > Thnak you very much Bede-Fazekas.
> >
> > I got the following error:
> >
> > g_25000_c_polygons_only <- g_25000_c[st_is(x = g_25000_c, type =
> "POLYGON")]
> >
> > Error in `[.data.frame`(x, i) : undefined columns selected
> >
> > El vie, 10 feb 2023 a las 11:53, Bede-Fazekas ?kos (<
> bfalevlist at gmail.com>)
> > escribi?:
> >
> >> Dear Manuel,
> >>
> >> technically, the result of st_intersection(x, y), where both x and y are
> >> POLYGONs, can be POINT, LINESTRING, POLGYON and GEOMETRY as well. The
> >> result is GEOMETRY if the type of the different features is not the same
> >> (e.g. POLYGON+POINT).
> >> You can subset the result in this way:
> >> g_25000_c_polygons_only <- g_25000_c[st_is(x = g_25000_c, type =
> >> "POLYGON")]
> >>
> >> HTH,
> >> ?kos
> >> ___________
> >> ?kos Bede-Fazekas
> >> Centre for Ecological Research, Hungary
> >>
> >> 2023.02.10. 18:32 keltez?ssel, Manuel Sp?nola ?rta:
> >>> Dear list members,
> >>>
> >>> I am trying to "crop" a polygon (grid) with a polygon, but the result
> is
> >> an
> >>> sf object Geometry type: GEOMETRY, instead of an sf object Geometry
> type:
> >>> POLYGON.
> >>>
> >>> How can I obtain an sf POLYGON?
> >>>
> >>> nc = st_read(system.file("shape/nc.shp", package="sf"))
> >>>
> >>>
> >>>
> >>> nc <- st_transform(nc, 3857)
> >>>
> >>>
> >>>
> >>> g_50000 <- st_make_grid(nc, cellsize = 50000) |> st_as_sf()
> >>>
> >>>
> >>>
> >>> g_50000 <- g_50000[nc, ]
> >>>
> >>>
> >>>
> >>> g_50000_d <- st_union(g_50000)
> >>>
> >>>
> >>>
> >>> g_25000 = st_make_grid(g_50000_d, cellsize = 25000) |> st_as_sf()
> >>>
> >>>
> >>>
> >>> g_25000 # Geometry type: POLYGON
> >>>
> >>>
> >>>
> >>> g_25000_c <- st_intersection(g_25000, g_50000_d)
> >>>
> >>>
> >>>
> >>> g_25000_c # Geometry type: GEOMETRY
> >>>
> >>>
> >>>
> >>>
> >> _______________________________________________
> >> R-sig-Geo mailing list
> >> R-sig-Geo at r-project.org
> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >>
> >
>
> --
> Marcelino de la Cruz Rot
> Coordinador funcional de Biolog?a
> Depto. de Biolog?a y Geolog?a
> F?sica y Qu?mica Inorg?nica
> Universidad Rey Juan Carlos
> M?stoles Espa?a
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at 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 at una.cr <mspinola at una.ac.cr>
mspinola10 at gmail.com
Tel?fono: (506) 8706 - 4662
Institutional website: ICOMVIS
<http://www.icomvis.una.ac.cr/index.php/manuel>
Blog sobre Ciencia de Datos: https://mspinola-ciencia-de-datos.netlify.app
[[alternative HTML version deleted]]