【问题标题】:Gaps in RasterLayer using R使用 R 的 RasterLayer 中的间隙
【发布时间】:2020-05-04 12:10:54
【问题描述】:

我有这个 shapefile,我从中获取了前两列(lefttop)来访问另一个数据库并获取 elevation 的值。

Simple feature collection with 959 features and 5 fields
geometry type:  MULTIPOINT
dimension:      XY
bbox:           xmin: -50.49206 ymin: -15.00123 xmax: -41.99206 ymax: -2.501234
epsg (SRID):    NA
proj4string:    +proj=longlat +ellps=GRS80 +no_defs
# A tibble: 959 x 6
    left   top right bottom    id              geometry
   <dbl> <dbl> <dbl>  <dbl> <dbl>      <MULTIPOINT [°]>
 1 -48.0 -7.50 -47.7  -7.25   605 (-47.99206 -7.501234)
 2 -48.0 -7.75 -47.7  -7.50   606 (-47.99206 -7.751234)
 3 -48.0 -8.00 -47.7  -7.75   607 (-47.99206 -8.001234)
 4 -48.0 -8.25 -47.7  -8.00   608 (-47.99206 -8.251234)
 5 -48.0 -8.50 -47.7  -8.25   609 (-47.99206 -8.501234)
 6 -48.0 -8.75 -47.7  -8.50   610 (-47.99206 -8.751234)
 7 -48.0 -9.00 -47.7  -8.75   611 (-47.99206 -9.001234)
 8 -48.0 -9.25 -47.7  -9.00   612 (-47.99206 -9.251234)
 9 -48.0 -9.50 -47.7  -9.25   613 (-47.99206 -9.501234)
10 -48.0 -9.75 -47.7  -9.50   614 (-47.99206 -9.751234)
# ... with 949 more rows

我访问了数据库并编写了一个 netCDF 文件 (StackOverflow Question)。我使用了相同的 959 个地理点。

class      : RasterLayer 
dimensions : 51, 35, 1785  (nrow, ncol, ncell)
resolution : 0.25, 0.25  (x, y)
extent     : -50.61706, -41.86706, -15.12623, -2.376234  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
source     : D:/2019/Projetos/Dados_Xavier/Xavier/elev.nc 
names      : elev 
zvar       : elev

但是,当我使用plot(RasterLayer) 进行绘图时,我得到了这个:

为什么光栅图有这种差距,为什么没有与shapefile图相同的形状?

【问题讨论】:

    标签: r raster shapefile geo ncdf4


    【解决方案1】:

    我找到了解决办法!我以为我的解释不是那么技术性,但这是我寻找解决方案所遵循的心理路径。

    我怀疑raster 应该是一个有四个面的图像。如果我感兴趣的地理位置不是正方形或矩形,当我导入我的 netCDF 文件时,就会出现这种奇怪的模式。

    所以,我想先创建一个有四个边的栅格,然后在这个新栅格中写入我的数据。

    首先,我创建了一个新的raster,其中包含xminxmaxyminymax 属性,这些属性来自之前的RasterLayer(损坏的那个)。

    new_raster = raster(xmn = -51, xmx = -41, ymn = -15.5, ymx = -2, res = 0.25)
    

    然后,我拿走了包含我的数据的data.frame

    data
    
             long        lat elevation
    1   -47.99206  -7.501234 242.0362
    2   -47.99206  -7.751234 200.7271
    3   -47.99206  -8.001234 165.6918
    4   -47.99206  -8.251234 271.2571
    5   -47.99206  -8.501234 235.2896
    6   -47.99206  -8.751234 271.5381
    7   -47.99206  -9.001234 290.0054
    8   -47.99206  -9.251234 218.8803
    9   -47.99206  -9.501234 261.7539
    10  -47.99206  -9.751234 318.0000
    
    ...
    

    我使用了rasterize函数:

    final_raster = rasterize(data[1:2], new_r, data[[3]])
    

    And here is what I want:


    希望我的奋斗能帮助到那里的人。

    【讨论】:

      猜你喜欢
      • 2014-07-07
      • 2020-09-17
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多