3

I have tried to used gdalwarp to project set of images(from hdf4 files to tif) before merging them using gdal_merge. But then the merge output has spaces/blanks. They're not merge properly, and I don't know why'd it happened like that. So I thought of merging first before projecting, when I tried to project the merge hdf files an error like this always appears:

ERROR 1: Unable to compute a transformation between pixel/line and georeferenced coordinates for merge.tif. There is no affine transformation and no GCPs.

Command line code: gdalwarp -te 109.975 3.475 135.025 25.025 merge.tif new.tif

Here is the gdalinfo:

Driver: HDF4Image/HDF4 Dataset
Files: A2014348055000.L2_LAC.SeAHABS.hdf
Size is 1160, 1990
Coordinate System is `'
Metadata:
  bad_value_scaled=-32767
  bad_value_unscaled=-32767
  Calibration Data=A2014348055000.L1A_LAC.eAHAB.hdf, MYD02_Reflective_LUTs.V6.1.17.24_OC.hdf, MYD02_Emissive_LUTs.V6.1.1
7.24_OC.hdf, MYD02_QA_LUTs.V6.1.17.24_OC.hdf
  cdm_data_type=swath
  Conventions=CF-1.6
  creator email=data@oceancolor.gsfc.nasa.gov
  creator name=NASA/GSFC/OBPG
  creator url=http://oceandata.sci.gsfc.nasa.gov
  date_created=20141214T092342Z
  Day or Night=Day
  Earth-Sun Distance Correction=1.03201282024384
  Easternmost Longitude=125.8173065
  End Center Latitude=25.38609505
  End Center Longitude=112.290802
  End Day=348
  End Millisec=21301577
  End Node=Ascending
  End Time=2014348055501577
  End Year=2014
  Flag Percentages=0.0001732801902, 22.30172539, 0.001126321382, 15.12727451, 80.96486664, 3.97266531, 5.644948959, 0, 1
5.79899502, 81.37419891, 0.1860162914, 0.8686535954, 0, 0, 0.2047305405, 0.01342921611, 0, 0, 0, 0.08087852597, 43.33668
518, 0.0002599202853, 0.1081701592, 0, 0, 0, 0, 68.54501343, 22.30384445, 0.1022786349, 94.91210175, 0
  geospatial_lat_max=26.48568916
  geospatial_lat_min=6.694877148
  geospatial_lat_units=degrees_north
  geospatial_lon_max=125.8173065
  geospatial_lon_min=105.5096741
  geospatial_lon_units=degrees_east
  Input Files=A2014348055000.L1B_LAC.SeAHABS.hdf,S201434718_NCEP.MET,S201434718_NCEP.MET,S201434718_NCEP.MET,N201434500_
O3_AURAOMI_24h.hdf,N201434500_O3_AURAOMI_24h.hdf,N201434500_O3_AURAOMI_24h.hdf,,xcal_modisa_axc26f,polcor_modisa_2010b,m
odisa_ocr_vc_nn,,landmask.dat,watermask.dat,digital_elevation_map.hdf,ETOPO1_ocssw.nc,,N201434600_SEAICE_NSIDC_24h.hdf,s
st_climatology.hdf,sss_climatology_woa2009.hdf,no2_climatology.hdf,alpha510_climatology.hdf,taua865_climatology.hdf,A201
4348055000.GEO,owmc_lut.hdf,


Geolocation:
  LINE_OFFSET=0
  LINE_STEP=1
  PIXEL_OFFSET=0
  PIXEL_STEP=1
  SRS=GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0
,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHOR
ITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]]
  • Can you supply the information that gdalinfo reports on the subdataset? Or give a link to the download site? – AndreJ Jan 3 '15 at 11:38
  • @AndreJ See edit. – user Jan 3 '15 at 14:23
  • The -te you provide does not fit to the geospatial metadata of the file. – AndreJ Jan 3 '15 at 17:59
4

As a reference, I took the file linked here: http://oceancolor.gsfc.nasa.gov/forum/oceancolor/topic_show.pl?tid=5426

gdalinfo on the subdataset 37 returns:

geospatial_lat_max=24.78230858
geospatial_lat_min=5.343300343
geospatial_lon_max=139.3295746
geospatial_lon_min=126.3987579
...
Lower Left Latitude=24.78230858
Lower Left Longitude=134.9941864
Lower Right Latitude=23.15408325
Lower Right Longitude=126.3987579
...
Upper Left Latitude=6.639705181
Upper Left Longitude=139.3295746
Upper Right Latitude=5.343300343
Upper Right Longitude=131.3719025
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0, 2040.0)
Upper Right (  423.0,    0.0)
Lower Right (  423.0, 2040.0)

These form a rectangle rotated to the east and north axis.

You have to use gdalwarp with the -geoloc option and -te from the geospatial_... tags:

gdalwarp -geoloc -of GTIFF -t_srs EPSG:4326 -te 126.3987579 5.343300343 139.3295746 24.78230858  HDF4_SDS:UNKNOWN:"A2014037040500.L2_LAC.SeAHABS.hdf":37 sds37.tif

which uses the geolocation information that is stored in the subdatasets 11 and 12.

Another way is to add gcp for all four points with gdal_translate:

gdal_translate -of VRT -a_srs EPSG:4326 -gcp 0 0 139.3295746 6.639705181 -gcp 423 0 131.3719025 5.343300343 -gcp 0 2040 134.9941864 24.78230858 -gcp 423 2040 126.3987579 23.15408325 HDF4_SDS:UNKNOWN:"A2014037040500.L2_LAC.SeAHABS.hdf":37 neu.vrt
gdalwarp -of GTIFF -tps neu.vrt 2014.tif

which puts the data in the right position:

enter image description here

  • By the way that file was also from me. What's the best command should I use? gdalwarp or gdal_translate? Does that mean that I need to specify their lat and lon? What if I have numerous hdf and they have different extents and want to warp them in batch? Or want to merge the hdf first before warping. I have 4 to 5 hdf in one day and want to merge them everyday. How will I do that? – user Jan 4 '15 at 7:17
  • 1
    The -geoloc version is better, because the view of the satellite is a bit perspective, which you will not get with just 4 gcp. Merging the hdf does not make sense to me, because the recordings may not fit perfectly. You have to extract the extents from every file, and maybe define a NODATA value too before merging. The resulting tif file has a non-rotated extent with NODATA triangles at the corners. – AndreJ Jan 4 '15 at 15:30
  • Is there any way that I could use the geolocation information that is stored in the subdatasets 11 and 12(lon and lat) without specifying the numerical extents? Let's say I'll just put subdatasets 11 and 12 or lonlat only together with the subdataset 37?(x and y will be the lonlat and the z will be the sds 37). – user Jan 5 '15 at 2:12
  • My task is to warp the hdf file then merge, or maybe merge the hdf file then warp. – user Jan 5 '15 at 2:15
  • You can try -te -180 -90 180 90 for all. I have not tested it myself. – AndreJ Jan 5 '15 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.