Java Code Examples for mil.nga.geopackage.GeoPackage#getBoundingBox()

The following examples show how to use mil.nga.geopackage.GeoPackage#getBoundingBox() . 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: FeatureTileGenerator.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Get the bounding box for the feature tile generator, from the provided
 * and from the feature table
 *
 * @param geoPackage   GeoPackage
 * @param featureTiles feature tiles
 * @param boundingBox  bounding box
 * @param projection   projection
 * @return bounding box
 */
private static BoundingBox getBoundingBox(GeoPackage geoPackage,
                                          FeatureTiles featureTiles, BoundingBox boundingBox,
                                          Projection projection) {

    String tableName = featureTiles.getFeatureDao().getTableName();
    boolean manualQuery = boundingBox == null;
    BoundingBox featureBoundingBox = geoPackage.getBoundingBox(projection,
            tableName, manualQuery);
    if (featureBoundingBox != null) {
        if (boundingBox == null) {
            boundingBox = featureBoundingBox;
        } else {
            boundingBox = boundingBox.overlap(featureBoundingBox);
        }
    }

    if (boundingBox != null) {
        boundingBox = featureTiles.expandBoundingBox(boundingBox,
                projection);
    }

    return boundingBox;
}
 
Example 2
Source File: FeatureTileGenerator.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Get the bounding box for the feature tile generator, from the provided
 * and from the feature table
 * 
 * @param geoPackage
 *            GeoPackage
 * @param featureTiles
 *            feature tiles
 * @param boundingBox
 *            bounding box
 * @param projection
 *            projection
 * @return bounding box
 */
private static BoundingBox getBoundingBox(GeoPackage geoPackage,
		FeatureTiles featureTiles, BoundingBox boundingBox,
		Projection projection) {

	String tableName = featureTiles.getFeatureDao().getTableName();
	boolean manualQuery = boundingBox == null;
	BoundingBox featureBoundingBox = geoPackage.getBoundingBox(projection,
			tableName, manualQuery);
	if (featureBoundingBox != null) {
		if (boundingBox == null) {
			boundingBox = featureBoundingBox;
		} else {
			boundingBox = boundingBox.overlap(featureBoundingBox);
		}
	}

	if (boundingBox != null) {
		boundingBox = featureTiles.expandBoundingBox(boundingBox,
				projection);
	}

	return boundingBox;
}
 
Example 3
Source File: OAPIFeatureGeneratorTest.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test a WFS server and create a GeoPackage
 *
 * @param server      server url
 * @param collection  collection name
 * @param name        geoPackage and table name
 * @param limit       request limit
 * @param totalLimit  total limit
 * @param boundingBox bounding box
 * @param time        time
 * @param period      period or end time
 * @throws SQLException upon error
 */
private void testServer(String server, String collection, String name,
                        Integer limit, Integer totalLimit, BoundingBox boundingBox,
                        String time, String period) throws SQLException {

    GeoPackageManager geoPackageManager = GeoPackageFactory.getManager(activity);

    geoPackageManager.delete(collection);

    geoPackageManager.create(collection);

    GeoPackage geoPackage = geoPackageManager.open(collection);

    OAPIFeatureGenerator generator = new OAPIFeatureGenerator(
            geoPackage, name, server, collection);
    generator.setLimit(limit);
    generator.setTotalLimit(totalLimit);
    generator.setBoundingBox(boundingBox);
    generator.setTime(time);
    generator.setPeriod(period);
    generator.setDownloadAttempts(3);

    int count = generator.generateFeatures();
    if (totalLimit != null) {
        TestCase.assertEquals(totalLimit.intValue(), count);
    }

    FeatureDao featureDao = generator.getFeatureDao();
    if (totalLimit != null) {
        TestCase.assertEquals(totalLimit.intValue(), featureDao.count());
    }

    FeatureIndexManager indexer = new FeatureIndexManager(activity, geoPackage, featureDao);
    indexer.setIndexLocation(FeatureIndexType.GEOPACKAGE);
    indexer.index();
    indexer.close();

    BoundingBox dataBounds = geoPackage
            .getBoundingBox(featureDao.getTableName());
    Contents contents = featureDao.getContents();
    contents.setBoundingBox(dataBounds);
    geoPackage.getContentsDao().update(contents);

    geoPackage.close();

}
 
