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

Marcelino de la Cruz Rot m@rce||no@de|@cruz @end|ng |rom urjc@e@
Fri Feb 10 20:00:19 CET 2023


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):
>
> library(sf)
> R <- st_as_sf(affine(letterR, mat=diag(c(20,20))))
> plot(R, border="blue")
>
> See https://r-spatial.org/r/2022/12/14/evolution2.html, maybe 
> https://rsbivand.github.io/csds_jan23/bivand_csds_ssg_230117.pdf and 
> https://www.youtube.com/watch?v=TlpjIqTPMCA&list=PLzREt6r1NenmWEidssmLm-VO_YmAh4pq9&index=1
>
> Roger

Thank you Roger!

In the spirit of the evolving, I then suggest this to Manuel:

# define this function (if it is not in your  version of sf)

st_as_sf.tess <- sf:::st_as_sf.owin

# transform tesselations in sf's

Dsf <-  st_as_sf(D)
Csf <-  st_as_sf(C)
Bsf <- st_as_sf(B)
Asf <- st_as_sf(A)

# crop tesselations with spatial polygon

RDsf <- Dsf[R,]
RCsf <- Csf[R,]
RBsf <- Bsf[R,]
RAsf <- Asf[R,]

#overimpose cropped grids
plot(RAsf)
plot(RDsf, border="green", add=T)
plot(RCsf, border="blue", add=T)
plot(RBsf, border="red", add=T)
plot(RAsf, add=T)

Cheers,

Marcelino







>
>> 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=T)
>>
>> Cheers,
>> Marcelino
>>
>>
>>
>> El 10/02/2023 a las 13:29, Manuel Spínola escribió:
>>>  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.delacruz using urjc.es> wrote:
>>>
>>>      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=1),ygrid=seq(0,80, by=1))
>>>
>>>      Cheers,
>>>      Marcelino
>>>
>>>
>>>      El 10/02/2023 a las 0:21, Manuel Spínola escribió:
>>>     >  Dear list members,
>>>     >
>>>     >  Is it possible to generate a spatial nested grid in R?
>>>     >
>>>     >  For example, a grid of several 8km x 8km tiles, and within that
>>>      grid, I
>>>     >  want 4 tiles of 4km x 4km, and in each of those I want 4 tiles
>>>      of 2km x
>>>     >  2km, and in each of those I want 4 tiles of 1km x 1km.
>>>     >
>>>     >  Manuel
>>>     >
>>>      --
>>>      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 using r-project.org
>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&data=05%7C01%7CRoger.Bivand%40nhh.no%7C0b29de36aca54242ddf008db0b6ade31%7C33a15b2f849941998d56f20b5aa91af2%7C0%7C0%7C638116325854200214%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Ngv4yEcnP6JM4zq5rpVgzcYgRHAFwPPS8JRFhMaRA58%3D&reserved=0
>>>
>>>  --
>>>  *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 <mailto:mspinola using una.ac.cr>
>>>  mspinola10 using gmail.com
>>>  Teléfono: (506) 8706 - 4662
>>>  Institutional website: ICOMVIS
>>>  <https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.icomvis.una.ac.cr%2Findex.php%2Fmanuel&data=05%7C01%7CRoger.Bivand%40nhh.no%7C0b29de36aca54242ddf008db0b6ade31%7C33a15b2f849941998d56f20b5aa91af2%7C0%7C0%7C638116325854200214%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fCKSKsYuj7JXD5CbsQDKFUkeAVpqekVl%2BbTYM2dpuzU%3D&reserved=0> 
>>>
>>>  Blog sobre Ciencia de Datos:
>>>  https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmspinola-ciencia-de-datos.netlify.app%2F&data=05%7C01%7CRoger.Bivand%40nhh.no%7C0b29de36aca54242ddf008db0b6ade31%7C33a15b2f849941998d56f20b5aa91af2%7C0%7C0%7C638116325854200214%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=cVcjfP2hgnbfK%2BZCrCGFi4HhnQjGEWtx8zeJ%2BjBZDtE%3D&reserved=0 
>>>
>>
>>
>>
>

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



More information about the R-sig-Geo mailing list