I've a Java class that generate a GeoTiff file by using Geotools library. My file is correctly generated and I can open it with a Tiff viewer. Now I need to append to this file some GDAL metadatas and I can't achieve it. Here a piece of my code:
DefaultGeographicCRS crs = DefaultGeographicCRS.WGS84;
ReferencedEnvelope refEnvelope = new ReferencedEnvelope(geoBox.getEastLongitude(),geoBox.getWestLongitude(), geoBox.getNorthLatitude(), geoBox.getSouthLatitude(), crs);
GridCoverage2D coverage = new GridCoverageFactory().create("GridCoverage", imagePixelData, refEnvelope);
GeoTiffWriteParams wp = new GeoTiffWriteParams();
wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
wp.setCompressionType("PackBits");
ParameterValueGroup params = new GeoTiffFormat().getWriteParameters();
params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp);
GeoTiffWriter writer = new GeoTiffWriter(new File("d:/test.tif"));
writer.setMetadataValue(Integer.toString(BaselineTIFFTagSet.TAG_COMPRESSION), Integer.toString(BaselineTIFFTagSet.COMPRESSION_PACKBITS));
writer.setMetadataValue(Integer.toString(BaselineTIFFTagSet.TAG_SOFTWARE), "mySoftware");
String xmlStats = "<GDALMetadata><Item name=\"STATISTICS_MAXIMUM\">-318.670013</Item><Item name=\"STATISTICS_MEAN\">-83.070274</Item><Item name=\"STATISTICS_MINIMUM\">-6.320007"
+ "</Item><Item name=\"STATISTICS_STDDEV\">72.243668</Item></GDALMetadata>";
writer.setMetadataValue("42112", xmlStats);
writer.write(coverage, params.values().toArray(new GeneralParameterValue[1]));
As you can see I set metadatas TAG_COMPRESSION and TAG_SOFTWARE and they are correctly readable in the generated file. From http://www.awaresystems.be/imaging/tiff/tifftags/gdal_metadata.html I could see that GDALMetadata identifier is 42112. But this is not working, no GDAL metadata is generated...
Could someone help me? Thanks!!
EDIT: After debugging deep in GeoTools, it seems that it's only possible to add metadatas defined in classes BaselineTIFFTagSet and GeoTIFFTagSet. I can't find a way to add a "private" tag. Is there any solution ?