Reputation: 754
Not sure as to why my plots are in very low pixels, how do I go about increasing them for my resolution?
I'm using this code:
neighborhood_radius <- 5 * floor(max(res(landcover))) / 2
agg_factor <- round(2 * neighborhood_radius / res(landcover))
r <- raster(landcover) %>%
aggregate(agg_factor)
r <- bcr %>%
st_transform(crs = projection(r)) %>%
rasterize(r, field = 1) %>%
# remove any empty cells at edges
trim()
forest_cover <- pland_coords %>%
# convert to spatial features
st_as_sf(coords = c("longitude", "latitude"), crs = 4326) %>%
st_transform(crs = projection(r)) %>%
# rasterize points
rasterize(r, field = "pland_13_urban") %>%
# project to albers equal-area for mapping
projectRaster(crs = st_crs("EPSG:27700")$proj4string, method = "ngb") %>%
+ # trim off empty edges of raster
+ trim()
par(mar = c(0.25, 0.25, 2, 0.25))
t <- str_glue("Proportion of Urban Area\n",
"{max_lc_year} MODIS Landcover")
plot(forest_cover, axes = FALSE, box = FALSE, col = viridis(10), main = t)
although, I have used the same code for a different dataset, at a large cover and got this:
Here is my raster:
r
class : RasterLayer
dimensions : 40, 52, 2080 (nrow, ncol, ncell)
resolution : 2316.564, 2316.564 (x, y)
extent : 463.3127, 120924.6, 5809941, 5902604 (xmin, xmax, ymin, ymax)
crs : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs
source : memory
names : layer
values : 1, 1 (min, max)
If I increase the resolution of r
using aggregate such as this:
r <- aggregate(r, fact = 2)
it pixelates the image further and zooms in:
Whilst dissaggregate
zooms out, and provides slightly less pixels, its also not as great.
Upvotes: 2
Views: 267
Reputation: 754
As Matthew suggested, changing the resolution was the best option, although using aggregate
or disaggregate
was not the right way for this particular situation.
Instead, I used resample
, to transfer the resolution with:
resample(r, landcover, method = 'ngb')
and got this:
Pixels are very similar to the second image, just that the coverage spans closer to 0, otherwise I consider this a success.
Upvotes: 0
Reputation: 332
Providing the data would be helpful. It's possible the spatial resolution of your data set is the limiting factor. However, try feeding in a matrix (i.e. a raster object, r
, or set of spatial x,y points) with a higher resolution to the rasterize
function - my understanding is you should be able to rasterize with arbitrary precision.
c.f. https://gis.stackexchange.com/questions/265064/rasterize-polygons-with-r
Upvotes: 1