Re: [R-sig-Geo] assigning raster cell values based on predefined criteria

2010-04-23 Thread Roman Luštrik
Thank you Marcelino and Robert for your valuable input. It was helpful. Marcelino, your solution seems to resolve the issue, however I find Robert's suggestion "easier" (more compliant with the existing code I already have). What I would like to add to the discussion is that I set the projection o

Re: [R-sig-Geo] assigning raster cell values based on predefined criteria

2010-04-22 Thread Robert J. Hijmans
I suspect this is because the raster you are using has a longitude/latitude CRS. This is the default if you create it using raster() -- I may change that. Set it to NA (or to what it really is) projection(r) <- NA And try again... Robert The picture suggest that you are not computing the dis

Re: [R-sig-Geo] assigning raster cell values based on predefined criteria

2010-04-22 Thread Marcelino de la Cruz
Sorry, that was the distance to the border of the polygon. For the distance to the centroid: # A example of polygon: ho_sp <- SpatialPolygons(list(Polygons(list(Polygon(cbind(c(0,1,1,0,0), c(0,0,1,1,0, ID="ho"))) ho.win <- as(ho_sp,"owin") centroide <- centroid.owin(ho.win) h2.ppp<

Re: [R-sig-Geo] assigning raster cell values based on predefined criteria

2010-04-22 Thread Marcelino de la Cruz
How about this?: library(spatstat) library(maptools) # A example of polygon: ho_sp <- SpatialPolygons(list(Polygons(list(Polygon(cbind(c(0,1,1,0,0), c(0,0,1,1,0, ID="ho"))) plot(ho_sp) ho.win <- as(ho_sp,"owin") ho.mask <- as.mask(ho.win) ho.dist<-bdist.pixels(ho.mask) plot(ho.dist) h

Re: [R-sig-Geo] assigning raster cell values based on predefined criteria

2010-04-22 Thread Roman Luštrik
This is the normal behavior (see image here) when I use option A-ish (calculating distance to a single point). Intuitively, however, I would expect the plot to look something like this (crudely drawn for your amusement

Re: [R-sig-Geo] assigning raster cell values based on predefined criteria

2010-04-20 Thread Robert J. Hijmans
Dear Roman, I think it depends on your data. Below are two examples (both assuming your polygons do not overlap). A) works if each cell in a polygon is closest to its own centroid (and not that of another polygon). It makes a distance surface with distanceFromPoints() and then uses mask() to mask

[R-sig-Geo] assigning raster cell values based on predefined criteria

2010-04-20 Thread Roman Luštrik
Dear list, I have a polygon that I converted to raster (kudos to polygonsToRaster()). I would like to assign values (through a custom function) to cells within this polygon (now as raster). Roughly speaking, cell value will depend on its distance from the central cell (polygon centroid). How would