Re: [R-sig-Geo] Spatial nested grid in R

2023-02-10 Thread Marcelino de la Cruz Rot
Dear Manuel, This is R. There is no "it is possible". Only "how" ;-). For example, with spatstat.geom, A <- tess(xgrid=seq(0,80, by=8),ygrid=seq(0,80, by=8)) B <- tess(xgrid=seq(0,80, by=4),ygrid=seq(0,80, by=4)) C <- tess(xgrid=seq(0,80, by=2),ygrid=seq(0,80, by=2)) D <- tess(xgrid=seq(0,80, by

Re: [R-sig-Geo] Spatial nested grid in R

2023-02-10 Thread Manuel Spínola
Thank you very much Marcelino. And how can overimpose those grids to a spatial polygon? Manuel On Fri, 10 Feb 2023 at 03:09 Marcelino de la Cruz Rot < marcelino.delac...@urjc.es> wrote: > Dear Manuel, > This is R. There is no "it is possible". Only "how" ;-). > > For example, with spatstat.geom

Re: [R-sig-Geo] Spatial nested grid in R

2023-02-10 Thread Marcelino de la Cruz Rot
It depends on what you mean by "overimpose". Maybe this way? # some spatial polygon library(maptools) R <- as(affine(letterR, mat=diag(c(20,20))), "SpatialPolygons") plot(R, border="blue") # "overimpose" grids A to C on R: plot(C, border="green", add=T) plot(B, border="red", add=T) plot(A, add=

Re: [R-sig-Geo] Spatial nested grid in R

2023-02-10 Thread Manuel Spínola
Thank you very much Marcelino. Manuel El vie, 10 feb 2023 a las 7:29, Marcelino de la Cruz Rot (< marcelino.delac...@urjc.es>) escribió: > It depends on what you mean by "overimpose". > > Maybe this way? > > # some spatial polygon > library(maptools) > R <- as(affine(letterR, mat=diag(c(20,20)))

Re: [R-sig-Geo] Spatial nested grid in R

2023-02-10 Thread Roger Bivand
On Fri, 10 Feb 2023, Marcelino de la Cruz Rot wrote: It depends on what you mean by "overimpose". Maybe this way? # some spatial polygon Please, in the spirit of the evolving r-spatial package ecosystem (maptools will retire during 2023): library(sf) R <- st_as_sf(affine(letterR, mat=diag

Re: [R-sig-Geo] Spatial nested grid in R

2023-02-10 Thread Manuel Spínola
Thank you very much Roger. Manuel El vie, 10 feb 2023 a las 8:13, Roger Bivand () escribió: > On Fri, 10 Feb 2023, Marcelino de la Cruz Rot wrote: > > > It depends on what you mean by "overimpose". > > > > Maybe this way? > > > > # some spatial polygon > > Please, in the spirit of the evolving r

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

2023-02-10 Thread Manuel Spínola
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

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_2

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

Re: [R-sig-Geo] Spatial nested grid in R

2023-02-10 Thread Marcelino de la Cruz Rot
El 10/02/2023 a las 15:13, Roger Bivand escribió: On Fri, 10 Feb 2023, Marcelino de la Cruz Rot wrote: It depends on what you mean by "overimpose". Maybe this way? # some spatial polygon Please, in the spirit of the evolving r-spatial package ecosystem (maptools will retire during 2023):

[R-sig-Geo] Lo Cape projections in sf and terra

2023-02-10 Thread dave furniss
Hello all I'm struggling with a projection system used by miners in South Africa, the Lo Cape system. I've put together some commented dummy code that I hope illustrates the issues. If someone could give me some guidance on how to convert between this and other crs's, that would be much appreci

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, t

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 int

Re: [R-sig-Geo] Spatial nested grid in R

2023-02-10 Thread Manuel Spínola
Thank you very much Marcelino. Manuel El vie, 10 feb 2023 a las 13:00, Marcelino de la Cruz Rot (< marcelino.delac...@urjc.es>) escribió: > El 10/02/2023 a las 15:13, Roger Bivand escribió: > > On Fri, 10 Feb 2023, Marcelino de la Cruz Rot wrote: > > > >> It depends on what you mean by "overimpo

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

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_o

Re: [R-sig-Geo] Spatial nested grid in R

2023-02-10 Thread Michael Sumner
One way is to write it to a (COG) GeoTIFF with overviews ("pyramid", or zoom levels) - these are pre-calculated copies of the highest resolution data saved as lower resolution versions. Do you want this to generate a set of nested data, or is it more about working with the nested logic? I'm not s

Re: [R-sig-Geo] Spatial nested grid in R

2023-02-10 Thread Michael Sumner
Oh, with a COG you'd also want control over reading a particular level - I'm not sure how well that's supported in the "R spatial" realm but I'll include it in my example, you can always generate VRT to get exactly what you want from terra and friends. Cheers, Mike On Sat, Feb 11, 2023 at 9:36 A

Re: [R-sig-Geo] Lo Cape projections in sf and terra

2023-02-10 Thread Edzer Pebesma
I ran into this a few months ago while preparing for a workshop I gave (online) to SASA22 participants in South Africa: https://edzer.github.io/SASA22/workshop.html If you divide the geometry by -1 (or multiply it by -1) I don't think you can simply set back the CRS to the old value (EPSG:2228

Re: [R-sig-Geo] Spatial nested grid in R

2023-02-10 Thread Manuel Spínola
Thank you very much Michael. My idea is to create a spatial nested grid to conduct spatial surveys for a monitoring protocol. I am thinking to create an 8km, 4km, 2km and 1km nested grids so you can use different tiles according to the desired resolution of species occurrences, landscape metrics,