mil.nga.geopackage.tiles.features.DefaultFeatureTiles Java Examples

The following examples show how to use mil.nga.geopackage.tiles.features.DefaultFeatureTiles. 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 5 votes vote down vote up
private static void createFeatureTileLinkExtension(Context context, GeoPackage geoPackage)
        throws SQLException, IOException {

    List<String> featureTables = geoPackage.getFeatureTables();
    for (String featureTable : featureTables) {

        FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
        FeatureTiles featureTiles = new DefaultFeatureTiles(context, geoPackage, featureDao,
                context.getResources().getDisplayMetrics().density);

        BoundingBox boundingBox = featureDao.getBoundingBox();
        Projection projection = featureDao.getProjection();

        Projection requestProjection = ProjectionFactory
                .getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);
        ProjectionTransform transform = projection
                .getTransformation(requestProjection);
        BoundingBox requestBoundingBox = boundingBox.transform(transform);

        int zoomLevel = TileBoundingBoxUtils
                .getZoomLevel(requestBoundingBox);
        zoomLevel = Math.max(zoomLevel, 8);
        zoomLevel = Math.min(zoomLevel, 19);

        int minZoom = zoomLevel - 8;
        int maxZoom = zoomLevel + 2;

        TileGenerator tileGenerator = new FeatureTileGenerator(context, geoPackage,
                featureTable + "_tiles", featureTiles, minZoom, maxZoom,
                requestBoundingBox, requestProjection);

        tileGenerator.generateTiles();
        featureTiles.close();
    }
}
 
Example #2
Source File: FeatureTileUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Create a new feature tiles
 *
 * @return
 */
public static FeatureTiles createFeatureTiles(Context context, GeoPackage geoPackage, FeatureDao featureDao, boolean useIcon) {

    FeatureTiles featureTiles = new DefaultFeatureTiles(context, featureDao, context.getResources().getDisplayMetrics().density);

    Paint pointPaint = featureTiles.getPointPaint();
    if (useIcon) {
        Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), mil.nga.geopackage.test.R.drawable.ic_launcher);
        bitmap = Bitmap.createScaledBitmap(bitmap, 25, 25, false);
        FeatureTilePointIcon icon = new FeatureTilePointIcon(bitmap);
        featureTiles.setPointIcon(icon);
    } else {
        pointPaint.setColor(Color.BLUE);
    }

    Paint linePaint = featureTiles.getLinePaintCopy();
    linePaint.setColor(Color.GREEN);
    featureTiles.setLinePaint(linePaint);

    Paint polygonPaint = featureTiles.getPolygonPaintCopy();
    polygonPaint.setColor(Color.RED);
    featureTiles.setPolygonPaint(polygonPaint);

    featureTiles.setFillPolygon(true);
    Paint polygonFillPaint = featureTiles.getPolygonFillPaintCopy();
    polygonFillPaint.setColor(Color.RED);
    polygonFillPaint.setAlpha(50);
    featureTiles.setPolygonFillPaint(polygonFillPaint);

    featureTiles.calculateDrawOverlap();

    return featureTiles;
}
 
Example #3
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void createFeatureTileLinkExtension(GeoPackage geoPackage)
		throws SQLException, IOException {

	List<String> featureTables = geoPackage.getFeatureTables();
	for (String featureTable : featureTables) {

		FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
		FeatureTiles featureTiles = new DefaultFeatureTiles(geoPackage,
				featureDao);

		BoundingBox boundingBox = featureDao.getBoundingBox();
		Projection projection = featureDao.getProjection();

		Projection requestProjection = ProjectionFactory
				.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);
		ProjectionTransform transform = projection
				.getTransformation(requestProjection);
		BoundingBox requestBoundingBox = boundingBox.transform(transform);

		int zoomLevel = TileBoundingBoxUtils
				.getZoomLevel(requestBoundingBox);
		zoomLevel = Math.max(zoomLevel, 8);
		zoomLevel = Math.min(zoomLevel, 19);

		int minZoom = zoomLevel - 8;
		int maxZoom = zoomLevel + 2;

		TileGenerator tileGenerator = new FeatureTileGenerator(geoPackage,
				featureTable + "_tiles", featureTiles, minZoom, maxZoom,
				requestBoundingBox, requestProjection);

		tileGenerator.generateTiles();
	}
}
 
