@Test public void testCreateTileEntry() throws Exception { TileEntry e = new TileEntry(); e.setTableName("foo"); e.setBounds(new ReferencedEnvelope(-180, 180, -90, 90, DefaultGeographicCRS.WGS84)); e.getTileMatricies().add(new TileMatrix(0, 1, 1, 256, 256, 0.1, 0.1)); e.getTileMatricies().add(new TileMatrix(1, 2, 2, 256, 256, 0.1, 0.1)); geopkg.create(e); assertTileEntry(e); List<Tile> tiles = new ArrayList(); tiles.add(new Tile(0, 0, 0, new byte[] {0})); tiles.add(new Tile(1, 0, 0, new byte[] {1})); tiles.add(new Tile(1, 0, 1, new byte[] {2})); tiles.add(new Tile(1, 1, 0, new byte[] {3})); tiles.add(new Tile(1, 1, 1, new byte[] {4})); for (Tile t : tiles) { geopkg.add(e, t); } try (TileReader r = geopkg.reader(e, null, null, null, null, null, null)) { assertTiles(tiles, r); } }
static TileEntry createTileEntry(ResultSet rs, Connection cx) throws SQLException, IOException { TileEntry e = new TileEntry(); initEntry(e, rs); PreparedStatement psm = cx.prepareStatement( format( "SELECT *, exists(SELECT 1 FROM \"%s\" data where data.zoom_level = tileMatrix.zoom_level) as has_tiles" + " FROM %s as tileMatrix" + " WHERE table_name = ?" + " ORDER BY zoom_level ASC", e.getTableName(), TILE_MATRIX_METADATA)); try { psm.setString(1, e.getTableName()); ResultSet rsm = psm.executeQuery(); try { while (rsm.next()) { TileMatrix m = new TileMatrix(); m.setZoomLevel(rsm.getInt("zoom_level")); m.setMatrixWidth(rsm.getInt("matrix_width")); m.setMatrixHeight(rsm.getInt("matrix_height")); m.setTileWidth(rsm.getInt("tile_width")); m.setTileHeight(rsm.getInt("tile_height")); m.setXPixelSize(rsm.getDouble("pixel_x_size")); m.setYPixelSize(rsm.getDouble("pixel_y_size")); m.setTiles(rsm.getBoolean("has_tiles")); e.getTileMatricies().add(m); } } finally { close(rsm); } } finally { close(psm); } psm = cx.prepareStatement( format( "SELECT * FROM %s a, %s b " + "WHERE a.table_name = ? " + "AND a.srs_id = b.srs_id " + "LIMIT 1", TILE_MATRIX_SET, SPATIAL_REF_SYS)); try { psm.setString(1, e.getTableName()); ResultSet rsm = psm.executeQuery(); try { if (rsm.next()) { int srid = rsm.getInt("organization_coordsys_id"); e.setSrid(srid); CoordinateReferenceSystem crs; try { crs = CRS.decode("EPSG:" + srid, true); } catch (Exception ex) { crs = e.getBounds().getCoordinateReferenceSystem(); } e.setTileMatrixSetBounds( new ReferencedEnvelope( rsm.getDouble("min_x"), rsm.getDouble("max_x"), rsm.getDouble("min_y"), rsm.getDouble("max_y"), crs)); } } finally { close(rsm); } } finally { close(psm); } return e; }
GeoPackage implements Closeable { static TileEntry createTileEntry(ResultSet rs, Connection cx) throws SQLException, IOException { TileEntry e = new TileEntry(); initEntry(e, rs); PreparedStatement psm = cx.prepareStatement( format( "SELECT *, exists(SELECT 1 FROM \"%s\" data where data.zoom_level = tileMatrix.zoom_level) as has_tiles" + " FROM %s as tileMatrix" + " WHERE table_name = ?" + " ORDER BY zoom_level ASC", e.getTableName(), TILE_MATRIX_METADATA)); try { psm.setString(1, e.getTableName()); ResultSet rsm = psm.executeQuery(); try { while (rsm.next()) { TileMatrix m = new TileMatrix(); m.setZoomLevel(rsm.getInt("zoom_level")); m.setMatrixWidth(rsm.getInt("matrix_width")); m.setMatrixHeight(rsm.getInt("matrix_height")); m.setTileWidth(rsm.getInt("tile_width")); m.setTileHeight(rsm.getInt("tile_height")); m.setXPixelSize(rsm.getDouble("pixel_x_size")); m.setYPixelSize(rsm.getDouble("pixel_y_size")); m.setTiles(rsm.getBoolean("has_tiles")); e.getTileMatricies().add(m); } } finally { close(rsm); } } finally { close(psm); } psm = cx.prepareStatement( format( "SELECT * FROM %s a, %s b " + "WHERE a.table_name = ? " + "AND a.srs_id = b.srs_id " + "LIMIT 1", TILE_MATRIX_SET, SPATIAL_REF_SYS)); try { psm.setString(1, e.getTableName()); ResultSet rsm = psm.executeQuery(); try { if (rsm.next()) { int srid = rsm.getInt("organization_coordsys_id"); e.setSrid(srid); CoordinateReferenceSystem crs; try { crs = CRS.decode("EPSG:" + srid, true); } catch (Exception ex) { crs = e.getBounds().getCoordinateReferenceSystem(); } e.setTileMatrixSetBounds( new ReferencedEnvelope( rsm.getDouble("min_x"), rsm.getDouble("max_x"), rsm.getDouble("min_y"), rsm.getDouble("max_y"), crs)); } } finally { close(rsm); } } finally { close(psm); } return e; } }
GeoPackage implements Closeable { static TileEntry createTileEntry(ResultSet rs, Connection cx) throws SQLException, IOException { TileEntry e = new TileEntry(); initEntry(e, rs); PreparedStatement psm = cx.prepareStatement( format( "SELECT *, exists(SELECT 1 FROM \"%s\" data where data.zoom_level = tileMatrix.zoom_level) as has_tiles" + " FROM %s as tileMatrix" + " WHERE table_name = ?" + " ORDER BY zoom_level ASC", e.getTableName(), TILE_MATRIX_METADATA)); try { psm.setString(1, e.getTableName()); ResultSet rsm = psm.executeQuery(); try { while (rsm.next()) { TileMatrix m = new TileMatrix(); m.setZoomLevel(rsm.getInt("zoom_level")); m.setMatrixWidth(rsm.getInt("matrix_width")); m.setMatrixHeight(rsm.getInt("matrix_height")); m.setTileWidth(rsm.getInt("tile_width")); m.setTileHeight(rsm.getInt("tile_height")); m.setXPixelSize(rsm.getDouble("pixel_x_size")); m.setYPixelSize(rsm.getDouble("pixel_y_size")); m.setTiles(rsm.getBoolean("has_tiles")); e.getTileMatricies().add(m); } } finally { close(rsm); } } finally { close(psm); } psm = cx.prepareStatement( format( "SELECT * FROM %s a, %s b " + "WHERE a.table_name = ? " + "AND a.srs_id = b.srs_id " + "LIMIT 1", TILE_MATRIX_SET, SPATIAL_REF_SYS)); try { psm.setString(1, e.getTableName()); ResultSet rsm = psm.executeQuery(); try { if (rsm.next()) { int srid = rsm.getInt("organization_coordsys_id"); e.setSrid(srid); CoordinateReferenceSystem crs; try { crs = CRS.decode("EPSG:" + srid, true); } catch (Exception ex) { crs = e.getBounds().getCoordinateReferenceSystem(); } e.setTileMatrixSetBounds( new ReferencedEnvelope( rsm.getDouble("min_x"), rsm.getDouble("max_x"), rsm.getDouble("min_y"), rsm.getDouble("max_y"), crs)); } } finally { close(rsm); } } finally { close(psm); } return e; } GeoPackage();  GeoPackage(File file);  GeoPackage(File file, String user, String passwd);  GeoPackage(File file, String user, String passwd, boolean readOnly);   GeoPackage(DataSource dataSource);  GeoPackage(JDBCDataStore dataStore);  GeoPackage(File file, SQLiteConfig config, Map<String, Object> storeParams); }
GeoPackage implements Closeable { static TileEntry createTileEntry(ResultSet rs, Connection cx) throws SQLException, IOException { TileEntry e = new TileEntry(); initEntry(e, rs); PreparedStatement psm = cx.prepareStatement( format( "SELECT *, exists(SELECT 1 FROM \"%s\" data where data.zoom_level = tileMatrix.zoom_level) as has_tiles" + " FROM %s as tileMatrix" + " WHERE table_name = ?" + " ORDER BY zoom_level ASC", e.getTableName(), TILE_MATRIX_METADATA)); try { psm.setString(1, e.getTableName()); ResultSet rsm = psm.executeQuery(); try { while (rsm.next()) { TileMatrix m = new TileMatrix(); m.setZoomLevel(rsm.getInt("zoom_level")); m.setMatrixWidth(rsm.getInt("matrix_width")); m.setMatrixHeight(rsm.getInt("matrix_height")); m.setTileWidth(rsm.getInt("tile_width")); m.setTileHeight(rsm.getInt("tile_height")); m.setXPixelSize(rsm.getDouble("pixel_x_size")); m.setYPixelSize(rsm.getDouble("pixel_y_size")); m.setTiles(rsm.getBoolean("has_tiles")); e.getTileMatricies().add(m); } } finally { close(rsm); } } finally { close(psm); } psm = cx.prepareStatement( format( "SELECT * FROM %s a, %s b " + "WHERE a.table_name = ? " + "AND a.srs_id = b.srs_id " + "LIMIT 1", TILE_MATRIX_SET, SPATIAL_REF_SYS)); try { psm.setString(1, e.getTableName()); ResultSet rsm = psm.executeQuery(); try { if (rsm.next()) { int srid = rsm.getInt("organization_coordsys_id"); e.setSrid(srid); CoordinateReferenceSystem crs; try { crs = CRS.decode("EPSG:" + srid, true); } catch (Exception ex) { crs = e.getBounds().getCoordinateReferenceSystem(); } e.setTileMatrixSetBounds( new ReferencedEnvelope( rsm.getDouble("min_x"), rsm.getDouble("max_x"), rsm.getDouble("min_y"), rsm.getDouble("max_y"), crs)); } } finally { close(rsm); } } finally { close(psm); } return e; } GeoPackage();  GeoPackage(File file);  GeoPackage(File file, String user, String passwd);  GeoPackage(File file, String user, String passwd, boolean readOnly);   GeoPackage(DataSource dataSource);  GeoPackage(JDBCDataStore dataStore);  GeoPackage(File file, SQLiteConfig config, Map<String, Object> storeParams); GeoPkgGeomWriter.Configuration getWriterConfiguration(); File getFile(); DataSource getDataSource(); void init(); void close(); void addCRS(int srid); static void addCRS(
            Connection cx,
            int srid,
            String srsName,
            String organization,
            int organizationCoordSysId,
            String definition,
            String description); void addCRS(CoordinateReferenceSystem crs, String auth, int srid); List<Entry> contents(); List<FeatureEntry> features(); FeatureEntry feature(String name); GeoPkgExtension getExtension(String name); T getExtension(Class<T> extensionClass); void create(FeatureEntry entry, SimpleFeatureType schema); void add(FeatureEntry entry, SimpleFeatureCollection collection); void add(FeatureEntry entry, SimpleFeatureSource source, Filter filter); SimpleFeatureWriter writer(
            FeatureEntry entry, boolean append, Filter filter, Transaction tx); SimpleFeatureReader reader(FeatureEntry entry, Filter filter, Transaction tx); static SimpleDateFormat getDateFormat(); void createSpatialIndex(FeatureEntry e); List<TileEntry> tiles(); TileEntry tile(String name); void create(TileEntry entry); void add(TileEntry entry, Tile tile); @SuppressWarnings("PMD.CloseResource") // cx and st get into the TileReader TileReader reader(
            TileEntry entry,
            Integer lowZoom,
            Integer highZoom,
            Integer lowCol,
            Integer highCol,
            Integer lowRow,
            Integer highRow); void addRange(String attribute, Integer low, Integer high, List<String> q); boolean hasSpatialIndex(FeatureEntry entry); Set<Identifier> searchSpatialIndex(
            FeatureEntry entry, Double minX, Double minY, Double maxX, Double maxY); int getTileBound(TileEntry entry, int zoom, boolean isMax, boolean isRow); }
GeoPackage implements Closeable { static TileEntry createTileEntry(ResultSet rs, Connection cx) throws SQLException, IOException { TileEntry e = new TileEntry(); initEntry(e, rs); PreparedStatement psm = cx.prepareStatement( format( "SELECT *, exists(SELECT 1 FROM \"%s\" data where data.zoom_level = tileMatrix.zoom_level) as has_tiles" + " FROM %s as tileMatrix" + " WHERE table_name = ?" + " ORDER BY zoom_level ASC", e.getTableName(), TILE_MATRIX_METADATA)); try { psm.setString(1, e.getTableName()); ResultSet rsm = psm.executeQuery(); try { while (rsm.next()) { TileMatrix m = new TileMatrix(); m.setZoomLevel(rsm.getInt("zoom_level")); m.setMatrixWidth(rsm.getInt("matrix_width")); m.setMatrixHeight(rsm.getInt("matrix_height")); m.setTileWidth(rsm.getInt("tile_width")); m.setTileHeight(rsm.getInt("tile_height")); m.setXPixelSize(rsm.getDouble("pixel_x_size")); m.setYPixelSize(rsm.getDouble("pixel_y_size")); m.setTiles(rsm.getBoolean("has_tiles")); e.getTileMatricies().add(m); } } finally { close(rsm); } } finally { close(psm); } psm = cx.prepareStatement( format( "SELECT * FROM %s a, %s b " + "WHERE a.table_name = ? " + "AND a.srs_id = b.srs_id " + "LIMIT 1", TILE_MATRIX_SET, SPATIAL_REF_SYS)); try { psm.setString(1, e.getTableName()); ResultSet rsm = psm.executeQuery(); try { if (rsm.next()) { int srid = rsm.getInt("organization_coordsys_id"); e.setSrid(srid); CoordinateReferenceSystem crs; try { crs = CRS.decode("EPSG:" + srid, true); } catch (Exception ex) { crs = e.getBounds().getCoordinateReferenceSystem(); } e.setTileMatrixSetBounds( new ReferencedEnvelope( rsm.getDouble("min_x"), rsm.getDouble("max_x"), rsm.getDouble("min_y"), rsm.getDouble("max_y"), crs)); } } finally { close(rsm); } } finally { close(psm); } return e; } GeoPackage();  GeoPackage(File file);  GeoPackage(File file, String user, String passwd);  GeoPackage(File file, String user, String passwd, boolean readOnly);   GeoPackage(DataSource dataSource);  GeoPackage(JDBCDataStore dataStore);  GeoPackage(File file, SQLiteConfig config, Map<String, Object> storeParams); GeoPkgGeomWriter.Configuration getWriterConfiguration(); File getFile(); DataSource getDataSource(); void init(); void close(); void addCRS(int srid); static void addCRS(
            Connection cx,
            int srid,
            String srsName,
            String organization,
            int organizationCoordSysId,
            String definition,
            String description); void addCRS(CoordinateReferenceSystem crs, String auth, int srid); List<Entry> contents(); List<FeatureEntry> features(); FeatureEntry feature(String name); GeoPkgExtension getExtension(String name); T getExtension(Class<T> extensionClass); void create(FeatureEntry entry, SimpleFeatureType schema); void add(FeatureEntry entry, SimpleFeatureCollection collection); void add(FeatureEntry entry, SimpleFeatureSource source, Filter filter); SimpleFeatureWriter writer(
            FeatureEntry entry, boolean append, Filter filter, Transaction tx); SimpleFeatureReader reader(FeatureEntry entry, Filter filter, Transaction tx); static SimpleDateFormat getDateFormat(); void createSpatialIndex(FeatureEntry e); List<TileEntry> tiles(); TileEntry tile(String name); void create(TileEntry entry); void add(TileEntry entry, Tile tile); @SuppressWarnings("PMD.CloseResource") // cx and st get into the TileReader TileReader reader(
            TileEntry entry,
            Integer lowZoom,
            Integer highZoom,
            Integer lowCol,
            Integer highCol,
            Integer lowRow,
            Integer highRow); void addRange(String attribute, Integer low, Integer high, List<String> q); boolean hasSpatialIndex(FeatureEntry entry); Set<Identifier> searchSpatialIndex(
            FeatureEntry entry, Double minX, Double minY, Double maxX, Double maxY); int getTileBound(TileEntry entry, int zoom, boolean isMax, boolean isRow); static final String GEOPACKAGE_CONTENTS; static final String GEOMETRY_COLUMNS; static final String SPATIAL_REF_SYS; static final String DATA_COLUMNS; static final String TILE_MATRIX_METADATA; static final String METADATA; static final String METADATA_REFERENCE; static final String TILE_MATRIX_SET; static final String DATA_COLUMN_CONSTRAINTS; static final String EXTENSIONS; static final String SPATIAL_INDEX; static final String SCHEMA; static final String SKIP_REGISTRATION; static final String DATA_COLUMN; }