簡體   English   中英

如何將經度從0 - 360轉換為-180 - 180

[英]how to convert longitude from 0 - 360 to -180 - 180

CMIP5未來氣候數據的經度為0 - 360度。 如何使用光柵包將其轉換為-180 - 180度?

我嘗試使用shift(r0,-180)shift(r0,-360) 這是行不通的。 任何幫助將不勝感激。 這里的r0是一個柵格。

嘗試rotate() 它的幫助頁面甚至提到了它與你正在處理的數據類型的效用:

將x坐標(經度)從0到360的Raster *對象旋轉到-180到180度之間的標准坐標。 全球氣候模型的數據經常使用0到360之間的經度。

這是一個簡單的可重現的例子來展示它的作用:

library(raster)
r <- raster(matrix(1:100, ncol=10), 0, 360, -90, 90, crs="+proj=merc")
r2 <- rotate(r)
r2
# class       : RasterLayer 
# dimensions  : 10, 10, 100  (nrow, ncol, ncell)
# resolution  : 36, 18  (x, y)
# extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=merc 
# data source : in memory
# names       : layer 
# values      : 1, 100  (min, max)

這很簡單:

ifelse(r0 > 180, -360 + r0, r0)

這是一種破解,在raster可能有更簡單的方法,但這是一個選項。 首先,您需要從柵格對象創建矩陣,然后修改一些經度值(僅限大於180的值)並切換回柵格。 marmap包可以為您進行來回切換:

# Switching from a raster to a matrix of class 'bathy'
library(marmap)
temp <- as.bathy(r0)
summary(temp)

# Changing the relevant longitude
names <- as.numeric(row.names(temp))
names[names > 180] <- names[names > 180] - 360

# Renaming the longitudes and switching back from a 'bathy' object to a raster
rownames(temp) <- names
r0.modified <- as.raster(temp)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM