mil.nga.geopackage.extension.scale.TileTableScaling Java Examples

The following examples show how to use mil.nga.geopackage.extension.scale.TileTableScaling. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeoPackageExample.java    From geopackage-android with MIT License 6 votes vote down vote up
private void validateNGAExtensions(GeoPackage geoPackage, boolean has)
        throws SQLException {

    ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();

    TestCase.assertEquals(
            has && GEOMETRY_INDEX,
            extensionsDao.isTableExists()
                    && !extensionsDao.queryByExtension(
                    FeatureTableIndex.EXTENSION_NAME).isEmpty());
    TestCase.assertEquals(has && FEATURE_TILE_LINK,
            new FeatureTileTableLinker(geoPackage).has());
    TestCase.assertEquals(
            has && TILE_SCALING,
            extensionsDao.isTableExists()
                    && !extensionsDao.queryByExtension(
                    TileTableScaling.EXTENSION_NAME).isEmpty());
    TestCase.assertEquals(has && PROPERTIES, new PropertiesExtension(
            geoPackage).has());
    TestCase.assertEquals(has && CONTENTS_ID, new ContentsIdExtension(
            geoPackage).has());
    TestCase.assertEquals(has && FEATURE_STYLE, new FeatureStyleExtension(
            geoPackage).has());

}
 
Example #2
Source File: GeoPackageExample.java    From geopackage-android with MIT License 6 votes vote down vote up
private static void createTileScalingExtension(GeoPackage geoPackage) {

        for (String tileTable : geoPackage.getTileTables()) {

            TileTableScaling tileTableScaling = new TileTableScaling(
                    geoPackage, tileTable);
            TileScaling tileScaling = new TileScaling();
            tileScaling.setZoomIn(2l);
            FeatureTileTableLinker linker = new FeatureTileTableLinker(
                    geoPackage);
            if (linker.has()
                    && !linker.getFeatureTablesForTileTable(tileTable)
                    .isEmpty()) {
                tileScaling.setScalingType(TileScalingType.IN);
            } else {
                tileScaling.setScalingType(TileScalingType.IN_OUT);
                tileScaling.setZoomOut(2l);
            }
            tileTableScaling.create(tileScaling);

        }

    }
 
Example #3
Source File: NGAExtensions.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Delete the Tile Scaling extensions for the table
 * 
 * @param geoPackage
 *            GeoPackage
 * @param table
 *            table name
 * @since 2.0.2
 */
public static void deleteTileScaling(GeoPackageCore geoPackage,
		String table) {

	TileScalingDao tileScalingDao = geoPackage.getTileScalingDao();
	ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();

	try {
		if (tileScalingDao.isTableExists()) {
			tileScalingDao.deleteById(table);
		}
		if (extensionsDao.isTableExists()) {
			extensionsDao.deleteByExtension(TileTableScaling.EXTENSION_NAME,
					table);
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to delete Tile Scaling. GeoPackage: "
						+ geoPackage.getName() + ", Table: " + table,
				e);
	}
}
 
Example #4
Source File: NGAExtensions.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Delete the Tile Scaling extension including the extension entries and
 * custom tables
 * 
 * @param geoPackage
 *            GeoPackage
 * @since 3.2.0
 */
public static void deleteTileScalingExtension(GeoPackageCore geoPackage) {

	TileScalingDao tileScalingDao = geoPackage.getTileScalingDao();
	ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();
	try {
		if (tileScalingDao.isTableExists()) {
			geoPackage.dropTable(tileScalingDao.getTableName());
		}
		if (extensionsDao.isTableExists()) {
			extensionsDao
					.deleteByExtension(TileTableScaling.EXTENSION_NAME);
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to delete Tile Scaling extension and table. GeoPackage: "
						+ geoPackage.getName(),
				e);
	}

}
 
Example #5
Source File: GeoPackageRepository.java    From geopackage-mapcache-android with MIT License 6 votes vote down vote up
/**
 * Create a tile table in the given GeoPackage
 * @return
 */
public boolean createTileTable(String gpName, BoundingBox boundingBox, long epsg, String tableName, TileScaling scaling){
    GeoPackage geoPackage = manager.open(gpName);
    try {
        // Create the srs if needed
        SpatialReferenceSystemDao srsDao = geoPackage.getSpatialReferenceSystemDao();
        SpatialReferenceSystem srs = srsDao.getOrCreateFromEpsg(epsg);
        // Create the tile table
        mil.nga.sf.proj.Projection projection = ProjectionFactory.getProjection(epsg);
        BoundingBox bbox = LoadTilesTask.transform(boundingBox, projection);
        geoPackage.createTileTableWithMetadata(
                tableName, bbox, srs.getSrsId(),
                bbox, srs.getSrsId());

        TileTableScaling tileTableScaling = new TileTableScaling(geoPackage, tableName);
        tileTableScaling.createOrUpdate(scaling);
    } catch (Exception e) {
        Log.i("Exception", e.toString());
        return false;
    } finally {
        geoPackage.close();
    }
    return true;
}
 
