public GeoPackageReader(Object source, Hints hints) throws IOException { coverageFactory = CoverageFactoryFinder.getGridCoverageFactory(this.hints); sourceFile = GeoPackageFormat.getFileFromSource(source); file = new GeoPackage(sourceFile, null, null, true); for (TileEntry tile : file.tiles()) { tiles.put(tile.getTableName(), tile); } // have a sane default when hit with no name, useful in particular // when the geopackage only has one coverage coverageName = tiles.keySet().iterator().next(); // add the overview count and allocate the final List<TileMatrix> tileMatricies = tiles.get(coverageName).getTileMatricies(); this.numOverviews = tileMatricies.size() - 1; overViewResolutions = new double[numOverviews][2]; // first tile matrix is the one with the lowest resolution, last one is native for (int i = 0; i < tileMatricies.size() - 1; i++) { final TileMatrix matrix = tileMatricies.get(i); overViewResolutions[tileMatricies.size() - i - 2] = new double[] {matrix.getXPixelSize(), matrix.getYPixelSize()}; } }
@Override public void dispose() { if (file != null) { file.close(); } }
@Override public void initializeConnection(Connection cx) throws SQLException { GeoPackage.init(cx); }
try { while (rs.next()) { entries.add(createTileEntry(rs, cx)); close(rs); close(ps); close(cx);
public static enum DataType { Feature("features"), Raster("rasters"), Tile("tiles"), FeatureWithRaster("featuresWithRasters"); String value; DataType(String value) { this.value = value; } public String value() { return value; } }
String tableName = getSpatialIndexName(entry); PreparedStatement ps = prepare(cx, "SELECT name FROM sqlite_master WHERE type='table' AND name=? ") return rs.next(); } finally { close(rs); close(ps); close(cx);
public void createChangeLog(final String targetTableName, Map<String, ChangeType> changedNodes) throws IOException, SQLException { final GeoPackage geopackage = new GeoPackage(geopackageDbFile); final DataSource dataSource = geopackage.getDataSource(); try (Connection connection = dataSource.getConnection(); GeopkgGeogigMetadata metadata = new GeopkgGeogigMetadata(connection)) { metadata.createChangeLog(targetTableName); metadata.populateChangeLog(targetTableName, changedNodes); } finally { geopackage.close(); } }
public File getTargetFile() { if (targetFile == null) { try { targetFile = File.createTempFile("GeoGigGeoPkgExport", ".gpkg"); targetFile.deleteOnExit(); GeoPackage gpkg = new GeoPackage(targetFile); try { gpkg.init(); } finally { gpkg.close(); } } catch (IOException e) { throw Throwables.propagate(e); } } return targetFile; }
final GeoPackage geopackage = new GeoPackage(geopackageDbFile); try { FeatureEntry featureEntry = geopackage.feature(targetTableName); checkState(featureEntry != null, "Table '%s' does not exist", targetTableName); geopackage.close();
@Then("^the result is a valid GeoPackage file$") public void gpkg_CheckResponseIsGeoPackage() throws Throwable { checkContentType(Variants.GEOPKG_MEDIA_TYPE.getType()); File tmp = File.createTempFile("gpkg_functional_test", ".gpkg", context.getTempFolder()); tmp.deleteOnExit(); try (InputStream stream = context.getLastResponseInputStream()) { try (OutputStream to = new FileOutputStream(tmp)) { ByteStreams.copy(stream, to); } } GeoPackage gpkg = new GeoPackage(tmp); try { List<FeatureEntry> features = gpkg.features(); System.err.printf("Found gpkg tables: %s\n", Lists.transform(features, (e) -> e.getTableName())); } finally { gpkg.close(); } }
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT")); if (!initialised) { init(); addCRS(e.getSrid()); double maxy = 0; if (e.getSrid() != null) { CoordinateReferenceSystem crs = getCRS(e.getSrid()); if (crs != null) { org.opengis.geometry.Envelope env = CRS.getEnvelope(crs); ps.execute(); } finally { close(ps); close(cx);
GeoPackage geopkg() { return new GeoPackage(dataStore); }
public Integer getGeometrySRID( String schemaName, String tableName, String columnName, Connection cx) throws SQLException { try { FeatureEntry fe = geopkg().feature(tableName); return fe != null ? fe.getSrid() : null; } catch (IOException e) { throw new SQLException(e); } }
/** * Create the audit tables for the specified feature type. * * @param geopackage the geopackage to add the tables to * @param mappedPath the feature tree path * @param fe the feature entry to add audit logs too * @param commitId the commit that the exported features came from * @throws SQLException */ private void createAuditLog(final GeoPackage geopackage, final String mappedPath, final FeatureEntry fe, final ObjectId commitId) throws SQLException { info("Creating audit metadata for table '%s'", fe.getIdentifier()); final DataSource dataSource = geopackage.getDataSource(); try (Connection connection = dataSource.getConnection(); GeopkgGeogigMetadata metadata = new GeopkgGeogigMetadata(connection)) { URI repoURI = context.repository().getLocation(); metadata.init(repoURI); final String auditedTable = fe.getIdentifier(); metadata.createAudit(auditedTable, mappedPath, commitId); } }
public void createFIDMappingTable(ConcurrentMap<String, String> fidMappings, String targetTableName) throws IOException { final GeoPackage geopackage = new GeoPackage(geopackageDbFile); try { final DataSource dataSource = geopackage.getDataSource(); try (Connection connection = dataSource.getConnection()) { try (GeopkgGeogigMetadata metadata = new GeopkgGeogigMetadata(connection)) { metadata.createFidMappingTable(targetTableName, fidMappings); } } catch (SQLException e) { throw new RuntimeException(e); } } finally { geopackage.close(); } }
public File createEmptyDatabase() throws Exception { File file = newFile(); GeoPackage geoPackage = new GeoPackage(file); try { geoPackage.init(); } finally { geoPackage.close(); } return file; }
final GeoPackage geopackage = new GeoPackage(geopackageDbFile); try { FeatureEntry featureEntry = geopackage.feature(targetTableName); checkState(featureEntry != null, "Table '%s' does not exist", targetTableName); geopackage.close();
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT")); if (!initialised) { init(); addCRS(e.getSrid()); double maxy = 0; if (e.getSrid() != null) { CoordinateReferenceSystem crs = getCRS(e.getSrid()); if (crs != null) { org.opengis.geometry.Envelope env = CRS.getEnvelope(crs); ps.execute(); } finally { close(ps); close(cx);