【问题标题】:Query WorldClim using R to obtain data set of Earth's terrestrial surface only?使用R查询WorldClim仅获取地球陆地表面的数据集?
【发布时间】:2022-11-14 01:24:17
【问题描述】:

WorldClim 可以通过以下方式从 R 中查询:

    library(geodata)

    df <- worldclim_global(var="bio",res = 2.5, path ="")

df 必然包括地球的所有陆地和海洋表面。有没有一种有效的方法将两者分开?我想单独从土地上取样——因此也需要去除被大型湖泊/河流和冰川覆盖的区域。土地表面必须是全球范围。

【问题讨论】:

    标签: r geospatial


    【解决方案1】:

    我已经确定了一个解决方案,用于隔离不在海洋、湖泊或冰川之下的地球的空间范围。以下脚本将为您生成该范围 - 尽管可能需要进行一些修改。

    要使此代码有用,您需要从 NaturalEarth 下载空间数据:https://www.naturalearthdata.com/downloads/10m-physical-vectors/。在网站上,搜索这些文件并将它们下载到您的计算机的项目工作目录中。文件:ne_10m_land.shp、dd_land.rda、ne_10m_glaciated_areas.shp 和 dd_lake.rda。

    此代码生成的内容可用于提取属于创建的空间范围内的栅格中的信息,然后将该数据保存在不同的栅格(或其他格式)中。在 stackoverflow 中有几个很好的例子说明如何做到这一点。

        ###
        # Keeping tidy
        
        # rm(list=ls(all=T))
        # gc()
        # .rs.restartR()
        # rm(list=ls(all=T))
        # gc()
        
        library(spatialEco)
        library(sf)
        library(ggOceanMaps)
        library(rgeos)
        library(scattermore)
        library(maptools)
        library(rgdal)
        library(sp)
        library(plyr)
        library(dplyr)
        library(raster)
        library(rgdal)
        library(geodata)
        library(exactextractr)
        
        
        # where data is stored
        NEDPath <- outPath <- ""  # I used data from Natural Earth:
        #https://www.naturalearthdata.com/downloads/10m-physical-vectors/
        #you'll need the following files from there for this code to work:
        #ne_10m_land.shp, dd_land.rda,ne_10m_glaciated_areas.shp, and
        #dd_lake.rda
        # 
        # # call in the world's terrestrial surface
        continental <- st_read(file.path(NEDPath, 
    "ne_10m_land/ne_10m_land.shp"))
            islands <- st_read(file.path(NEDPath, "ne_10m_minor_islands/ne_10m_minor_islands.shp"))
            world <- rbind(continental,islands)
            dd_land <- clip_shapefile(world, c(-180, 180, -90, 90))
            save(dd_land, file = paste(outPath, "ggOceanMapsData/dd_land.rda", sep = "/"), compress = "xz")
    
        
        # call in glacier coverage
        glaciers <- st_read(file.path(NEDPath, "ne_10m_glaciated_areas/ne_10m_glaciated_areas.shp"))
        glaciers <- as_Spatial(glaciers)
        glaciers <- gBuffer(glaciers, byid = TRUE, width = 0)
        dd_glacier <- clip_shapefile(glaciers, c(-180, 180, -90, 90))
        dd_glacier <- gBuffer(dd_glacier, byid = FALSE, width = 0.1)
        dd_glacier <- gBuffer(dd_glacier, byid = FALSE, width = -0.1)
        save(dd_glacier, file = paste(outPath, "ggOceanMapsData/dd_glacier.rda", sep = "/"), compress = "xz")
        
        # call in lakes
        lake <- st_read(file.path(NEDPath, "ne_10m_lakes/ne_10m_lakes.shp"))
        lake <- as_Spatial(lake)
        lake <- gBuffer(lake, byid = TRUE, width = 0)
        dd_lake <- clip_shapefile(lake, c(-180, 180, -90, 90))
        dd_lake <- gBuffer(dd_lake, byid = FALSE, width = 0.1)
        dd_lake <- gBuffer(dd_lake, byid = FALSE, width = -0.1)
        save(dd_lake, file = paste(outPath, "ggOceanMapsData/dd_lake.rda", sep = "/"), compress = "xz")
        
        # isolating extent of world's surface not covered by ice or water
        terrestrial <- gDifference(dd_land, dd_lake)
        terrestrial_ice_free <- gDifference(terrestrial, dd_glacier)
        save(terrestrial_ice_free, file = paste(outPath, "ggOceanMapsData/landsurface.rda", sep = "/"), compress = "xz")
        
        # call the files if saved already, if saved, you can comment out the all the code above until where the working directory is defined - this will save you a lot of time...
        load(file = paste(outPath, "ggOceanMapsData/dd_land.rda", sep = "/"))
        load(file = paste(outPath, "ggOceanMapsData/dd_glacier.rda", sep = "/"))
        load(file = paste(outPath, "ggOceanMapsData/dd_lake.rda", sep = "/"))
        load(file = paste(outPath, "ggOceanMapsData/landsurface.rda", sep = "/"))
        
        # for convenience
        land<-terrestrial_ice_free
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-31
      • 2019-05-21
      • 1970-01-01
      相关资源
      最近更新 更多