Example 4
Source File: FeaturePreviewUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test the GeoPackage draw feature preview
 *
 * @param activity   activity
 * @param geoPackage GeoPackage
 * @throws IOException upon error
 */
public static void testDraw(Activity activity, GeoPackage geoPackage) throws IOException {

    for (String featureTable : geoPackage.getFeatureTables()) {

        FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
        int count = featureDao.count(
                CoreSQLUtils.quoteWrap(featureDao.getGeometryColumnName())
                        + " IS NOT NULL");

        BoundingBox contentsBoundingBox = geoPackage
                .getContentsBoundingBox(featureTable);
        BoundingBox indexedBoundingBox = geoPackage
                .getBoundingBox(featureTable);
        boolean expectImage = (contentsBoundingBox != null
                || indexedBoundingBox != null) && count > 0;
        boolean epsg = featureDao.getProjection().getAuthority()
                .equalsIgnoreCase(ProjectionConstants.AUTHORITY_EPSG);

        FeaturePreview preview = new FeaturePreview(activity, geoPackage, featureDao);

        Bitmap image = preview.draw();
        if (epsg) {
            assertEquals(expectImage, image != null);
        }

        preview.setBufferPercentage(0.4);
        preview.setLimit((int) Math.ceil(count / 2.0));
        Bitmap imageLimit = preview.draw();
        if (epsg) {
            assertEquals(expectImage, imageLimit != null);
        }

        preview.setManual(true);
        preview.setBufferPercentage(0.05);
        preview.setLimit(null);
        FeatureTiles featureTiles = preview.getFeatureTiles();
        featureTiles.setTileWidth(TileUtils.TILE_PIXELS_DEFAULT);
        featureTiles.setTileHeight(TileUtils.TILE_PIXELS_DEFAULT);
        featureTiles.setDensity(
                TileUtils.density(TileUtils.TILE_PIXELS_DEFAULT));
        featureTiles.clearIconCache();
        Bitmap imageManual = preview.draw();
        if (epsg) {
            assertNotNull(imageManual);
        }

        preview.setBufferPercentage(0.35);
        preview.setLimit(Math.max(count - 1, 1));
        Bitmap imageManualLimit = preview.draw();
        if (epsg) {
            assertNotNull(imageManualLimit);
        }

        preview.setBufferPercentage(0.15);
        preview.setLimit(null);
        preview.appendWhere(
                CoreSQLUtils.quoteWrap(featureDao.getIdColumnName()) + " > "
                        + ((int) Math.floor(count / 2.0)));
        Bitmap imageManualWhere = preview.draw();
        if (epsg) {
            assertNotNull(imageManualWhere);
        }

        if(image != null) {
            image.recycle();
        }
        if(imageLimit != null) {
            imageLimit.recycle();
        }
        if(imageManual != null) {
            imageManual.recycle();
        }
        if(imageManualLimit != null) {
            imageManualLimit.recycle();
        }
        if(imageManualWhere != null) {
            imageManualWhere.recycle();
        }

        preview.close();
    }

}
 
Example 5
Source File: OAPIFeatureGeneratorTest.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test a WFS server and create a GeoPackage
 * 
 * @param server
 *            server url
 * @param collection
 *            collection name
 * @param name
 *            geoPackage and table name
 * @param limit
 *            request limit
 * @param totalLimit
 *            total limit
 * @param boundingBox
 *            bounding box
 * @param time
 *            time
 * @param period
 *            period or end time
 * @param progressFrequency
 *            progress frequency
 * @throws SQLException
 *             upon error
 */