Example #6
Source File: GeoPackageExample.java    From geopackage-java with MIT License 6 votes vote down vote up
private void validateNGAExtensions(GeoPackage geoPackage, boolean has)
		throws SQLException {

	ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();

	TestCase.assertEquals(has && GEOMETRY_INDEX,
			extensionsDao.isTableExists() && !extensionsDao
					.queryByExtension(FeatureTableIndex.EXTENSION_NAME)
					.isEmpty());
	TestCase.assertEquals(has && FEATURE_TILE_LINK,
			new FeatureTileTableLinker(geoPackage).has());
	TestCase.assertEquals(has && TILE_SCALING,
			extensionsDao.isTableExists() && !extensionsDao
					.queryByExtension(TileTableScaling.EXTENSION_NAME)
					.isEmpty());
	TestCase.assertEquals(has && PROPERTIES,
			new PropertiesExtension(geoPackage).has());
	TestCase.assertEquals(has && CONTENTS_ID,
			new ContentsIdExtension(geoPackage).has());
	TestCase.assertEquals(has && FEATURE_STYLE,
			new FeatureStyleExtension(geoPackage).has());

}
 
Example #7
Source File: GeoPackageExample.java    From geopackage-java with MIT License 6 votes vote down vote up
private static void createTileScalingExtension(GeoPackage geoPackage) {

		for (String tileTable : geoPackage.getTileTables()) {

			TileTableScaling tileTableScaling = new TileTableScaling(geoPackage,
					tileTable);
			TileScaling tileScaling = new TileScaling();
			tileScaling.setZoomIn(2l);
			FeatureTileTableLinker linker = new FeatureTileTableLinker(
					geoPackage);
			if (linker.has() && !linker.getFeatureTablesForTileTable(tileTable)
					.isEmpty()) {
				tileScaling.setScalingType(TileScalingType.IN);
			} else {
				tileScaling.setScalingType(TileScalingType.IN_OUT);
				tileScaling.setZoomOut(2l);
			}
			tileTableScaling.create(tileScaling);

		}

	}
 
Example #8
Source File: NGAExtensions.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Copy the Tile Scaling extensions for the table
 * 
 * @param geoPackage
 *            GeoPackage
 * @param table
 *            table name
 * @param newTable
 *            new table name
 * @since 3.3.0
 */
public static void copyTileScaling(GeoPackageCore geoPackage, String table,
		String newTable) {

	try {

		TileTableScaling tileTableScaling = new TileTableScaling(geoPackage,
				table);

		if (tileTableScaling.has()) {

			Extensions extension = tileTableScaling.getExtension();

			if (extension != null) {
				extension.setTableName(newTable);
				tileTableScaling.getExtensionsDao().create(extension);

				if (geoPackage.isTable(TileScaling.TABLE_NAME)) {

					CoreSQLUtils.transferTableContent(
							geoPackage.getDatabase(),
							TileScaling.TABLE_NAME,
							TileScaling.COLUMN_TABLE_NAME, newTable, table);

				}
			}
		}

	} catch (Exception e) {
		logger.log(Level.WARNING,
				"Failed to create Tile Scaling for table: " + newTable
						+ ", copied from table: " + table,
				e);
	}

}
 
Example #9
Source File: MapFragment.java    From mage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Add the GeoPackage Tile Table Cache Overlay
 * @param enabledCacheOverlays
 * @param tileTableCacheOverlay
 * @param geoPackage
 * @param linkedToFeatures
 */
private void addGeoPackageTileCacheOverlay(Map<String, CacheOverlay> enabledCacheOverlays, GeoPackageTileTableCacheOverlay tileTableCacheOverlay, GeoPackage geoPackage, boolean linkedToFeatures){
	// Retrieve the cache overlay if it already exists (and remove from cache overlays)
	CacheOverlay cacheOverlay = cacheOverlays.remove(tileTableCacheOverlay.getCacheName());
	if(cacheOverlay != null){
		// If the existing cache overlay is being replaced, create a new cache overlay
		if(tileTableCacheOverlay.getParent().isAdded()){
			cacheOverlay = null;
		}
	}
	if(cacheOverlay == null){
		// Create a new GeoPackage tile provider and add to the map
		TileDao tileDao = geoPackage.getTileDao(tileTableCacheOverlay.getName());

		TileTableScaling tileTableScaling = new TileTableScaling(geoPackage, tileDao);
		TileScaling tileScaling = tileTableScaling.get();

		BoundedOverlay overlay = GeoPackageOverlayFactory
				.getBoundedOverlay(tileDao, getResources().getDisplayMetrics().density, tileScaling);

		TileOverlayOptions overlayOptions = null;
		if(linkedToFeatures){
			overlayOptions = createFeatureTileOverlayOptions(overlay);
		}else {
			overlayOptions = createTileOverlayOptions(overlay);
		}
		TileOverlay tileOverlay = map.addTileOverlay(overlayOptions);
		tileTableCacheOverlay.setTileOverlay(tileOverlay);

		// Check for linked feature tables
		tileTableCacheOverlay.clearFeatureOverlayQueries();
		FeatureTileTableLinker linker = new FeatureTileTableLinker(geoPackage);
		List<FeatureDao> featureDaos = linker.getFeatureDaosForTileTable(tileDao.getTableName());
		for(FeatureDao featureDao: featureDaos){

			// Create the feature tiles
			FeatureTiles featureTiles = new DefaultFeatureTiles(getActivity(), geoPackage, featureDao,
					getResources().getDisplayMetrics().density);

			// Add the feature overlay query
			FeatureOverlayQuery featureOverlayQuery = new FeatureOverlayQuery(getActivity(), overlay, featureTiles);
			tileTableCacheOverlay.addFeatureOverlayQuery(featureOverlayQuery);
		}

		cacheOverlay = tileTableCacheOverlay;
	}
	// Add the cache overlay to the enabled cache overlays
	enabledCacheOverlays.put(cacheOverlay.getCacheName(), cacheOverlay);
}