[gdal-dev] GDAL Java Bindings - No data value using AutoCreateWarpedVRT
Even Rouault
even.rouault at spatialys.com
Wed Jun 24 07:35:59 PDT 2015
Le mercredi 24 juin 2015 15:19:01, johie a écrit :
> Hi,
>
> I have been working with small application to reproject some raster files
> into WGS84. For this purpose I have used GDAL and Java Bindings.
> Reprojection works just fine, but the problem is that it creates "black"
> bounding box around the warped image (see image below) The problem with
> this is that the value of this black area is 0. In my data I have values
> of 0, so I cannot really set it as noData later. Below is also the part of
> my code I have been using to do this. I have already spent hours with this
> problem :/
>
> So my question is, is there any way to input some parameter to the
> autoCreateWarpedVRT that it changes the Nodata value or is there some way
> to change it later? I must use Java bindings on the app :) It is sad that
> there are so few examples of how to to actually use the gdal Java bindings
> available on the internet.
Jesse,
I don't think you can do what you want to do in a single step with the current
API (the librarified gdalwarp will be welcome for that !). The steps I see
would be :
1) Use gdal.AutoCreateWarpedVRT() to get the output dataset dimension and
geotransform and don't use it afterwards
2) Create a fresh new GeoTIFF with the above information with Driver.Create()
+ Dataset.SetGeoTransform() + Dataset.SetProjection()
3) Set its nodata value to the value of your choice
4) Fill it completely with that value (Band.Fill())
5) Use gdal.ReprojectImage()
Note: I see that you need GDAL 2.0 from the doc of GDALReprojectImage():
"Starting with GDAL 2.0, nodata values set on destination dataset are taken
into account."
More or less what gdalwarp does in fact. Except that it wouldn't do directly
4, but use the INIT_DEST=NO_DATA warping option which would be slightly more
efficient, but that wasn't yet available to SWIG, before my commit of a few
seconds ago :-)
Even
>
>
> <http://osgeo-org.1560.x6.nabble.com/file/n5212697/BlackBoxAutoCreateWarped
> VRT.png>
>
> Band originalBand = inputDataset.GetRasterBand(1);
> Double[] noDataval = new Double[2];
> originalBand.GetNoDataValue(noDataval);
>
> SpatialReference dstRef = new SpatialReference("");
> dstRef.ImportFromEPSG(4326);
>
> Dataset vrt_ds = gdal.AutoCreateWarpedVRT(inputDataset,
> inputDataset.GetProjection(), dstRef.ExportToWkt(),
> gdalconst.GRA_NearestNeighbour);
> vrt_ds.GetRasterBand(1).SetNoDataValue(noDataval[0]);
>
> Driver GeoTiffDriver = gdal.GetDriverByName("GTiff");
>
> Dataset out_ds = GeoTiffDriver.CreateCopy("C:\\temp\\test.tif",
> vrt_ds);
> out_ds.GetRasterBand(1).SetNoDataValue(noDataval[0]);
>
> vrt_ds.delete();
> inputDataset.delete();
> out_ds.delete();
>
> Thanks for your help!
>
>
>
>
> --
> View this message in context:
> http://osgeo-org.1560.x6.nabble.com/gdal-dev-GDAL-Java-Bindings-No-data-va
> lue-using-AutoCreateWarpedVRT-tp5212697.html Sent from the GDAL - Dev
> mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the gdal-dev
mailing list