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

The following examples show how to use mil.nga.geopackage.extension.scale.TileScaling. 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-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 #2
Source File: LoadTilesTask.java    From geopackage-mapcache-android with MIT License 6 votes vote down vote up
/**
 * Set the tile generator settings
 *
 * @param activity
 * @param tileGenerator
 * @param minZoom
 * @param maxZoom
 * @param compressFormat
 * @param compressQuality
 * @param googleTiles
 * @param boundingBox
 * @param scaling
 */
private static void setTileGenerator(Activity activity, TileGenerator tileGenerator, int minZoom, int maxZoom,
                                     CompressFormat compressFormat, Integer compressQuality,
                                     boolean googleTiles, BoundingBox boundingBox, TileScaling scaling) {

    if (minZoom > maxZoom) {
        throw new GeoPackageException(
                activity.getString(R.string.generate_tiles_min_zoom_label)
                        + " can not be larger than "
                        + activity
                        .getString(R.string.generate_tiles_max_zoom_label));
    }

    tileGenerator.setCompressFormat(compressFormat);
    tileGenerator.setCompressQuality(compressQuality);
    tileGenerator.setGoogleTiles(googleTiles);
    tileGenerator.setScaling(scaling);
}
 
Example #3
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 #4
Source File: GeoPackageDaoManager.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Unregister all GeoPackage DAO with the connection source
 * 
 * @param connectionSource
 *            connection source
 */
public static void unregisterDaos(ConnectionSource connectionSource) {
	// TODO when ormlite-core version > 5.1 is released, replace with:
	// "DaoManager.unregisterDaos(connectionSource);"
	// See https://github.com/j256/ormlite-core/pull/149
	unregisterDao(connectionSource, Contents.class,
			SpatialReferenceSystem.class,
			SpatialReferenceSystemSfSql.class,
			SpatialReferenceSystemSqlMm.class, Extensions.class,
			GriddedCoverage.class, GriddedTile.class, GeometryIndex.class,
			TableIndex.class, FeatureTileLink.class,
			ExtendedRelation.class, TileScaling.class,
			GeometryColumns.class, GeometryColumnsSfSql.class,
			GeometryColumnsSqlMm.class, Metadata.class,
			MetadataReference.class, DataColumns.class,
			DataColumnConstraints.class, TileMatrix.class,
			TileMatrixSet.class, ContentsId.class);
}
 
Example #5
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean createTileScalingTable() {
	verifyWritable();

	boolean created = false;
	TileScalingDao dao = getTileScalingDao();
	try {
		if (!dao.isTableExists()) {
			created = tableCreator.createTileScaling() > 0;
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to check if " + TileScaling.class.getSimpleName()
						+ " table exists and create it",
				e);
	}
	return created;
}
 
Example #6
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 #7
Source File: GeoPackageOverlay.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Constructor with tile scaling options
 *
 * @param tileDao tile dao
 * @param scaling tile scaling options
 * @since 2.0.2
 */
public GeoPackageOverlay(TileDao tileDao, TileScaling scaling) {
    GeoPackageTileRetriever tileRetriever = new GeoPackageTileRetriever(tileDao);
    if (scaling != null) {
        tileRetriever.setScaling(scaling);
    }
    this.retriever = tileRetriever;
}
 
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: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public TileScalingDao getTileScalingDao() {
	return createDao(TileScaling.class);
}
 
Example #10
Source File: LoadTilesTask.java    From geopackage-mapcache-android with MIT License 4 votes vote down vote up
/**
 * Load tiles from features
 *
 * @param activity
 * @param callback
 * @param active
 * @param geoPackage
 * @param tableName
 * @param featureTiles
 * @param minZoom
 * @param maxZoom
 * @param compressFormat
 * @param compressQuality
 * @param googleTiles
 * @param boundingBox
 * @param scaling
 * @param authority
 * @param code
 */
