2

I want to read tiles from a geopackage file using Geotools (v. 17.0). I found the class GeoPackageReaderTest.java on GitHub and modified the example to read tiles from my file:

// try to read geopackage tiles (modified from https://github.com/geotools/geotools/blob/06e864481205da8af17a7e5083c7894d484785fa/modules/plugin/geopkg/src/test/java/org/geotools/geopkg/mosaic/GeoPackageReaderTest.java)
GeoPackage geoPackage = new GeoPackage(inputFile); // inputfile: http://ngageoint.github.io/GeoPackage/examples/rivers.gpkg
GeoPackageReader reader = new GeoPackageReader(inputFile, null);
GeneralParameterValue[] parameters = new GeneralParameterValue[1];
TileEntry tileEntry = geoPackage.tiles().get(0);
ReferencedEnvelope referencedEnvelope = tileEntry.getBounds();
Rectangle rectangle = new Rectangle((int) referencedEnvelope.getWidth(), (int) referencedEnvelope.getHeight());
GridEnvelope2D gridEnvelope = new GridEnvelope2D(rectangle);
GridGeometry2D gridGeometry = new GridGeometry2D(gridEnvelope, referencedEnvelope);
parameters[0] = new Parameter<GridGeometry2D>(AbstractGridFormat.READ_GRIDGEOMETRY2D, gridGeometry);
String tableName = tileEntry.getTableName(); // "rivers_tiles"
GridCoverage2D gridCoverage = reader.read(tableName, parameters); // throws java.lang.IllegalArgumentException: Envelope must be at least two-dimensional and non-empty.
RenderedImage img = gridCoverage.getRenderedImage();

In the line reader.read(...) I get an IllegalArgumentException:

java.lang.IllegalArgumentException: Envelope must be at least two-dimensional and non-empty.

If I am printing the width and height of my envelope I get this result:

System.out.println("2 dimensions of gridEnvelope - width: " + gridEnvelope.getWidth() + " | height:" + gridEnvelope.getHeight());
// -> 2 dimensions of gridEnvelope - width: 4.0075016E7 | height:4.0075016E7

Any suggestions what is wrong with the code?

1

The problem seems to be that GeoTools thinks that your packages coordinate system is infinitely wide and high which throws off some of the later calculations and leads to a bounding box which is NaN by NaN and hence the error.

I suspect that this is a bug so if you could file one including this test case and the geopackage, some one will look at it.

Update: the problem is resolved in newer GT versions (at least >=19.2)! (https://osgeo-org.atlassian.net/browse/GEOT-5752)

| improve this answer | |
  • Rivers.gpkg opens fine with QGIS. GDAL gives a warning but does not have real problems Warning 1: Database relies on the 'nga_feature_tile_link' (http://ngageoint.github.io/GeoPackage/docs/extensions/feature-tile-link.html) extension that should be implemented in order to read it safely, but is not currently. Some data may be missing while reading that database. – user30184 Jun 6 '17 at 14:23
  • I added the issue: osgeo-org.atlassian.net/browse/GEOT-5752 – Lars Jun 6 '17 at 14:31
  • This gpkg does not totally fit inside the valid bounds of EPSG:3857 Upper Left (-20037508.343,20037508.343) Lower Right (20037508.343,-20037508.343) which might make trouble. Compare epsg.io/3857 Projected bounds: -20026376.39 -20048966.10 20026376.39 20048966.10 – user30184 Jun 6 '17 at 14:32
  • If this was the problem the error should be resolved by this line: GridGeometry2D gridGeometry = new GridGeometry2D(new GridEnvelope2D(new Rectangle(1000,500)), new ReferencedEnvelope(0, 160, 0, 80, referencedEnvelope.getCoordinateReferenceSystem()));? But the error is the same... – Lars Jun 7 '17 at 5:45
  • No, it is reading the CRS from the geopackage which is epsg;3758, look at the code line I mentioned – Ian Turton Jun 7 '17 at 7:39
1

There was a bug in placing the tileorigin into bottom-left while it should be in top-left that was originally reported by GDAL developer

http://osgeo-org.1560.x6.nabble.com/Feedback-on-GeoPackage-plugin-td5177340.html

and next faulty noticed by GeoServer developer as a GDAL bug

https://trac.osgeo.org/gdal/ticket/6871

which finally lead to fixes in both GeoServer and GeoTools

https://osgeo-org.atlassian.net/browse/GEOS-8112

https://osgeo-org.atlassian.net/browse/GEOT-5715

Fix seems to be in GeoTools v.1.17.1 but not in v.1.17.0. Update and try again.

| improve this answer | |
  • Thanks for the hint but setting the geotools version to 17.1 did not fix the issue. – Lars Jun 6 '17 at 14:06
  • 1
    If you could made it to open it would have opened in a wrong way with 17.0 so at least you should now have a good version for your tests. – user30184 Jun 6 '17 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.