[gdal-dev] Reading from PNG file in Java from using GDAL

paul.malm at lfv.se paul.malm at lfv.se
Tue Aug 17 22:24:27 PDT 2021


I've used gdalwarp.exe to project a tif-file from EPSG:4326 to EPSG:32635 and storing it in the PNG-format:

    gdalwarp.exe -dstalpha -t_srs EPSG:32635 -s_srs EPSG:4326 -if GTiff -of PNG -et 0.125 -r cubicspline -co COMPRESS=LZW -co WORLDFILE=YES H:\somlos_8.tif H:\trans32635.png

Then I try to read that PNG_file in JAVA with GDAL:

       import org.geotools.coverage.grid.GridCoverage2D;
       import org.geotools.coverage.grid.io.AbstractGridFormat;
       import org.geotools.coverage.grid.io.GridCoverage2DReader;
       import org.geotools.coverage.grid.io.GridFormatFinder;
       import org.geotools.factory.Hints;
       import org.geotools.gce.geotiff.GeoTiffFormat;

       public class Test {
          public Test() {
             AbstractGridFormat format = GridFormatFinder.findFormat("H:\\trans32635.png");
             Hints hints=null;;
             GridCoverage2DReader reader = null;
             if (!format.getName().equals("Unknown Format"))
                hints = new Hints();
             if (format instanceof GeoTiffFormat) {
                hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
             }
             try {
                reader = format.getReader("H:\\trans32635.png", hints);
                GridCoverage2D cov = null;
                cov = reader.read(null); // here it breaks
                ...
                ...
             } catch (Exception e1) {
                e1.printStackTrace();
             }
          }
      }
The problem is reading "GridCoverage2D" from the reader "cov = reader.read(null);", where it breaks. It works with the original TIF-file.
The program breaks here:
java.awt.geom.affineTransform.class (public AffineTransform(AffineTransform Tx) { this.m00 = Tx.m00; )
I have the gt-image module and matching .wld, .prj and .png.aux.xml files.
I'm running the JAVA-program on Windows 10 and using GDAL 3.21 and org.geotools 0.0.1-SNAPSHOT.
Any ideas?
Kind regards,
Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210818/9a7fee6e/attachment.html>


More information about the gdal-dev mailing list