public static void loadTiles(Activity activity, ILoadTilesTask callback,
                             GeoPackageDatabases active, GeoPackage geoPackage, String tableName,
                             FeatureTiles featureTiles, int minZoom, int maxZoom,
                             CompressFormat compressFormat, Integer compressQuality,
                             boolean googleTiles, BoundingBox boundingBox, TileScaling scaling, String authority, String code) {

    GeoPackageUtils.prepareFeatureTiles(featureTiles);

    Projection projection = ProjectionFactory.getProjection(authority, code);
    BoundingBox bbox = transform(boundingBox, projection);

    TileGenerator tileGenerator = new FeatureTileGenerator(activity, geoPackage,
            tableName, featureTiles, minZoom, maxZoom, bbox, projection);
    setTileGenerator(activity, tileGenerator, minZoom, maxZoom, compressFormat, compressQuality, googleTiles, boundingBox, scaling);

    loadTiles(activity, callback, active, geoPackage, tableName, tileGenerator);
}
 
Example #11
Source File: LoadTilesTask.java    From geopackage-mapcache-android with MIT License 4 votes vote down vote up
/**
 * Load tiles from a URL
 *
 * @param activity
 * @param callback
 * @param active
 * @param database
 * @param tableName
 * @param tileUrl
 * @param minZoom
 * @param maxZoom
 * @param compressFormat
 * @param compressQuality
 * @param googleTiles
 * @param boundingBox
 * @param scaling
 * @param authority
 * @param code
 */
public static void loadTiles(Activity activity, ILoadTilesTask callback,
                             GeoPackageDatabases active, String database, String tableName,
                             String tileUrl, int minZoom, int maxZoom,
                             CompressFormat compressFormat, Integer compressQuality,
                             boolean googleTiles, BoundingBox boundingBox, TileScaling scaling, String authority, String code) {

    GeoPackageManager manager = GeoPackageFactory.getManager(activity);
    GeoPackage geoPackage = manager.open(database);

    Projection projection = ProjectionFactory.getProjection(authority, code);
    BoundingBox bbox = transform(boundingBox, projection);

    TileGenerator tileGenerator = new UrlTileGenerator(activity, geoPackage,
            tableName, tileUrl, minZoom, maxZoom, bbox, projection);
    setTileGenerator(activity, tileGenerator, minZoom, maxZoom, compressFormat, compressQuality, googleTiles, boundingBox, scaling);

    loadTiles(activity, callback, active, geoPackage, tableName, tileGenerator);
}
 
Example #12
Source File: GeoPackageViewModel.java    From geopackage-mapcache-android with MIT License 4 votes vote down vote up
/**
 * Create tile table in the given GeoPackage
 * @return
 */
public boolean createTileTable(String gpName, BoundingBox boundingBox, long epsg, String tableName, TileScaling scaling){
    repository.createTileTable(gpName, boundingBox, epsg, tableName, scaling);
    regenerateGeoPackageTableList();
    return true;
}
 
Example #13
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);
}
 
Example #14
Source File: GeoPackageOverlay.java    From geopackage-android-map with MIT License 3 votes vote down vote up
/**
 * Constructor with specified tile size and tile scaling options
 *
 * @param tileDao tile dao
 * @param width   tile width
 * @param height  tile height
 * @param scaling tile scaling options
 * @since 2.0.2
 */
public GeoPackageOverlay(TileDao tileDao, int width, int height, TileScaling scaling) {
    GeoPackageTileRetriever tileRetriever = new GeoPackageTileRetriever(tileDao, width, height);
    if (scaling != null) {
        tileRetriever.setScaling(scaling);
    }
    this.retriever = tileRetriever;
}
 
Example #15
Source File: GeoPackageOverlay.java    From geopackage-android-map with MIT License 2 votes vote down vote up
/**
 * Constructor using the density to determine tile size and with tile scaling options
 *
 * @param tileDao tile dao
 * @param density display density: {@link android.util.DisplayMetrics#density}
 * @param scaling tile scaling options
 * @since 3.2.0
 */
public GeoPackageOverlay(TileDao tileDao, float density, TileScaling scaling) {
    this(tileDao, TileUtils.tileLength(density), TileUtils.tileLength(density), scaling);
}
 
Example #16
Source File: GeoPackageOverlayFactory.java    From geopackage-android-map with MIT License 2 votes vote down vote up
/**
 * Get a Bounded Overlay Tile Provider for the Tile DAO with the tile creator options
 *
 * @param tileDao tile dao
 * @param scaling tile scaling options
 * @return bounded overlay
 * @since 2.0.2
 */
