Era临时数据集是否有错误的proj4string?

Era临时数据集是否有错误的proj4string?,r,geospatial,raster,sf,R,Geospatial,Raster,Sf,我正在使用Era临时数据集。我想提取一些城市的天气数据。代码和数据将更新为 首先,我使用光栅读取我从网站下载的文件: library(raster) windspeed <- raster("data/10m_wind_speed_19950101.grib") windspeed # class : RasterLayer # dimensions : 241, 480, 115680 (nrow, ncol, ncell) # resolution : 0.75,

我正在使用Era临时数据集。我想提取一些城市的天气数据。代码和数据将更新为

首先,我使用光栅读取我从网站下载的文件:

library(raster)
windspeed <- raster("data/10m_wind_speed_19950101.grib")
windspeed
# class       : RasterLayer 
# dimensions  : 241, 480, 115680  (nrow, ncol, ncell)
# resolution  : 0.75, 0.75  (x, y)
# extent      : -0.375, 359.625, -90.375, 90.375  (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=longlat +a=6367470 +b=6367470 +no_defs 
。。。并将其转换为sf对象:

library(sf)
capitals_sf <- st_as_sf(capitals, coords = c("long", "lat"), crs = 4326)
capitals_sf
# Simple feature collection with 40 features and 4 fields
# geometry type:  POINT
# dimension:      XY
# bbox:           xmin: -99.14 ymin: -35.31 xmax: 149.13 ymax: 60.17
# epsg (SRID):    4326
# proj4string:    +proj=longlat +datum=WGS84 +no_defs
# First 10 features:
#   ID iso3        country  capital              geometry
# 1   1  AUS      Australia Canberra POINT (149.13 -35.31)
# 2   2  AUT        Austria   Vienna   POINT (16.37 48.22)
# 3   3  BEL        Belgium Brussels    POINT (4.33 50.83)
# 4   4  BGR       Bulgaria    Sofia   POINT (23.31 42.69)
# 5   5  BRA         Brazil Brasilia POINT (-47.91 -15.78)
# 6   6  CAN         Canada   Ottawa  POINT (-75.71 45.42)
# 7   7  CHN          China  Beijing   POINT (116.4 39.93)
# 9   8  CYP         Cyprus  Nicosia   POINT (33.38 35.16)
# 11  9  CZE Czech Republic   Prague   POINT (14.43 50.08)
# 12 10  DEU        Germany   Berlin   POINT (13.38 52.52)
奇怪的是,proj4string改变了,但是坐标没有改变

为了查看我的转换是否成功,我制作了一个情节:

plot(windspeed)
plot(capitals_tf, col = "black", add = TRUE)
图为:

经度范围从-0.375到359.627,而不是从-180到180。因此,东半球的所有城市都有正确的标记,而西半球的所有城市都没有


我很困惑。为什么
st_变换
不起作用?我是否传递了错误的proj4string,或者函数无法处理定制的CRS?

这是有关ERA临时数据集格式的一个很好的参考:

它具体报告说:

经度范围从0到360,相当于地理坐标系中的-180到+180

获取所需内容的一种快速而肮脏的方法可能是“移动”光栅的右侧 到左侧,然后手动调整范围,使其跨越-180到180。
这样,光栅以“标准GCS”表示,您可以轻松地 使用它进行绘图

例如:

# create temporary raster, then "move" the right side to the left
tmp <- windspeed
tmp[, 1:240] <- windspeed[, 241:480]
tmp[, 241:480] <- windspeed[, 1:240]

# put data back in windspeed (not really needed) and update extent
windspeed <- tmp
extent(windspeed)@xmin <- extent(windspeed)@xmin -180
extent(windspeed)@xmax <- extent(windspeed)@xmax -180

windspeed
class       : RasterLayer 
dimensions  : 241, 480, 115680  (nrow, ncol, ncell)
resolution  : 0.75, 0.75  (x, y)
extent      : -180.375, 179.625, -90.375, 90.375  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +a=6367470 +b=6367470 +no_defs 
data source : in memory
names       : X10m_wind_speed_19950101 
values      : 0.9062432, 14.906  (min, max)

# now plot: 
capitals_sf <- st_as_sf(capitals, coords = c("long", "lat"), crs = 4326)

plot(windspeed)
plot(capitals_sf, col = "black", add = TRUE)
#创建临时光栅,然后将右侧“移动”到左侧

tmp没有a很难提供帮助,但同时,您可以尝试使用sp::spTransform作为另一种方法来查明您的问题。非常感谢。我尝试了sp::spTransform。它产生了同样的结果。我上传的代码和数据,它应该作为一个可复制的例子工作。非常感谢!你的回答激励了我!实际上,我想使用同一个资本数据集处理很多GRIB文件。因此,我没有交换光栅,而是交换了大写字母:大写字母%mutate(long=ifelse(long<-0.375,long+360,long))。地图看起来不太好,但提取函数给出的结果与我交换光栅时的结果相同。
plot(windspeed)
plot(capitals_tf, col = "black", add = TRUE)
# create temporary raster, then "move" the right side to the left
tmp <- windspeed
tmp[, 1:240] <- windspeed[, 241:480]
tmp[, 241:480] <- windspeed[, 1:240]

# put data back in windspeed (not really needed) and update extent
windspeed <- tmp
extent(windspeed)@xmin <- extent(windspeed)@xmin -180
extent(windspeed)@xmax <- extent(windspeed)@xmax -180

windspeed
class       : RasterLayer 
dimensions  : 241, 480, 115680  (nrow, ncol, ncell)
resolution  : 0.75, 0.75  (x, y)
extent      : -180.375, 179.625, -90.375, 90.375  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +a=6367470 +b=6367470 +no_defs 
data source : in memory
names       : X10m_wind_speed_19950101 
values      : 0.9062432, 14.906  (min, max)

# now plot: 
capitals_sf <- st_as_sf(capitals, coords = c("long", "lat"), crs = 4326)

plot(windspeed)
plot(capitals_sf, col = "black", add = TRUE)