Dear sir,

I am currently using the Imaging Apache Common library in order to create
GeoTIFF images.

I succeeded to create the image and write the metadata in it
(ModelTiepointTag and ModelPixelScaleTag) but they seem not to be
recognized by GDAL or any other GIS Software. As a result my output image
is not georeferenced.

I was not able to solve that problem so far.

I attach to this mail the part of the script where I create the file. Could
you please tell me where is my mistake?

Here is the gdalinfo on the output image :

Driver: GTiff/GeoTIFF
> Files: <my-path>\output.tif
> Size is 2340, 1654
> Coordinate System is `'
> Metadata:
>   TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
>   TIFFTAG_XRESOLUTION=72
>   TIFFTAG_YRESOLUTION=72
> Image Structure Metadata:
>   COMPRESSION=LZW
>   INTERLEAVE=PIXEL
> Corner Coordinates:
> Upper Left  (    0.0,    0.0)
> Lower Left  (    0.0, 1654.0)
> Upper Right ( 2340.0,    0.0)
> Lower Right ( 2340.0, 1654.0)
> Center      ( 1170.0,  827.0)
> Band 1 Block=2340x1 Type=Byte, ColorInterp=Red
> Band 2 Block=2340x1 Type=Byte, ColorInterp=Green
> Band 3 Block=2340x1 Type=Byte, ColorInterp=Blue



Best regards

-- 
*Eric DAVID*
06 83 22 61 96
private void writeGeoTiff(File imgFile, OutputImageFactory imageFactory) {

    try {

        // Create the geoMetadata
        double[] modelTiePoint = new double[6];
        modelTiePoint[3] = imageFactory.getPlan().getxOri();
        modelTiePoint[4] = imageFactory.getPlan().getyOri();

        double[] modelPixelScale = new double[3];
        modelPixelScale[0] = 1 / imageFactory.getScaleX();
        modelPixelScale[1] = 1 / imageFactory.getScaleY();

        byte[] imageBytes = 
Imaging.writeImageToBytes(imageFactory.getOutputImage(), ImageFormats.TIFF,
                new HashMap<>());

        TiffImageMetadata metadata = (TiffImageMetadata) 
Imaging.getMetadata(imageBytes);

        TiffOutputSet outputSet = null;
        if (null != metadata) {
            outputSet = metadata.getOutputSet();
        }

        if (null == outputSet) {
            outputSet = new TiffOutputSet();
        }

        
outputSet.getOrCreateExifDirectory().add(GeoTiffTagConstants.EXIF_TAG_MODEL_PIXEL_SCALE_TAG,
                modelPixelScale);
        
outputSet.getOrCreateExifDirectory().add(GeoTiffTagConstants.EXIF_TAG_MODEL_TIEPOINT_TAG,
 modelTiePoint);

        Map<String, Object> params = new HashMap<>();

        params.put(ImagingConstants.PARAM_KEY_EXIF, outputSet);

        Imaging.writeImage(imageFactory.getOutputImage(), imgFile, 
ImageFormats.TIFF, params);

    } catch (IOException ioe) {
        LoggerManager.debug(ioe);
    } catch (ImageWriteException iwe) {
        LoggerManager.debug(iwe);
    } catch (ImageReadException ire) {
        LoggerManager.debug(ire);
    }

}
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org

Reply via email to