简体   繁体   English

增加绘图的像素分辨率

[英]Increase pixel resolution of plot

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)

this is the output:这是输出: 在此处输入图片说明

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的分辨率,例如:

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.虽然dissaggregate缩小并提供略少的像素,但它也没有那么好。

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 (ie 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.但是,尝试将具有更高分辨率的矩阵(即光栅对象、 r或一组空间 x,y 点)输入到rasterize函数中 - 我的理解是您应该能够以任意精度进行光栅化。

cf https://gis.stackexchange.com/questions/265064/rasterize-polygons-with-r参见https://gis.stackexchange.com/questions/265064/rasterize-polygons-with-r

As Matthew suggested, changing the resolution was the best option, although using aggregate or disaggregate was not the right way for this particular situation.正如 Matthew 所建议的那样,更改分辨率是最好的选择,尽管在这种特定情况下使用aggregatedisaggregate并不是正确的方法。

Instead, I used resample , to transfer the resolution with:相反,我使用resample来传输分辨率:

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.像素与第二张图像非常相似,只是覆盖范围更接近于 0,否则我认为这是成功的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM