【问题标题】:r sp/maps/maptools libraries: Map of annual solar irradiation in Rr sp/maps/maptools 库:R 中的年度太阳辐射图
【发布时间】:2018-06-26 00:47:54
【问题描述】:

我正在尝试在世界地图上绘制不同颜色的年度太阳辐射数据。我为此目的使用 R 编程。

我使用的数据来自http://eosweb.larc.nasa.gov/sse/global/text/global_radiation

首先,我将此数据转换为空间数据框,并将使用 map(world) 函数获得的世界地图转换为空间形式。

我正在按照https://www.r-bloggers.com/maps-of-solar-radiation/的示例进行练习

用于绘制我的代码如下。我相信代码是完全正确的,但我遇到了一些错误

library(sp)
library(maps)
library(mapdata)
library(maptools)
library(RColorBrewer)

nasafile <- 'http://eosweb.larc.nasa.gov/sse/global/text/global_radiation'
nasa <- read.table(file=nasafile, skip=13, header=TRUE)

proj <- CRS('+proj=latlon +ellps=WGS84')
coords = nasa[,2:1]
datos = nasa[,3:15]
nasaSP <- SpatialPixelsDataFrame(points=coords, data=datos, proj4string=proj)

world <- map("world", plot=FALSE)

llCRS <- CRS("+proj=latlong +ellps=WGS84")
world_sp <- map2SpatialLines(world, proj4string=llCRS)

colar_sp = colorRampPalette(c("snow1", "thistle1", "plum2", "red4"))


map_sp <- list('sp.lines', world_sp)
spplot(nasaSP["Ann"], col.regions=color_sp, sp.layout=map_sp)

我遇到的主要错误与预测有关。我相信我在代码中添加它们的方式是正确的,并且已经看到了许多以相同方式编写它们的示例。请查看这些错误并让我知道如何使此代码正常工作。

提前致谢!

错误:

Error in CRS("+proj=latlon +ellps=WGS84") : 
  northings must follow eastings: +proj=latlon +ellps=WGS84

Error in checkSlotAssignment(object, name, value) : 
  assignment of an object of class “function” is not valid for slot ‘proj4string’ in an object of class “Spatial”; is(value, "CRS") is not TRUE

Error in CRS("+proj=latlong +ellps=WGS84") : 
  northings must follow eastings: +proj=latlong +ellps=WGS84

Error in initialize(value, ...) : object 'llCRS' not found

【问题讨论】:

    标签: r maps sp maptools


    【解决方案1】:

    我发现你的代码有两个问题:

    1) 你错误地使用了CRS。在CRS("+proj=latlong...) 而不是latlong 中,您必须使用longlat(参见?CRS);

    2) 当您绘制地图时,您的color_sp 被称为colar_sp。


    这是您的代码,其中包含更正:

    library(sp)
    library(maps)
    library(mapdata)
    library(maptools)
    library(RColorBrewer)
    
    nasafile <- 'http://eosweb.larc.nasa.gov/sse/global/text/global_radiation'
    nasa <- read.table(file=nasafile, skip=13, header=TRUE)
    
    proj <- CRS("+proj=longlat + datum=WGS84")
    coords = nasa[,2:1]
    datos = nasa[,3:15]
    nasaSP <- SpatialPixelsDataFrame(points=coords, data=datos, proj4string=proj)
    
    world <- map("world", plot=FALSE)
    
    llCRS <- CRS("+proj=longlat + datum=WGS84")
    world_sp <- map2SpatialLines(world, proj4string=llCRS)
    
    color_sp = colorRampPalette(c("snow1", "thistle1", "plum2", "red4"))
    
    
    map_sp <- list('sp.lines', world_sp)
    spplot(nasaSP["Ann"], col.regions=color_sp, sp.layout=map_sp)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多