Thank you Michael for taking interest in my problem. Here is the code that should work. The only difference is that here, for a polygon, I use a square instead of a circle (no biggie). I suspect gridDistance may have something to do with the "hexagon".
library(raster) library(sp) rst <- raster(nrow = 200, ncol = 200, xmn = -100, xmx = 100, ymn = -100, ymx = 100, projs = "+proj=NA") sample.matrix <- t(matrix(c(50,-50, 50,50, -50,50, -50,-50), 2, 4)) sample.matrix <- rbind(sample.matrix, sample.matrix[1,]) sq.polygon <- SpatialPolygons(list(Polygons(list(Polygon(sample.matrix)), ID = "effect_dist"))) rst[] <- runif(ncell(rst)) xy <- matrix(c(0,0), 1, 2) rst.poly <- polygonsToRaster(sq.polygon, rst) rst.lines <- linesToRaster(sq.polygon, rst) rst.lines[rst.lines > 0] <- 0 rst.point <- pointsToRaster(rst, xy) rst.cover <- cover(rst.point, rst.lines) rst.grid <- gridDistance(rst.cover) rst.grid[!is.na(rst.lines)] <- NA plot(rst.grid) Cheers, Roman On Tue, Jun 22, 2010 at 9:55 AM, Michael Sumner <mdsum...@gmail.com> wrote: > Could you please provide a reproducible example with useable code? > > Cheers, Mike. > > On Tue, Jun 22, 2010 at 5:36 PM, Roman Luštrik <roman.lust...@gmail.com> > wrote: > > Can someone explain to me why values of distances from a point are not in > a > > uniform, circle-like fashion, but rather form a hexagon shape (see > > image<http://imagepaste.nullnetwork.net/viewimage.php?id=1075>)? > > Here is the code I'm using to produce this plot (kudos to > > Robert< > http://r-sig-geo.2731867.n2.nabble.com/assigning-raster-cell-values-based-on-predefined-criteria-td4929775.html#a4929775 > >). > > Raster projection is "+projs = NA". > > > > rst.poly <- polygonsToRaster(circle.polygon, rst) #circle.polygon is the > > polygon I'm overlaying, rst is the raster > > rst.lines <- linesToRaster(circle.polygon, rst) > > rst.lines[rst.lines > 0] <- 0 > > rst.point <- pointsToRaster(rst, xy[[i]][j,]) #xy is the point from where > > the distances are calculated > > rst.cover <- cover(rst.point, rst.lines) > > rst.grid <- gridDistance(rst.cover) > > rst.grid[!is.na(rst.lines)] <- NA > > plot(rst.grid) > > > > > > Cheers, > > Roman > > > > > > -- > > In God we trust, all others bring data. > > > > [[alternative HTML version deleted]] > > > > _______________________________________________ > > R-sig-Geo mailing list > > R-sig-Geo@stat.math.ethz.ch > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > > -- In God we trust, all others bring data. -- In God we trust, all others bring data. [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo