I wrote this simple code below in C# to convert a raster from Lambert Azimutal Equal Area to regular long-lat raster using GDAL. It works quite fine excepted for the zero-value bands on each side, in purple in the image. I understand that those area would have the nodata_value (i.e. -9999) in turn of zero.

Using comments to this question I found that using a .vrt file and adding this to the <GDALWarpOptions> section:

<Option name="INIT_DEST">-9999</Option>

it works! So my problem now is how to add this option programmatically, intended that I'm using a AutoCreateWarpedVRT.

            Dataset ds = Gdal.Open(file, Access.GA_ReadOnly);
            SpatialReference sss = new OSGeo.OSR.SpatialReference(null);
            sss.ImportFromProj4("+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m");
            string srs_wkt;
            sss.ExportToWkt(out srs_wkt);

            SpatialReference ttt = new OSGeo.OSR.SpatialReference(null);
            ttt.ImportFromProj4("+proj=longlat +datum=WGS84");
            string trs_wkt;
            ttt.ExportToWkt(out trs_wkt);

            Dataset tgs = Gdal.AutoCreateWarpedVRT(ds, srs_wkt, trs_wkt, ResampleAlg.GRA_NearestNeighbour, 0);

            Driver ddf = Gdal.GetDriverByName("AAIGrid");
            ddf.CreateCopy(@"out.asc", tgs, 1, null, null, null);

enter image description here

  • I guess that you don't deal with nodata. Perhaps this Python example helps programcreek.com/python/example/87699/gdal.AutoCreateWarpedVRT.
    – user30184
    Oct 5, 2017 at 10:54
  • @user30184 thanks, I've read this other question but they say: "If I add this line into the rgbwarped.vrt generated in the second step everything is OK: <Option name="UNIFIED_SRC_NODATA">YES</Option> C++ applications can set this option directly. Applications using AutoCreateWarpedVRT from SWIG binding must add this line in to the text of the produced VRT manually." As I use AutoCreateWarpedVRT , I didn't figure out how to add this option??? I've found no "setOption" method or something like that in the API....
    – modestprog
    Oct 5, 2017 at 12:15
  • This question is for python but might have some clues on setting the nodata value.
    – mkennedy
    Oct 6, 2017 at 22:36


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.