public static BoundedOverlay getBoundedOverlay(TileDao tileDao, TileScaling scaling) {
    return new GeoPackageOverlay(tileDao, scaling);
}
 
Example #17
Source File: TileGenerator.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Set the tile scaling settings
 *
 * @param scaling
 *            tile scaling
 * @since 2.0.2
 */
public void setScaling(TileScaling scaling) {
	this.scaling = scaling;
}
 
Example #18
Source File: TileGenerator.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Get the tile scaling settings
 *
 * @return tile scaling
 * @since 2.0.2
 */
public TileScaling getScaling() {
	return scaling;
}
 
Example #19
Source File: TileCreator.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Set the tile scaling options
 *
 * @param scaling
 *            tile scaling options
 * @since 2.0.2
 */
public void setScaling(TileScaling scaling) {
	this.scaling = scaling;
}
 
Example #20
Source File: TileCreator.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Get the tile scaling options
 *
 * @return tile scaling options
 * @since 2.0.2
 */
public TileScaling getScaling() {
	return scaling;
}
 
Example #21
Source File: GeoPackageTileRetriever.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Set the Tile Scaling options
 *
 * @param scaling
 *            tile scaling options
 * @since 2.0.2
 */
public void setScaling(TileScaling scaling) {
	tileCreator.setScaling(scaling);
}
 
Example #22
Source File: GeoPackageTileRetriever.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Get the Tile Scaling options
 *
 * @return tile scaling options
 * @since 2.0.2
 */
public TileScaling getScaling() {
	return tileCreator.getScaling();
}
 
Example #23
Source File: GeoPackageOverlayFactory.java    From geopackage-android-map with MIT License 2 votes vote down vote up
/**
 * Get a Bounded Overlay Tile Provider for the Tile DAO with the display density and tile creator options
 *
 * @param tileDao tile dao
 * @param density display density: {@link android.util.DisplayMetrics#density}
 * @param scaling tile scaling options
 * @return bounded overlay
 * @since 3.2.0
 */
public static BoundedOverlay getBoundedOverlay(TileDao tileDao, float density, TileScaling scaling) {
    return new GeoPackageOverlay(tileDao, density, scaling);
}
 
Example #24
Source File: TileCreator.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Set the tile scaling options
 *
 * @param scaling tile scaling options
 * @since 2.0.2
 */
public void setScaling(TileScaling scaling) {
    this.scaling = scaling;
}
 
Example #25
Source File: TileGenerator.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Get the tile scaling settings
 *
 * @return tile scaling
 * @since 2.0.2
 */
public TileScaling getScaling() {
    return scaling;
}
 
Example #26
Source File: TileGenerator.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Set the tile scaling settings
 *
 * @param scaling tile scaling
 * @since 2.0.2
 */
public void setScaling(TileScaling scaling) {
    this.scaling = scaling;
}
 
Example #27
Source File: GeoPackageTileRetriever.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Get the Tile Scaling options
 *
 * @return tile scaling options
 * @since 2.0.2
 */
public TileScaling getScaling() {
    return tileCreator.getScaling();
}
 
Example #28
Source File: GeoPackageTileRetriever.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Set the Tile Scaling options
 *
 * @param scaling tile scaling options
 * @since 2.0.2
 */
public void setScaling(TileScaling scaling) {
    tileCreator.setScaling(scaling);
}
 
Example #29
Source File: GeoPackageOverlayFactory.java    From geopackage-android-map with MIT License 2 votes vote down vote up
/**
 * Get a Tile Provider for the Tile DAO with the tile creator options
 *
 * @param tileDao tile dao
 * @param scaling tile scaling options
 * @return tile provider
 * @since 2.0.2
 */
public static TileProvider getTileProvider(TileDao tileDao, TileScaling scaling) {
    return getBoundedOverlay(tileDao, scaling);
}
 
Example #30
Source File: TileCreator.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Get the tile scaling options
 *
 * @return tile scaling options
 * @since 2.0.2
 */
public TileScaling getScaling() {
    return scaling;
}