Java Code Examples for mil.nga.geopackage.features.user.FeatureDao#getProjection()

The following examples show how to use mil.nga.geopackage.features.user.FeatureDao#getProjection() . 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: RTreeIndexTableDao.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Constructor
 *
 * @param rTree      RTree extension
 * @param dao        user custom data access object
 * @param featureDao feature DAO
 */
RTreeIndexTableDao(RTreeIndexExtension rTree, UserCustomDao dao,
                   FeatureDao featureDao) {
    super(dao, dao.getTable());
    this.rTree = rTree;
    this.featureDao = featureDao;
    this.projection = featureDao.getProjection();
    setUseBindings(true);
    featureDao.setUseBindings(true);
}
 
Example 2
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 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: GoogleMapShapeConverterUtils.java    From geopackage-android-map with MIT License 4 votes vote down vote up
/**
 * Test shapes
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testShapes(GeoPackage geoPackage) throws SQLException {

	GeometryColumnsDao geometryColumnsDao = geoPackage
			.getGeometryColumnsDao();

	if (geometryColumnsDao.isTableExists()) {
		List<GeometryColumns> results = geometryColumnsDao.queryForAll();

		for (GeometryColumns geometryColumns : results) {

			FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);

			GoogleMapShapeConverter converter = new GoogleMapShapeConverter(
					dao.getProjection());
			converter.setExteriorOrientation(null);
			converter.setHoleOrientation(null);

			// Query for all
			FeatureCursor cursor = dao.queryForAll();
			while (cursor.moveToNext()) {
				FeatureRow featureRow = cursor.getRow();

				GeoPackageGeometryData geometryData = featureRow
						.getGeometry();

				if (geometryData != null) {
					Geometry geometry = geometryData.getGeometry();
					GeometryType geometryType = geometry.getGeometryType();

					switch (geometryType) {
					case POINT:
						convertPoint(converter, (Point) geometry);
						break;
					case LINESTRING:
						convertLineString(converter, (LineString) geometry);
						break;
					case POLYGON:
						convertPolygon(converter, (Polygon) geometry);
						break;
					case MULTIPOINT:
						convertMultiPoint(converter, (MultiPoint) geometry);
						break;
					case MULTILINESTRING:
						convertMultiLineString(converter,
								(MultiLineString) geometry);
						break;
					case MULTIPOLYGON:
						convertMultiPolygon(converter,
								(MultiPolygon) geometry);
						break;
					case CIRCULARSTRING:
						convertLineString(converter,
								(CircularString) geometry);
						break;
					case COMPOUNDCURVE:
						convertCompoundCurve(converter,
								(CompoundCurve) geometry);
						break;
					case POLYHEDRALSURFACE:
						convertMultiPolygon(converter,
								(PolyhedralSurface) geometry);
						break;
					case TIN:
						convertMultiPolygon(converter, (TIN) geometry);
						break;
					case TRIANGLE:
						convertPolygon(converter, (Triangle) geometry);
						break;
					default:
					}
				}

			}
			cursor.close();

		}
	}

}
 
Example 5
Source File: FeatureTiles.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Constructor, auto creates the index manager for indexed tables and feature styles for styled tables
 *
 * @param context    context
 * @param geoPackage GeoPackage
 * @param featureDao feature dao
 * @param density    display density: {@link android.util.DisplayMetrics#density}
 * @param width      drawn tile width
 * @param height     drawn tile height
 * @since 3.2.0
 */
public FeatureTiles(Context context, GeoPackage geoPackage, FeatureDao featureDao, float density, int width, int height) {

    this.context = context;
    this.featureDao = featureDao;
    if (featureDao != null) {
        this.projection = featureDao.getProjection();
    }

    this.density = TileUtils.tileDensity(density, width, height);

    tileWidth = width;
    tileHeight = height;

    createEmptyImage();

    compressFormat = CompressFormat.valueOf(context.getString(R.string.feature_tiles_compress_format));

    pointPaint.setAntiAlias(true);
    pointRadius = Float.valueOf(context.getString(R.string.feature_tiles_point_radius));

    linePaint.setAntiAlias(true);
    lineStrokeWidth = Float.valueOf(context.getString(R.string.feature_tiles_line_stroke_width));
    linePaint.setStrokeWidth(this.density * lineStrokeWidth);
    linePaint.setStyle(Style.STROKE);

    polygonPaint.setAntiAlias(true);
    polygonStrokeWidth = Float.valueOf(context.getString(R.string.feature_tiles_polygon_stroke_width));
    polygonPaint.setStrokeWidth(this.density * polygonStrokeWidth);
    polygonPaint.setStyle(Style.STROKE);

    Resources resources = context.getResources();
    fillPolygon = resources.getBoolean(R.bool.feature_tiles_polygon_fill);
    polygonFillPaint.setAntiAlias(true);
    polygonFillPaint.setStyle(Style.FILL);
    polygonFillPaint.setAlpha(resources.getInteger(R.integer.feature_tiles_polygon_fill_alpha));

    if (geoPackage != null) {

        indexManager = new FeatureIndexManager(context, geoPackage, featureDao);
        if (!indexManager.isIndexed()) {
            indexManager.close();
            indexManager = null;
        }

        featureTableStyles = new FeatureTableStyles(geoPackage, featureDao.getTable());
        if (!featureTableStyles.has()) {
            featureTableStyles = null;
        }

    }

    calculateDrawOverlap();
}
 
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: FeatureTiles.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Constructor, auto creates the index manager for indexed tables and
 * feature styles for styled tables
 *
 * @param geoPackage
 *            GeoPackage
 * @param featureDao
 *            feature dao
 * @param scale
 *            scale factor
 * @param width
 *            drawn tile width
 * @param height
 *            drawn tile height
 * @since 3.2.0
 */
