How to create a regular grid?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to create a regular grid?

Roberto Patuelli
Dear All,

Maybe a basic question:

How can I create - for simulation purposes - a regular grid (a raster) N by N on which to generate a rook spatial weights matrix (listw or nb object)?

I actually only need to obtain the listw/nb object for such regular grid.

It feels like this is very simple, but somehow I'm stuck.

Thanks
Roberto

********************
Roberto Patuelli, Ph.D.
Department of Economics
University of Bologna
Rimini campus
Italy

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: How to create a regular grid?

Barry Rowlingson
`cell2nb` in spdep will do exactly that:

 library(sp)
 library(spdep)
 plot(cell2nb(5,5),coords=expand.grid(1:5,1:5))

If you want the points as sp class objects, feed SpatialPoints from
expand.grid:

pts = sp::SpatialPoints(expand.grid(x=1:N,y=1:N))

Barry


On Wed, Apr 11, 2018 at 4:31 PM, Roberto Patuelli <[hidden email]
> wrote:

> Dear All,
>
> Maybe a basic question:
>
> How can I create - for simulation purposes - a regular grid (a raster) N
> by N on which to generate a rook spatial weights matrix (listw or nb
> object)?
>
> I actually only need to obtain the listw/nb object for such regular grid.
>
> It feels like this is very simple, but somehow I'm stuck.
>
> Thanks
> Roberto
>
> ********************
> Roberto Patuelli, Ph.D.
> Department of Economics
> University of Bologna
> Rimini campus
> Italy
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo