zoukankan      html  css  js  c++  java
  • R:MODIS 原数据下载

    目前下载MODIS数据的工具功能不够完整,比如先要下载500米分辨率的LAI数据集MOD15A2H, 无论是MODIS官网提供的网页下载工具daac2disk,还是R论坛提供的ftp协议下载包http://r-gis.net/?q=ModisDownload, 都不能下载MOD15A2H。 这里展示使用R下载http协议的MODIS数据,有兴趣的可以自己研究一下,贴出全部代码 :

    rm(list = ls())
    setwd("F:/modis/MOD15A2H006/")
    library(RCurl)
    library(rgdal)
    
    #去除网页Html标记 cleanFun <- function(htmlString) { return(gsub("<.*?>", "", htmlString)) } #R的防错机制 safe_download <- function(furl, fsave, fmode, fmethod) { tryCatch ( { download.file(url = furl,destfile = fsave,mode = fmode,method = fmethod) }, error = function(cond) { print("error") } ) } #下载数据的地址 MOD15A2H006 <- "http://e4ftl01.cr.usgs.gov/MOLT/MOD15A2H.006/" gg<- getURL(MOD15A2H006) gg<- cleanFun(gg) items <- strsplit(gg, " - ")[[1]] items<- items[-1] items<- items[-1* NROW(items)] pp<- strsplit(items, "/ ") dirs <- unlist(lapply(strsplit(items, "/ "), function(x){x[1]})) dates <- unlist(lapply(strsplit(items, "/ "), function(x){x[2]})) dirsURL<- paste(MOD15A2H006, dirs, "/", sep="") #记录日志
    sink(file = "log.log",split = T) for (i in 1:length(dirsURL)) { print(dirsURL[i]) dirurl<- dirsURL[i] files<- getURL(dirurl) files<- cleanFun(files) bb <- strsplit(files, " ")[[1]] bb<- bb[-1] bb<- bb[-1*NROW(bb)] hh <- unlist( lapply(strsplit(bb, " "), function(x){x[[1]]})) hdffile<- hh[grep(hh, pattern="MOD15A2H.*.h26v05.*.hdf")[1]] gurl = paste(dirurl, hdffile, "", sep="") gsave = paste(getwd(), "/", hdffile, sep="") gmode='wb' gmethod='wininet'
     #开始下载 safe_download(furl = gurl, fsave = gsave, fmode = gmode, fmethod = gmethod) print(gurl) } sink()

     转载请注明出处:http://www.cnblogs.com/ABMRG/p/5194082.html

  • 相关阅读:
    雪妖现世:给SAP Fiori Launchpad增添雪花纷飞的效果
    ABAP开发环境语法高亮的那些事儿
    如何使用Prometheus采集SAP ABAP Netweaver的应用日志数据
    如何免费试用SAP的Fiori应用
    使用ABAP绘制可伸缩矢量图
    背景建模
    C# 属性和索引
    Equation
    Phone numbers
    BerOS file system
  • 原文地址:https://www.cnblogs.com/ABMRG/p/5194082.html
Copyright © 2011-2022 走看看