public FeatureTiles(GeoPackage geoPackage, FeatureDao featureDao,
		float scale, int width, int height) {

	this.featureDao = featureDao;
	if (featureDao != null) {
		this.projection = featureDao.getProjection();
	}

	this.scale = scale;

	tileWidth = width;
	tileHeight = height;

	compressFormat = GeoPackageJavaProperties.getProperty(
			JavaPropertyConstants.FEATURE_TILES,
			JavaPropertyConstants.FEATURE_TILES_COMPRESS_FORMAT);

	pointRadius = GeoPackageJavaProperties.getFloatProperty(
			JavaPropertyConstants.FEATURE_TILES_POINT,
			JavaPropertyConstants.FEATURE_TILES_RADIUS);
	pointPaint.setColor(GeoPackageJavaProperties.getColorProperty(
			JavaPropertyConstants.FEATURE_TILES_POINT,
			JavaPropertyConstants.FEATURE_TILES_COLOR));

	lineStrokeWidth = GeoPackageJavaProperties.getFloatProperty(
			JavaPropertyConstants.FEATURE_TILES_LINE,
			JavaPropertyConstants.FEATURE_TILES_STROKE_WIDTH);
	linePaint.setStrokeWidth(this.scale * lineStrokeWidth);
	linePaint.setColor(GeoPackageJavaProperties.getColorProperty(
			JavaPropertyConstants.FEATURE_TILES_LINE,
			JavaPropertyConstants.FEATURE_TILES_COLOR));

	polygonStrokeWidth = GeoPackageJavaProperties.getFloatProperty(
			JavaPropertyConstants.FEATURE_TILES_POLYGON,
			JavaPropertyConstants.FEATURE_TILES_STROKE_WIDTH);
	polygonPaint.setStrokeWidth(this.scale * polygonStrokeWidth);
	polygonPaint.setColor(GeoPackageJavaProperties.getColorProperty(
			JavaPropertyConstants.FEATURE_TILES_POLYGON,
			JavaPropertyConstants.FEATURE_TILES_COLOR));

	fillPolygon = GeoPackageJavaProperties.getBooleanProperty(
			JavaPropertyConstants.FEATURE_TILES_POLYGON_FILL);
	polygonFillPaint.setColor(GeoPackageJavaProperties.getColorProperty(
			JavaPropertyConstants.FEATURE_TILES_POLYGON_FILL,
			JavaPropertyConstants.FEATURE_TILES_COLOR));

	if (geoPackage != null) {

		featureIndex = new FeatureTableIndex(geoPackage, featureDao);
		if (!featureIndex.isIndexed()) {
			featureIndex.close();
			featureIndex = null;
		}

		featureTableStyles = new FeatureTableStyles(geoPackage,
				featureDao.getTable());
		if (!featureTableStyles.has()) {
			featureTableStyles = null;
		}

	}

	calculateDrawOverlap();
}
 
Example 8
Source File: RTreeIndexTableDao.java    From geopackage-java with MIT License 3 votes vote down vote up
/**
 * Constructor
 * 
 * @param rTree
 *            RTree extension
 * @param dao
 *            user custom data access object
 * @param featureDao
 *            feature DAO
 */
RTreeIndexTableDao(RTreeIndexExtension rTree, UserCustomDao dao,
		FeatureDao featureDao) {
	super(dao, dao.getTable());
	this.rTree = rTree;
	this.featureDao = featureDao;
	this.projection = featureDao.getProjection();
}