private void testServer(String server, String collection, String name,
		Integer limit, Integer totalLimit, BoundingBox boundingBox,
		String time, String period, int progressFrequency)
		throws SQLException {

	File file = new File(PATH + name + ".gpkg");

	file.delete();

	GeoPackageManager.create(file);
	GeoPackage geoPackage = GeoPackageManager.open(file);

	OAPIFeatureGenerator generator = new OAPIFeatureGenerator(geoPackage,
			name, server, collection);
	generator.setLimit(limit);
	generator.setTotalLimit(totalLimit);
	generator.setBoundingBox(boundingBox);
	generator.setTime(time);
	generator.setPeriod(period);
	generator.setDownloadAttempts(3);
	generator.setProgress(new Progress(collection, progressFrequency, 10));

	int count = generator.generateFeatures();
	if (totalLimit != null) {
		TestCase.assertEquals(totalLimit.intValue(), count);
	}

	FeatureDao featureDao = generator.getFeatureDao();
	if (totalLimit != null) {
		TestCase.assertEquals(totalLimit.intValue(), featureDao.count());
	}

	RTreeIndexExtension rTree = new RTreeIndexExtension(geoPackage);
	rTree.create(featureDao.getTable());

	BoundingBox dataBounds = geoPackage
			.getBoundingBox(featureDao.getTableName());
	Contents contents = featureDao.getContents();
	contents.setBoundingBox(dataBounds);
	geoPackage.getContentsDao().update(contents);

	SQLExec.executeSQL(geoPackage,
			"PRAGMA table_info(\"" + generator.getTableName() + "\")")
			.printResults();
	SQLExec.executeSQL(geoPackage,
			"SELECT * FROM \"" + generator.getTableName() + "\"")
			.printResults();

	geoPackage.close();

}
 
Example 6
Source File: FeaturePreviewUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test the GeoPackage draw feature preview
 * 
 * @param geoPackage
 *            GeoPackage
 * @throws IOException
 *             upon error
 */
public static void testDraw(GeoPackage geoPackage) throws IOException {

	for (String featureTable : geoPackage.getFeatureTables()) {

		FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
		int count = featureDao.count(
				CoreSQLUtils.quoteWrap(featureDao.getGeometryColumnName())
						+ " IS NOT NULL");

		BoundingBox contentsBoundingBox = geoPackage
				.getContentsBoundingBox(featureTable);
		BoundingBox indexedBoundingBox = geoPackage
				.getBoundingBox(featureTable);
		boolean expectImage = (contentsBoundingBox != null
				|| indexedBoundingBox != null) && count > 0;
		boolean epsg = featureDao.getProjection().getAuthority()
				.equalsIgnoreCase(ProjectionConstants.AUTHORITY_EPSG);

		FeaturePreview preview = new FeaturePreview(geoPackage, featureDao);

		BufferedImage image = preview.draw();
		if (epsg) {
			assertEquals(expectImage, image != null);
		}
		if (writeImages) {
			ImageIO.write(image, "png", new File("image.png"));
		}

		preview.setBufferPercentage(0.4);
		preview.setLimit((int) Math.ceil(count / 2.0));
		BufferedImage imageLimit = preview.draw();
		if (epsg) {
			assertEquals(expectImage, imageLimit != null);
		}
		if (writeImages) {
			ImageIO.write(imageLimit, "png", new File("image_limit.png"));
		}

		preview.setManual(true);
		preview.setBufferPercentage(0.05);
		preview.setLimit(null);
		FeatureTiles featureTiles = preview.getFeatureTiles();
		featureTiles.setTileWidth(TileUtils.TILE_PIXELS_DEFAULT);
		featureTiles.setTileHeight(TileUtils.TILE_PIXELS_DEFAULT);
		featureTiles.setScale(
				TileUtils.tileScale(TileUtils.TILE_PIXELS_DEFAULT));
		featureTiles.clearIconCache();
		BufferedImage imageManual = preview.draw();
		if (epsg) {
			assertNotNull(imageManual);
		}
		if (writeImages) {
			ImageIO.write(imageManual, "png", new File("image_manual.png"));
		}

		preview.setBufferPercentage(0.35);
		preview.setLimit(Math.max(count - 1, 1));
		BufferedImage imageManualLimit = preview.draw();
		if (epsg) {
			assertNotNull(imageManualLimit);
		}
		if (writeImages) {
			ImageIO.write(imageManualLimit, "png",
					new File("image_manual_limit.png"));
		}

		preview.setBufferPercentage(0.15);
		preview.setLimit(null);
		preview.appendWhere(
				CoreSQLUtils.quoteWrap(featureDao.getIdColumnName()) + " > "
						+ ((int) Math.floor(count / 2.0)));
		BufferedImage imageManualWhere = preview.draw();
		if (epsg) {
			assertNotNull(imageManualWhere);
		}
		if (writeImages) {
			ImageIO.write(imageManualWhere, "png",
					new File("image_manual_where.png"));
			System.out.println("Breakpoint here");
		}

	}

}