Re: [R-sig-Geo] st_intersection produce Geometry type: GEOMETRY instead of Geometry type: POLYGON

2023-02-10 Thread Manuel Spínola
Thank you very much Marcelino.

That works.

I also find that this works (with terra):

g_25000_c <- crop(vect(g_25000), vect(g_5_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.delac...@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 (<
> bfalevl...@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_5 <- st_make_grid(nc, cellsize = 5) |> st_as_sf()
> >>>
> >>>
> >>>
> >>> g_5 <- g_5[nc, ]
> >>>
> >>>
> >>>
> >>> g_5_d <- st_union(g_5)
> >>>
> >>>
> >>>
> >>> g_25000 = st_make_grid(g_5_d, cellsize = 25000) |> st_as_sf()
> >>>
> >>>
> >>>
> >>> g_25000 # Geometry type: POLYGON
> >>>
> >>>
> >>>
> >>> g_25000_c <- st_intersection(g_25000, g_5_d)
> >>>
> >>>
> >>>
> >>> g_25000_c # Geometry type: GEOMETRY
> >>>
> >>>
> >>>
> >>>
> >> ___
> >> R-sig-Geo mailing list
> >> R-sig-Geo@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@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
mspin...@una.cr 
mspinol...@gmail.com
Teléfono: (506) 8706 - 4662
Institutional website: ICOMVIS

Blog sobre Ciencia de Datos: https://mspinola-ciencia-de-datos.netlify.app

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] st_intersection produce Geometry type: GEOMETRY instead of Geometry type: POLYGON

2023-02-10 Thread Marcelino de la Cruz Rot



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 ()
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_5 <- st_make_grid(nc, cellsize = 5) |> st_as_sf()



g_5 <- g_5[nc, ]



g_5_d <- st_union(g_5)



g_25000 = st_make_grid(g_5_d, cellsize = 25000) |> st_as_sf()



g_25000 # Geometry type: POLYGON



g_25000_c <- st_intersection(g_25000, g_5_d)



g_25000_c # Geometry type: GEOMETRY





___
R-sig-Geo mailing list
R-sig-Geo@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@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] st_intersection produce Geometry type: GEOMETRY instead of Geometry type: POLYGON

2023-02-10 Thread Manuel Spínola
Thank you very much Josiah.

If I ran the code you suggested me, How I get the g_25000 object (a grid)?

index <- which(lengths(st_intersects(g_5, nc)) > 0)
plot(st_union(g_5[index,]))



El vie, 10 feb 2023 a las 12:10, Josiah Parry ()
escribió:

> Manuel, I think you're looking for an intersect*s* rather than the
> intersection. Is the following what you're after?
>
>
> nc = st_read(system.file("shape/nc.shp", package="sf"))
> nc <- st_transform(nc, 3857)
> g_5 <- st_make_grid(nc, cellsize = 5) |> st_as_sf()
> g_5 <- g_5[nc, ]
> g_5_d <- st_union(g_5)
> g_25000 = st_make_grid(g_5_d, cellsize = 25000) |> st_as_sf()
> g_25000 # Geometry type: POLYGON
>
> index <- which(lengths(st_intersects(g_5, nc)) > 0)
> plot(st_union(g_5[index,]))
>
> On Fri, Feb 10, 2023 at 12:53 PM Bede-Fazekas Ákos 
> wrote:
>
> > 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_5 <- st_make_grid(nc, cellsize = 5) |> st_as_sf()
> > >
> > >
> > >
> > > g_5 <- g_5[nc, ]
> > >
> > >
> > >
> > > g_5_d <- st_union(g_5)
> > >
> > >
> > >
> > > g_25000 = st_make_grid(g_5_d, cellsize = 25000) |> st_as_sf()
> > >
> > >
> > >
> > > g_25000 # Geometry type: POLYGON
> > >
> > >
> > >
> > > g_25000_c <- st_intersection(g_25000, g_5_d)
> > >
> > >
> > >
> > > g_25000_c # Geometry type: GEOMETRY
> > >
> > >
> > >
> > >
> >
> > ___
> > R-sig-Geo mailing list
> > R-sig-Geo@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
> [[alternative HTML version deleted]]
>
> ___
> R-sig-Geo mailing list
> R-sig-Geo@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
mspin...@una.cr 
mspinol...@gmail.com
Teléfono: (506) 8706 - 4662
Institutional website: ICOMVIS

Blog sobre Ciencia de Datos: https://mspinola-ciencia-de-datos.netlify.app

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] st_intersection produce Geometry type: GEOMETRY instead of Geometry type: POLYGON

2023-02-10 Thread Manuel Spínola
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 ()
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_5 <- st_make_grid(nc, cellsize = 5) |> st_as_sf()
> >
> >
> >
> > g_5 <- g_5[nc, ]
> >
> >
> >
> > g_5_d <- st_union(g_5)
> >
> >
> >
> > g_25000 = st_make_grid(g_5_d, cellsize = 25000) |> st_as_sf()
> >
> >
> >
> > g_25000 # Geometry type: POLYGON
> >
> >
> >
> > g_25000_c <- st_intersection(g_25000, g_5_d)
> >
> >
> >
> > g_25000_c # Geometry type: GEOMETRY
> >
> >
> >
> >
>
> ___
> R-sig-Geo mailing list
> R-sig-Geo@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
mspin...@una.cr 
mspinol...@gmail.com
Teléfono: (506) 8706 - 4662
Institutional website: ICOMVIS

Blog sobre Ciencia de Datos: https://mspinola-ciencia-de-datos.netlify.app

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] st_intersection produce Geometry type: GEOMETRY instead of Geometry type: POLYGON

2023-02-10 Thread Josiah Parry
Manuel, I think you're looking for an intersect*s* rather than the
intersection. Is the following what you're after?


nc = st_read(system.file("shape/nc.shp", package="sf"))
nc <- st_transform(nc, 3857)
g_5 <- st_make_grid(nc, cellsize = 5) |> st_as_sf()
g_5 <- g_5[nc, ]
g_5_d <- st_union(g_5)
g_25000 = st_make_grid(g_5_d, cellsize = 25000) |> st_as_sf()
g_25000 # Geometry type: POLYGON

index <- which(lengths(st_intersects(g_5, nc)) > 0)
plot(st_union(g_5[index,]))

On Fri, Feb 10, 2023 at 12:53 PM Bede-Fazekas Ákos 
wrote:

> 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_5 <- st_make_grid(nc, cellsize = 5) |> st_as_sf()
> >
> >
> >
> > g_5 <- g_5[nc, ]
> >
> >
> >
> > g_5_d <- st_union(g_5)
> >
> >
> >
> > g_25000 = st_make_grid(g_5_d, cellsize = 25000) |> st_as_sf()
> >
> >
> >
> > g_25000 # Geometry type: POLYGON
> >
> >
> >
> > g_25000_c <- st_intersection(g_25000, g_5_d)
> >
> >
> >
> > g_25000_c # Geometry type: GEOMETRY
> >
> >
> >
> >
>
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] st_intersection produce Geometry type: GEOMETRY instead of Geometry type: POLYGON

2023-02-10 Thread Bede-Fazekas Ákos

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_5 <- st_make_grid(nc, cellsize = 5) |> st_as_sf()



g_5 <- g_5[nc, ]



g_5_d <- st_union(g_5)



g_25000 = st_make_grid(g_5_d, cellsize = 25000) |> st_as_sf()



g_25000 # Geometry type: POLYGON



g_25000_c <- st_intersection(g_25000, g_5_d)



g_25000_c # Geometry type: GEOMETRY






___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo