使用rgee处理后,光栅与shapefile不对齐

使用rgee处理后,光栅与shapefile不对齐,r,raster,projection,google-earth-engine,rgee,R,Raster,Projection,Google Earth Engine,Rgee,我定义了一个多边形: library(rgee) ee_Initialize() polygon <- ee$Geometry$Polygon( list( c(91.17, -13.42), c(154.10, -13.42), c(154.10, 21.27), c(91.17, 21.27), c(91.17, -13.42) )) Map$addLayer(polygon) 有一个错位,我不确定它是否是正确的光栅已经 为给定

我定义了一个多边形:

library(rgee)
ee_Initialize()
  
polygon <- ee$Geometry$Polygon(
list(
    c(91.17, -13.42), 
    c(154.10, -13.42), 
    c(154.10, 21.27), 
    c(91.17, 21.27),
    c(91.17, -13.42)
))

Map$addLayer(polygon)

有一个错位,我不确定它是否是正确的光栅已经 为给定多边形处理。我还检查了他们的投影是否相同

crs(my_rast)
CRS arguments: +proj=longlat +datum=WGS84 +no_defs
crs(sea_shp)      
CRS arguments: +proj=longlat +datum=WGS84 +no_defs
它们都有相同的投影。我不知道出了什么问题

编辑

正如评论中所建议的,我定义了一个覆盖澳大利亚的新多边形,如下所示:

polygon <- ee$Geometry$Polygon(
   list(
     c(88.75,-45.26), 
     c(162.58,-45.26), 
     c(162.58,8.67), 
     c(88.75,8.67),
     c(88.75,-45.26)
   )
  )

 Map$addLayer(polygon)

多边形似乎没有错位。要在一步中规划所有这些国家,您可以

x <- lapply(c('IDN','MYS','SGP','BRN','PHL'), function(i) getData('GADM', country = i, level = 0))
sea_shp <- bind(x)

x似乎没有错位。要在一步中规划所有这些国家,您可以

x <- lapply(c('IDN','MYS','SGP','BRN','PHL'), function(i) getData('GADM', country = i, level = 0))
sea_shp <- bind(x)

x这似乎与rgdal有关,而不是与光栅包有关。从GEE下载的某些光栅的数据相对于y翻转。我解决了这个问题,如下所示:

library(rgee)
library(raster)
ee_Initialize()

polygon <- ee$Geometry$Polygon(
  list(
    c(91.17, -13.42), 
    c(154.10, -13.42), 
    c(154.10, 21.27), 
    c(91.17, 21.27),
    c(91.17, -13.42)
  ))


month_vec <- 1:12
pr_ls <- list()


for(m in seq_along(month_vec)){
  month_ref <- month_vec[m]
  pr_ls[[m]] <-  
    ee$ImageCollection("NASA/NEX-GDDP")$ 
    filterBounds(polygon)$ # filter it by polygon
    select('pr')$ # select rainfall
    filter(ee$Filter$calendarRange(2000, 2000, "year"))$ # filter the year
    filter(ee$Filter$calendarRange(month_ref, month_ref, "month"))$ # filter the month 
    filter(ee$Filter$eq("model","ACCESS1-0"))$ # filter the model
    sum() # sum the rainfall
}

Imagecollection_pr <- ee$ImageCollection(pr_ls) %>% ee_get(0)

exp1 <- ee_imagecollection_to_local(
  ic = Imagecollection_pr,
  region = polygon,
  dsn = "pp_via_drive",
  via = "drive" # please always use "drive" or "gcs" until rgee 1.0.6 release
)

# One option
gdalinfo <- try (rgdal::GDALinfo(exp1))
if (isTRUE(attr(gdalinfo, "ysign") == 1)) {
  exp1_r <- flip(raster(exp1), direction='y')
}
库(rgee)
图书馆(光栅)
ee_初始化()

多边形这似乎与rgdal有关,而不是与光栅包有关。从GEE下载的某些光栅的数据相对于y翻转。我解决了这个问题,如下所示:

library(rgee)
library(raster)
ee_Initialize()

polygon <- ee$Geometry$Polygon(
  list(
    c(91.17, -13.42), 
    c(154.10, -13.42), 
    c(154.10, 21.27), 
    c(91.17, 21.27),
    c(91.17, -13.42)
  ))


month_vec <- 1:12
pr_ls <- list()


for(m in seq_along(month_vec)){
  month_ref <- month_vec[m]
  pr_ls[[m]] <-  
    ee$ImageCollection("NASA/NEX-GDDP")$ 
    filterBounds(polygon)$ # filter it by polygon
    select('pr')$ # select rainfall
    filter(ee$Filter$calendarRange(2000, 2000, "year"))$ # filter the year
    filter(ee$Filter$calendarRange(month_ref, month_ref, "month"))$ # filter the month 
    filter(ee$Filter$eq("model","ACCESS1-0"))$ # filter the model
    sum() # sum the rainfall
}

Imagecollection_pr <- ee$ImageCollection(pr_ls) %>% ee_get(0)

exp1 <- ee_imagecollection_to_local(
  ic = Imagecollection_pr,
  region = polygon,
  dsn = "pp_via_drive",
  via = "drive" # please always use "drive" or "gcs" until rgee 1.0.6 release
)

# One option
gdalinfo <- try (rgdal::GDALinfo(exp1))
if (isTRUE(attr(gdalinfo, "ysign") == 1)) {
  exp1_r <- flip(raster(exp1), direction='y')
}
库(rgee)
图书馆(光栅)
ee_初始化()

多边形是否确实存在未对齐?在两张图片中,国家相对于多边形的位置看起来大致相同。如果你加上澳大利亚、越南、泰国和中国,对齐效果如何?因为没有对齐,我的意思是我怀疑我的光栅是从w.r.t倒转到polgyon的。是否有任何方法可以检查我的shapefile是否与光栅的方向相同。我编辑了我的问题以反映这一点,你确定存在偏差吗?在两张图片中,国家相对于多边形的位置看起来大致相同。如果你加上澳大利亚、越南、泰国和中国,对齐效果如何?因为没有对齐,我的意思是我怀疑我的光栅是从w.r.t倒转到polgyon的。是否有任何方法可以检查我的shapefile是否与光栅的方向相同。我编辑了我的问题,以反映未对准的情况,我的意思是我怀疑我的光栅与polgyon相反。是否有任何方法可以检查我的shapefile是否与光栅的方向相同。我编辑了我的问题,以反映未对准的情况,我的意思是我怀疑我的光栅与polgyon相反。是否有任何方法可以检查我的shapefile是否与光栅的方向相同。我编辑了我的问题以反映这一点,谢谢。这很有用,谢谢你。了解这一点非常有用
x <- lapply(c('IDN','MYS','SGP','BRN','PHL'), function(i) getData('GADM', country = i, level = 0))
sea_shp <- bind(x)
library(rgee)
library(raster)
ee_Initialize()

polygon <- ee$Geometry$Polygon(
  list(
    c(91.17, -13.42), 
    c(154.10, -13.42), 
    c(154.10, 21.27), 
    c(91.17, 21.27),
    c(91.17, -13.42)
  ))


month_vec <- 1:12
pr_ls <- list()


for(m in seq_along(month_vec)){
  month_ref <- month_vec[m]
  pr_ls[[m]] <-  
    ee$ImageCollection("NASA/NEX-GDDP")$ 
    filterBounds(polygon)$ # filter it by polygon
    select('pr')$ # select rainfall
    filter(ee$Filter$calendarRange(2000, 2000, "year"))$ # filter the year
    filter(ee$Filter$calendarRange(month_ref, month_ref, "month"))$ # filter the month 
    filter(ee$Filter$eq("model","ACCESS1-0"))$ # filter the model
    sum() # sum the rainfall
}

Imagecollection_pr <- ee$ImageCollection(pr_ls) %>% ee_get(0)

exp1 <- ee_imagecollection_to_local(
  ic = Imagecollection_pr,
  region = polygon,
  dsn = "pp_via_drive",
  via = "drive" # please always use "drive" or "gcs" until rgee 1.0.6 release
)

# One option
gdalinfo <- try (rgdal::GDALinfo(exp1))
if (isTRUE(attr(gdalinfo, "ysign") == 1)) {
  exp1_r <- flip(raster(exp1), direction='y')
}