Example #4
Source File: FeatureTileUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Create a new feature tiles
 *
 * @param geoPackage
 * @param featureDao
 * @param useIcon
 *            true to use an icon instead of the default point
 * @return feature tiles
 */
public static FeatureTiles createFeatureTiles(GeoPackage geoPackage,
		FeatureDao featureDao, boolean useIcon) {

	FeatureTiles featureTiles = new DefaultFeatureTiles(featureDao);

	if (useIcon) {
		BufferedImage icon = new BufferedImage(5, 5,
				BufferedImage.TYPE_INT_ARGB);
		Graphics2D graphics = icon.createGraphics();
		graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		graphics.setColor(Color.MAGENTA);
		graphics.fillRect(0, 0, 5, 5);
		FeatureTilePointIcon pointIcon = new FeatureTilePointIcon(icon);
		pointIcon.centerIcon();
		featureTiles.setPointIcon(pointIcon);
	} else {
		featureTiles.setPointColor(Color.BLUE);
	}

	featureTiles.setLineColor(Color.GREEN);

	featureTiles.setPolygonColor(Color.RED);

	featureTiles.setFillPolygon(true);
	featureTiles.setPolygonFillColor(new Color(255, 0, 0, 50));

	featureTiles.calculateDrawOverlap();

	return featureTiles;
}
 
Example #5
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 #6
Source File: MapFragment.java    From mage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Add the GeoPackage Feature Table Cache Overlay
 * @param enabledCacheOverlays
 * @param featureTableCacheOverlay
 * @param geoPackage
 */
private void addGeoPackageFeatureCacheOverlay(Map<String, CacheOverlay> enabledCacheOverlays, GeoPackageFeatureTableCacheOverlay featureTableCacheOverlay, GeoPackage geoPackage){
	// Retrieve the cache overlay if it already exists (and remove from cache overlays)
	CacheOverlay cacheOverlay = cacheOverlays.remove(featureTableCacheOverlay.getCacheName());
	if(cacheOverlay != null){
		// If the existing cache overlay is being replaced, create a new cache overlay
		if(featureTableCacheOverlay.getParent().isAdded()){
			cacheOverlay = null;
		}
		for(GeoPackageTileTableCacheOverlay linkedTileTable: featureTableCacheOverlay.getLinkedTileTables()){
			cacheOverlays.remove(linkedTileTable.getCacheName());
		}
	}
	if(cacheOverlay == null) {
		// Add the features to the map
		FeatureDao featureDao = geoPackage.getFeatureDao(featureTableCacheOverlay.getName());

		// If indexed, add as a tile overlay
		if(featureTableCacheOverlay.isIndexed()){
			FeatureTiles featureTiles = new DefaultFeatureTiles(getActivity(), geoPackage, featureDao,
					getResources().getDisplayMetrics().density);
			Integer maxFeaturesPerTile = null;
			if(featureDao.getGeometryType() == GeometryType.POINT){
				maxFeaturesPerTile = getResources().getInteger(R.integer.geopackage_feature_tiles_max_points_per_tile);
			}else{
				maxFeaturesPerTile = getResources().getInteger(R.integer.geopackage_feature_tiles_max_features_per_tile);
			}
			featureTiles.setMaxFeaturesPerTile(maxFeaturesPerTile);
			NumberFeaturesTile numberFeaturesTile = new NumberFeaturesTile(getActivity());
			// Adjust the max features number tile draw paint attributes here as needed to
			// change how tiles are drawn when more than the max features exist in a tile
			featureTiles.setMaxFeaturesTileDraw(numberFeaturesTile);
			// Adjust the feature tiles draw paint attributes here as needed to change how
			// features are drawn on tiles
			FeatureOverlay featureOverlay = new FeatureOverlay(featureTiles);
			featureOverlay.setMinZoom(featureTableCacheOverlay.getMinZoom());

			// Get the tile linked overlay
			BoundedOverlay overlay = GeoPackageOverlayFactory.getLinkedFeatureOverlay(featureOverlay, geoPackage);

			FeatureOverlayQuery featureOverlayQuery = new FeatureOverlayQuery(getActivity(), overlay, featureTiles);
			featureTableCacheOverlay.setFeatureOverlayQuery(featureOverlayQuery);
			TileOverlayOptions overlayOptions = createFeatureTileOverlayOptions(overlay);
			TileOverlay tileOverlay = map.addTileOverlay(overlayOptions);
			featureTableCacheOverlay.setTileOverlay(tileOverlay);
		}
		// Not indexed, add the features to the map
		else {
			int maxFeaturesPerTable = 0;
			if(featureDao.getGeometryType() == GeometryType.POINT){
				maxFeaturesPerTable = getResources().getInteger(R.integer.geopackage_features_max_points_per_table);
			}else{
				maxFeaturesPerTable = getResources().getInteger(R.integer.geopackage_features_max_features_per_table);
			}
			Projection projection = featureDao.getProjection();
			GoogleMapShapeConverter shapeConverter = new GoogleMapShapeConverter(projection);
			FeatureCursor featureCursor = featureDao.queryForAll();
			try {
				final int totalCount = featureCursor.getCount();
				int count = 0;
				while (featureCursor.moveToNext()) {
					try {
						FeatureRow featureRow = featureCursor.getRow();
						GeoPackageGeometryData geometryData = featureRow.getGeometry();
						if (geometryData != null && !geometryData.isEmpty()) {
							Geometry geometry = geometryData.getGeometry();
							if (geometry != null) {
								GoogleMapShape shape = shapeConverter.toShape(geometry);
								// Set the Shape Marker, PolylineOptions, and PolygonOptions here if needed to change color and style
								featureTableCacheOverlay.addShapeToMap(featureRow.getId(), shape, map);

								if (++count >= maxFeaturesPerTable) {
									if (count < totalCount) {
										Toast.makeText(getActivity().getApplicationContext(), featureTableCacheOverlay.getCacheName()
												+ "- added " + count + " of " + totalCount, Toast.LENGTH_LONG).show();
									}
									break;
								}
							}
						}
					}catch(Exception e){
						Log.e(LOG_NAME, "Failed to display feature. GeoPackage: " + geoPackage.getName()
								+ ", Table: " + featureDao.getTableName() + ", Row: " + featureCursor.getPosition(), e);
					}
				}
			} finally {
				featureCursor.close();
			}
		}

		cacheOverlay = featureTableCacheOverlay;
	}

	// Add the cache overlay to the enabled cache overlays
	enabledCacheOverlays.put(cacheOverlay.getCacheName(), cacheOverlay);
}
 
Example #7
Source File: GeoPackageUtils.java    From geopackage-mapcache-android with MIT License 4 votes vote down vote up
/**
 * Prepare the feature draw limits and defaults
 *
 * @param context
 * @param geoPackage
 * @param featureTable
 * @param pointAlpha
 * @param lineAlpha
 * @param polygonAlpha
 * @param polygonFillAlpha
 * @param pointColor
 * @param lineColor
 * @param pointRadius
 * @param lineStroke
 * @param polygonColor
 * @param polygonStroke
 * @param polygonFill
 * @param polygonFillColor
 */
public static void prepareFeatureDraw(Context context, GeoPackage geoPackage, String featureTable, EditText pointAlpha, EditText lineAlpha, EditText polygonAlpha, EditText polygonFillAlpha,
                                      EditText pointColor, EditText lineColor, EditText pointRadius, EditText lineStroke,
                                      EditText polygonColor, EditText polygonStroke, CheckBox polygonFill, EditText polygonFillColor) {

    FeatureTableStyles featureTableStyles = new FeatureTableStyles(geoPackage, featureTable);

    // Set feature limits
    pointAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
            0, 255)});
    lineAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
            0, 255)});
    polygonAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
            0, 255)});
    polygonFillAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
            0, 255)});

    // Set default feature attributes
    FeatureTiles featureTiles = new DefaultFeatureTiles(context);
    String defaultColor = "#000000";

    StyleRow pointStyle = featureTableStyles.getTableStyle(GeometryType.POINT);
    if(pointStyle != null){
        mil.nga.geopackage.style.Color pointStyleColor = pointStyle.getColorOrDefault();
        pointColor.setText(pointStyleColor.getColorHex());
        pointAlpha.setText(String.valueOf(pointStyleColor.getAlpha()));
        pointRadius.setText(new DecimalFormat("0.0#").format(pointStyle.getWidthOrDefault() / 2.0));
    }else{
        Paint pointPaint = featureTiles.getPointPaint();
        pointColor.setText(defaultColor);
        pointAlpha.setText(String.valueOf(pointPaint.getAlpha()));
        pointRadius.setText(String.valueOf(featureTiles.getPointRadius()));
    }

    StyleRow lineStyle = featureTableStyles.getTableStyle(GeometryType.LINESTRING);
    if(lineStyle != null){
        mil.nga.geopackage.style.Color lineStyleColor = lineStyle.getColorOrDefault();
        lineColor.setText(lineStyleColor.getColorHex());
        lineAlpha.setText(String.valueOf(lineStyleColor.getAlpha()));
        lineStroke.setText(new DecimalFormat("0.0#").format(lineStyle.getWidthOrDefault()));
    }else{
        Paint linePaint = featureTiles.getLinePaintCopy();
        lineColor.setText(defaultColor);
        lineAlpha.setText(String.valueOf(linePaint.getAlpha()));
        lineStroke.setText(String.valueOf(linePaint.getStrokeWidth()));
    }

    StyleRow polygonStyle = featureTableStyles.getTableStyle(GeometryType.POLYGON);
    if(polygonStyle != null){
        mil.nga.geopackage.style.Color polygonStyleColor = polygonStyle.getColorOrDefault();
        polygonColor.setText(polygonStyleColor.getColorHex());
        polygonAlpha.setText(String.valueOf(polygonStyleColor.getAlpha()));
        polygonStroke.setText(new DecimalFormat("0.0#").format(polygonStyle.getWidthOrDefault()));
        mil.nga.geopackage.style.Color polygonStyleFillColor = polygonStyle.getFillColor();
        polygonFill.setChecked(polygonStyleFillColor != null);
        if(polygonStyleFillColor != null){
            polygonFillColor.setText(polygonStyleFillColor.getColorHex());
            polygonFillAlpha.setText(String.valueOf(polygonStyleFillColor.getAlpha()));
        }else{
            polygonFillColor.setText(defaultColor);
            polygonFillAlpha.setText(String.valueOf(255));
        }
    }else{
        Paint polygonPaint = featureTiles.getPolygonPaintCopy();
        polygonColor.setText(defaultColor);
        polygonAlpha.setText(String.valueOf(polygonPaint.getAlpha()));
        polygonStroke.setText(String.valueOf(polygonPaint.getStrokeWidth()));

        polygonFill.setChecked(featureTiles.isFillPolygon());
        Paint polygonFillPaint = featureTiles.getPolygonFillPaintCopy();
        polygonFillColor.setText(defaultColor);
        polygonFillAlpha.setText(String.valueOf(polygonFillPaint.getAlpha()));
    }

}