[R-sig-Geo] grid overlay on polylines

Robert J. Hijmans r.hijmans at gmail.com
Mon Nov 25 22:43:32 CET 2013


Lee,
What are you trying the accomplish with this "overlay"? If you want to
do a spatial query (extract grid cell values covered by the line), you
can use raster::extract. If you want to rasterize (create a raster
where the cells covered by the line get a particular value), you can
use raster::rasterize.
Robert

On Mon, Nov 25, 2013 at 1:15 PM,  <ldecola at comcast.net> wrote:
>
> i'm trying to overlay a grid on a SpatialLines object but over() doesn't work, even if i load rgeos...
> --------
> library(sp)
> library(rgeos)
>
> # SPATIAL LINES OBJECT
> tmp_sl <- SpatialLines(
> list(
> Lines(
> list(
> Line(matrix(c(0, 1, 1, 0, 0, 1), 3))
> ),
> ID = 'a'
> )
> )
> )
> plot(tmp_sl, axes = T, col = 'red', lwd = 4)
>
> # SPATIAL GRID TO COVER IT
> res <- 2^-3
> tmp_grd <- SpatialGrid(
> GridTopology(
> bbox(tmp_sl)[, 'min'],
> rep(res, 2),
> round(apply(bbox(tmp_sl), 1, diff) / res + 1)
> )
> )
> plot(tmp_grd, add = T)
>
> # DOESN'T WORK...
> over(tmp_grd, tmp_sl)
> # *** END ***
> --------
>
>
> Lee De Cola, PhD, MCP.
> DATA to Insight
> LDECOLA at COMCAST.NET
> Reston, Virginia
> 703 709 6972
> 571 315 0577 mobile
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list