title: Converting HDF to georeferenced file (geotiff, shapefile)
body: <p>I am dealing with 28 HDF4 files on ocean primary productivity (annual .tar files can be found here: <a href="http://orca.science.oregonstate.edu/1080.by.2160.monthly.hdf.cbpm2.v.php" rel="nofollow noreferrer">http://orca.science.oregonstate.edu/1080.by.2160.monthly.hdf.cbpm2.v.php</a>)
  My goal is to do some calculations (I need to calculate concentrations per area and obtain the mean over several years, i.e. combine all files spatially) and then convert them to a georeferenced file I can work with in ArcGIS (preferably shapefile, or geotiff). </p>
  
  <p>I have tried several ways to convert to ASCII or raster files and then add a projection using <code>gdalUtils</code> tools such as <code>gdal_translate</code> and <code>get_subdatasets</code>. However, as the HDF4 files are not named after the standards (unlike the MODIS files), the latter doesn't work and I cannot access the subsets.</p>
  
  <p>Here's the code I used to convert to raster:</p>
  
  <pre><code>library(raster)
  library(gdalUtils)
  
  setwd("...path_to_files...")
  
  gdalinfo("cbpm.2015060.hdf")
  hdf_file &lt;- "cbpm.2015060.hdf"
  
  outfile="testout"
  gdal_translate(hdf_file,outfile,sds=TRUE,verbose=TRUE)
  file.rename(outfile,paste("CBPM_test",".tif",sep="")) 
  
  rast &lt;- raster("CBPM_test.tif")
  
  wgs1984 &lt;- CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
  projection(rast) &lt;- wgs1984
  #crs(rast) &lt;- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" 
  
  plot(rast)
  
  writeRaster(rast, file="CBPM_geo.tif", format='GTiff', overwrite=TRUE)
  </code></pre>
  
  <p>The resulting projection is completely off. I'd appreciate help how to do this (converting through any format that works), preferably as batch process.</p>