Created
October 23, 2015 16:12
-
-
Save hakimabdi/a2ea2a4aecfd5e3c9198 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################## | |
# title : projHDF2GTiff.R | |
# purpose : Converts desired HDF layer to a GeoTIFF and projects it | |
# author : Abdulhakim Abdi (@HakimAbdi) | |
# input : HDF-EOS files | |
# output : Projected GeoTIFF files | |
############################################################################## | |
projHDF2GTiff = function(loc, hdfs, gtiffs, lyr, fromSRS, toSRS){ | |
if("gdalUtils" %in% rownames(installed.packages()) == FALSE){ | |
install.packages("gdalUtils", repos="http://r-forge.r-project.org") | |
require(gdalUtils) | |
} # install and load the gdalUtils package. | |
setwd(loc) # set the working directory to where the data is | |
suppressWarnings(dir.create(paste(loc,"Projected",sep="/"))) # create a directory to store projected files | |
for (i in 1:length(hdfs)){ | |
gdal_translate(hdfs[i],gtiffs[i],sd_index=lyr) # extract the specified HDF layer and save it as a Geotiff | |
gdalwarp(gtiffs[i],paste(loc,"Projected",gtiffs[i],sep="/"),s_srs=fromSRS,t_srs=toSRS,srcnodata=-3000,dstnodata=-3000,overwrite = T) # project geotiffs | |
unlink(gtiffs[i]) # delete unprojected geotiffs to save space | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi.. Thanks for this program.
I have tried to run your program on my data and I keep getting this error
"Error in projHDF2GTiff(loc = myloc, hdfs = hdfs1, gtiffs = gtiffs1, lyr = 1, :
unused arguments (srcnodata = s.nodata, dstnodata = d.nodata)".
Could you take a look and see what I am doing wrong? I have attached my code and some of my data for your consideration.
sample data and code