After some testing, I think that the geoloc is not working properly. So I used the alternative method using manually created vrt files:
- Create a file named
lon.vrt
:
<VRTDataset rasterXSize="1354" rasterYSize="2030">
<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,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]]</SRS>
<VRTRasterBand dataType="Float32" band="1">
<SimpleSource>
<SourceFilename relativeToVRT="1">HDF5:A2015045060000.L2_LAC_OC.nc://navigation_data/longitude</SourceFilename>
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="1354" RasterYSize="2030" DataType="Float32" BlockXSize="452" BlockYSize="21" />
<SrcRect xOff="0" yOff="0" xSize="1354" ySize="2030" />
<DstRect xOff="0" yOff="0" xSize="1354" ySize="2030" />
</SimpleSource>
</VRTRasterBand>
</VRTDataset>
- Same for the latitudes in
lat.vrt
:
<VRTDataset rasterXSize="1354" rasterYSize="2030">
<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,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]]</SRS>
<VRTRasterBand dataType="Float32" band="1">
<SimpleSource>
<SourceFilename relativeToVRT="1">HDF5:A2015045060000.L2_LAC_OC.nc://navigation_data/latitude</SourceFilename>
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="1354" RasterYSize="2030" DataType="Float32" BlockXSize="452" BlockYSize="21" />
<SrcRect xOff="0" yOff="0" xSize="1354" ySize="2030" />
<DstRect xOff="0" yOff="0" xSize="1354" ySize="2030" />
</SimpleSource>
</VRTRasterBand>
</VRTDataset>
- and for the data
chlor.vrt
:
<VRTDataset rasterXSize="1354" rasterYSize="2030">
<metadata domain="GEOLOCATION">
<mdi key="X_DATASET">lon.vrt</mdi>
<mdi key="X_BAND">1</mdi>
<mdi key="Y_DATASET">lat.vrt</mdi>
<mdi key="Y_BAND">1</mdi>
<mdi key="PIXEL_OFFSET">0</mdi>
<mdi key="LINE_OFFSET">0</mdi>
<mdi key="PIXEL_STEP">1</mdi>
<mdi key="LINE_STEP">1</mdi>
</metadata>
<VRTRasterBand band="1" datatype="Float32">
<SimpleSource>
<SourceFilename relativeToVRT="1">HDF5:A2015045060000.L2_LAC_OC.nc://geophysical_data/chlor_a</SourceFilename>
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="1354" RasterYSize="2030" DataType="Float32" BlockXSize="452" BlockYSize="21" />
<SrcRect xOff="0" yOff="0" xSize="1354" ySize="2030" />
<DstRect xOff="0" yOff="0" xSize="1354" ySize="2030" />
</SimpleSource>
</VRTRasterBand>
</VRTDataset>
- Do the warping with:
gdalwarp -geoloc -t_srs EPSG:4326 chlor.vrt chlor-out.tif
and the result fits to the shorelines around Borneo:

Alternatively to creating the vrts manually, you can create them with GDAL:
gdal_translate -of VRT HDF5:A2015045060000.L2_LAC_OC.nc://navigation_data/longitude lon.vrt
gdal_translate -of VRT HDF5:A2015045060000.L2_LAC_OC.nc://navigation_data/latitude lat.vrt
gdal_translate -of VRT HDF5:A2015045060000.L2_LAC_OC.nc://geophysical_data/chlor_a chlor.vrt
With a good text editor, remove the GCP lists from all of them, and insert only into the chlor.vrt this section instead:
<metadata domain="GEOLOCATION">
<mdi key="X_DATASET">lon.vrt</mdi>
<mdi key="X_BAND">1</mdi>
<mdi key="Y_DATASET">lat.vrt</mdi>
<mdi key="Y_BAND">1</mdi>
<mdi key="PIXEL_OFFSET">0</mdi>
<mdi key="LINE_OFFSET">0</mdi>
<mdi key="PIXEL_STEP">1</mdi>
<mdi key="LINE_STEP">1</mdi>
</metadata>
Then run
gdalwarp -geoloc -t_srs EPSG:4326 -overwrite chlor.vrt chlor-vrt.tif
to get the same picture as above.
Another solution, working with manually edited GCP points, can be found in my answer for Using GDALwarp for reprojecting netCDF file?
-geoloc
and-te
in two commands?gdalwarp -geoloc -of GTIFF -t_srs EPSG:4326 -te ...
should run. But you have to use the right values for te, taken from the metadata as reported by gdalinfo.<metadata>
should be removed too, or closed before the new section. The lon.vrt and lat.vrt get no GEOLOCATION, only the chlor.vrt.