Java Code Examples for mil.nga.geopackage.core.srs.SpatialReferenceSystemDao#queryForAll()

The following examples show how to use mil.nga.geopackage.core.srs.SpatialReferenceSystemDao#queryForAll() . 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: GeometryColumnsUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test create
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

    SpatialReferenceSystemDao srsDao = geoPackage
            .getSpatialReferenceSystemDao();
    ContentsDao contentsDao = geoPackage.getContentsDao();
    GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

    if (dao.isTableExists()) {

        // Get current count
        long count = dao.countOf();
        TestCase.assertEquals(count, dao.getFeatureTables().size());

        // Retrieve a random srs
        List<SpatialReferenceSystem> results = srsDao.queryForAll();
        SpatialReferenceSystem srs = null;
        if (!results.isEmpty()) {
            int random = (int) (Math.random() * results.size());
            srs = results.get(random);
        }

        // Create a new contents
        Contents contents = new Contents();
        contents.setTableName("test_contents");
        contents.setDataType(ContentsDataType.FEATURES);
        contents.setIdentifier("test_contents");
        contents.setDescription("");
        // contents.setLastChange(new Date());
        contents.setMinX(-180.0);
        contents.setMinY(-90.0);
        contents.setMaxX(180.0);
        contents.setMaxY(90.0);
        contents.setSrs(srs);

        // Create the feature table
        geoPackage.createFeatureTable(TestUtils.buildFeatureTable(
                contents.getTableName(), "geom", GeometryType.GEOMETRY));

        contentsDao.create(contents);

        String columnName = "TEST_COLUMN_NAME";
        GeometryType geometryType = GeometryType.POINT;
        byte z = 2;
        byte m = 2;

        // Create new geometry columns
        GeometryColumns geometryColumns = new GeometryColumns();
        geometryColumns.setContents(contents);
        geometryColumns.setColumnName(columnName);
        geometryColumns.setGeometryType(geometryType);
        geometryColumns.setSrs(contents.getSrs());
        geometryColumns.setZ(z);
        geometryColumns.setM(m);
        dao.create(geometryColumns);

        // Verify count
        long newCount = dao.countOf();
        TestCase.assertEquals(count + 1, newCount);
        TestCase.assertEquals(newCount, dao.getFeatureTables().size());
        TestCase.assertTrue(dao.getFeatureTables().contains(
                contents.getTableName()));

        // Verify saved geometry columns
        GeometryColumns queryGeometryColumns = dao
                .queryForId(geometryColumns.getId());
        TestCase.assertEquals(contents.getId(),
                queryGeometryColumns.getTableName());
        TestCase.assertEquals(columnName,
                queryGeometryColumns.getColumnName());
        TestCase.assertEquals(geometryType,
                queryGeometryColumns.getGeometryType());
        TestCase.assertEquals(contents.getSrsId().longValue(),
                queryGeometryColumns.getSrsId());
        TestCase.assertEquals(z, queryGeometryColumns.getZ());
        TestCase.assertEquals(m, queryGeometryColumns.getM());
        TestCase.assertEquals(contents.getId(), queryGeometryColumns
                .getContents().getId());
        TestCase.assertEquals(contents.getSrsId().longValue(),
                queryGeometryColumns.getSrs().getId());
    }
}
 
Example 2
Source File: TileMatrixUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();
	ContentsDao contentsDao = geoPackage.getContentsDao();
	TileMatrixDao dao = geoPackage.getTileMatrixDao();

	if (dao.isTableExists()) {

		// Get current count
		long count = dao.countOf();

		// Retrieve a random srs
		List<SpatialReferenceSystem> results = srsDao.queryForAll();
		SpatialReferenceSystem srs = null;
		if (!results.isEmpty()) {
			int random = (int) (Math.random() * results.size());
			srs = results.get(random);
		}

		// Create a new contents
		Contents contents = new Contents();
		contents.setTableName("test_contents");
		contents.setDataType(ContentsDataType.TILES);
		contents.setIdentifier("test_contents");
		contents.setDescription("");
		// contents.setLastChange(new Date());
		contents.setMinX(-180.0);
		contents.setMinY(-90.0);
		contents.setMaxX(180.0);
		contents.setMaxY(90.0);
		contents.setSrs(srs);

		// Create the user tile table
		geoPackage.createTileTable(TestUtils.buildTileTable(contents
				.getTableName()));

		contentsDao.create(contents);

		// Create new matrix tile
		int zoom = 3;
		int matrixWidth = 4;
		int matrixHeight = 5;
		int tileWidth = 128;
		int tileHeight = 256;
		double pixelXSize = 889.5;
		double pixelYSize = 900.1;

		TileMatrix tileMatrix = new TileMatrix();
		tileMatrix.setContents(contents);
		tileMatrix.setZoomLevel(zoom);
		tileMatrix.setMatrixWidth(matrixWidth);
		tileMatrix.setMatrixHeight(matrixHeight);
		tileMatrix.setTileWidth(tileWidth);
		tileMatrix.setTileHeight(tileHeight);
		tileMatrix.setPixelXSize(pixelXSize);
		tileMatrix.setPixelYSize(pixelYSize);
		dao.create(tileMatrix);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);

		// Verify saved matrix tile
		TileMatrix queryTileMatrix = dao.queryForId(tileMatrix.getId());
		TestCase.assertEquals(contents.getId(),
				queryTileMatrix.getTableName());
		TestCase.assertEquals(zoom, queryTileMatrix.getZoomLevel());
		TestCase.assertEquals(matrixWidth, queryTileMatrix.getMatrixWidth());
		TestCase.assertEquals(matrixHeight,
				queryTileMatrix.getMatrixHeight());
		TestCase.assertEquals(tileWidth, queryTileMatrix.getTileWidth());
		TestCase.assertEquals(tileHeight, queryTileMatrix.getTileHeight());
		TestCase.assertEquals(pixelXSize, queryTileMatrix.getPixelXSize());
		TestCase.assertEquals(pixelYSize, queryTileMatrix.getPixelYSize());
		TestCase.assertEquals(contents.getId(), queryTileMatrix
				.getContents().getId());
	}
}
 
Example 3
Source File: TileMatrixSetUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();
	ContentsDao contentsDao = geoPackage.getContentsDao();
	TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();

	if (dao.isTableExists()) {

		// Get current count
		long count = dao.countOf();
		TestCase.assertEquals(count, dao.getTileTables().size());

		// Retrieve a random srs
		List<SpatialReferenceSystem> results = srsDao.queryForAll();
		SpatialReferenceSystem srs = null;
		if (!results.isEmpty()) {
			int random = (int) (Math.random() * results.size());
			srs = results.get(random);
		}

		// Create a new contents
		Contents contents = new Contents();
		contents.setTableName("test_contents");
		contents.setDataType(ContentsDataType.TILES);
		contents.setIdentifier("test_contents");
		contents.setDescription("");
		// contents.setLastChange(new Date());
		contents.setMinX(-180.0);
		contents.setMinY(-90.0);
		contents.setMaxX(180.0);
		contents.setMaxY(90.0);
		contents.setSrs(srs);

		// Create the user tile table
		geoPackage.createTileTable(TestUtils.buildTileTable(contents
				.getTableName()));

		contentsDao.create(contents);

		// Create new matrix tile set
		TileMatrixSet tileMatrixSet = new TileMatrixSet();
		tileMatrixSet.setContents(contents);
		tileMatrixSet.setSrs(contents.getSrs());
		tileMatrixSet.setMinX(contents.getMinX());
		tileMatrixSet.setMinY(contents.getMinY());
		tileMatrixSet.setMaxX(contents.getMaxX());
		tileMatrixSet.setMaxY(contents.getMaxY());
		dao.create(tileMatrixSet);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);
		TestCase.assertEquals(newCount, dao.getTileTables().size());
		TestCase.assertTrue(dao.getTileTables().contains(
				contents.getTableName()));

		// Verify saved matrix tile set
		TileMatrixSet queryTileMatrixSet = dao.queryForId(tileMatrixSet
				.getId());
		TestCase.assertEquals(contents.getId(),
				queryTileMatrixSet.getTableName());
		TestCase.assertEquals(contents.getSrsId().longValue(),
				queryTileMatrixSet.getSrsId());
		TestCase.assertEquals(contents.getMinX(),
				queryTileMatrixSet.getMinX());
		TestCase.assertEquals(contents.getMinY(),
				queryTileMatrixSet.getMinY());
		TestCase.assertEquals(contents.getMaxX(),
				queryTileMatrixSet.getMaxX());
		TestCase.assertEquals(contents.getMaxY(),
				queryTileMatrixSet.getMaxY());
		TestCase.assertEquals(contents.getId(), queryTileMatrixSet
				.getContents().getId());
		TestCase.assertEquals(contents.getSrsId().longValue(),
				queryTileMatrixSet.getSrs().getId());
	}
}
 
Example 4
Source File: GeoPackageRepository.java    From geopackage-mapcache-android with MIT License 4 votes vote down vote up
/**
 * Create an alert dialog with a GeoPackage's details for viewing
 *
 * @param geoPackageName
 * @param activity
 * @return
 */
public AlertDialog getGeoPackageDetailDialog(String geoPackageName, Activity activity) {
    StringBuilder databaseInfo = new StringBuilder();
    GeoPackage geoPackage = manager.open(geoPackageName, false);
    try {
        SpatialReferenceSystemDao srsDao = geoPackage
                .getSpatialReferenceSystemDao();

        List<SpatialReferenceSystem> srsList = srsDao.queryForAll();
        databaseInfo.append("Size: ")
                .append(manager.readableSize(geoPackageName));
        databaseInfo.append("\n\nLocation: ").append(
                manager.isExternal(geoPackageName) ? "External" : "Local");
        databaseInfo.append("\nPath: ").append(manager.getPath(geoPackageName));
        databaseInfo.append("\n\nFeature Tables: ").append(
                geoPackage.getFeatureTables().size());
        databaseInfo.append("\nTile Tables: ").append(
                geoPackage.getTileTables().size());
        databaseInfo.append("\n\nSpatial Reference Systems: ").append(
                srsList.size());
        for (SpatialReferenceSystem srs : srsList) {
            databaseInfo.append("\n");
            addSrs(databaseInfo, srs);
        }

    } catch (Exception e) {
        databaseInfo.append(e.getMessage());
    } finally {
        geoPackage.close();
    }
    AlertDialog viewDialog = new AlertDialog.Builder(activity, R.style.AppCompatAlertDialogStyle)
            .setTitle(geoPackageName)
            .setPositiveButton(R.string.button_ok_label,

                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).setMessage(databaseInfo.toString()).create();

    return viewDialog;

}
 
Example 5
Source File: GeometryColumnsUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();
	ContentsDao contentsDao = geoPackage.getContentsDao();
	GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao();

	if (dao.isTableExists()) {

		// Get current count
		long count = dao.countOf();
		TestCase.assertEquals(count, dao.getFeatureTables().size());

		// Retrieve a random srs
		List<SpatialReferenceSystem> results = srsDao.queryForAll();
		SpatialReferenceSystem srs = null;
		if (!results.isEmpty()) {
			int random = (int) (Math.random() * results.size());
			srs = results.get(random);
		}

		// Create a new contents
		Contents contents = new Contents();
		contents.setTableName("test_contents");
		contents.setDataType(ContentsDataType.FEATURES);
		contents.setIdentifier("test_contents");
		contents.setDescription("");
		// contents.setLastChange(new Date());
		contents.setMinX(-180.0);
		contents.setMinY(-90.0);
		contents.setMaxX(180.0);
		contents.setMaxY(90.0);
		contents.setSrs(srs);

		// Create the feature table
		geoPackage.createFeatureTable(TestUtils.buildFeatureTable(
				contents.getTableName(), "geom", GeometryType.GEOMETRY));

		contentsDao.create(contents);

		String columnName = "TEST_COLUMN_NAME";
		GeometryType geometryType = GeometryType.POINT;
		byte z = 2;
		byte m = 2;

		// Create new geometry columns
		GeometryColumns geometryColumns = new GeometryColumns();
		geometryColumns.setContents(contents);
		geometryColumns.setColumnName(columnName);
		geometryColumns.setGeometryType(geometryType);
		geometryColumns.setSrs(contents.getSrs());
		geometryColumns.setZ(z);
		geometryColumns.setM(m);
		dao.create(geometryColumns);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);
		TestCase.assertEquals(newCount, dao.getFeatureTables().size());
		TestCase.assertTrue(dao.getFeatureTables().contains(
				contents.getTableName()));

		// Verify saved geometry columns
		GeometryColumns queryGeometryColumns = dao
				.queryForId(geometryColumns.getId());
		TestCase.assertEquals(contents.getId(),
				queryGeometryColumns.getTableName());
		TestCase.assertEquals(columnName,
				queryGeometryColumns.getColumnName());
		TestCase.assertEquals(geometryType,
				queryGeometryColumns.getGeometryType());
		TestCase.assertEquals(contents.getSrsId().longValue(),
				queryGeometryColumns.getSrsId());
		TestCase.assertEquals(z, queryGeometryColumns.getZ());
		TestCase.assertEquals(m, queryGeometryColumns.getM());
		TestCase.assertEquals(contents.getId(), queryGeometryColumns
				.getContents().getId());
		TestCase.assertEquals(contents.getSrsId().longValue(),
				queryGeometryColumns.getSrs().getId());
	}
}
 
Example 6
Source File: TileMatrixUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();
	ContentsDao contentsDao = geoPackage.getContentsDao();
	TileMatrixDao dao = geoPackage.getTileMatrixDao();

	if (dao.isTableExists()) {

		// Get current count
		long count = dao.countOf();

		// Retrieve a random srs
		List<SpatialReferenceSystem> results = srsDao.queryForAll();
		SpatialReferenceSystem srs = null;
		if (!results.isEmpty()) {
			int random = (int) (Math.random() * results.size());
			srs = results.get(random);
		}

		// Create a new contents
		Contents contents = new Contents();
		contents.setTableName("test_contents");
		contents.setDataType(ContentsDataType.TILES);
		contents.setIdentifier("test_contents");
		contents.setDescription("");
		// contents.setLastChange(new Date());
		contents.setMinX(-180.0);
		contents.setMinY(-90.0);
		contents.setMaxX(180.0);
		contents.setMaxY(90.0);
		contents.setSrs(srs);

		// Create the user tile table
		geoPackage.createTileTable(TestUtils.buildTileTable(contents
				.getTableName()));

		contentsDao.create(contents);

		// Create new matrix tile
		int zoom = 3;
		int matrixWidth = 4;
		int matrixHeight = 5;
		int tileWidth = 128;
		int tileHeight = 256;
		double pixelXSize = 889.5;
		double pixelYSize = 900.1;

		TileMatrix tileMatrix = new TileMatrix();
		tileMatrix.setContents(contents);
		tileMatrix.setZoomLevel(zoom);
		tileMatrix.setMatrixWidth(matrixWidth);
		tileMatrix.setMatrixHeight(matrixHeight);
		tileMatrix.setTileWidth(tileWidth);
		tileMatrix.setTileHeight(tileHeight);
		tileMatrix.setPixelXSize(pixelXSize);
		tileMatrix.setPixelYSize(pixelYSize);
		dao.create(tileMatrix);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);

		// Verify saved matrix tile
		TileMatrix queryTileMatrix = dao.queryForId(tileMatrix.getId());
		TestCase.assertEquals(contents.getId(),
				queryTileMatrix.getTableName());
		TestCase.assertEquals(zoom, queryTileMatrix.getZoomLevel());
		TestCase.assertEquals(matrixWidth, queryTileMatrix.getMatrixWidth());
		TestCase.assertEquals(matrixHeight,
				queryTileMatrix.getMatrixHeight());
		TestCase.assertEquals(tileWidth, queryTileMatrix.getTileWidth());
		TestCase.assertEquals(tileHeight, queryTileMatrix.getTileHeight());
		TestCase.assertEquals(pixelXSize, queryTileMatrix.getPixelXSize());
		TestCase.assertEquals(pixelYSize, queryTileMatrix.getPixelYSize());
		TestCase.assertEquals(contents.getId(), queryTileMatrix
				.getContents().getId());
	}
}
 
Example 7
Source File: TileMatrixSetUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test create
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testCreate(GeoPackage geoPackage) throws SQLException {

	SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();
	ContentsDao contentsDao = geoPackage.getContentsDao();
	TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();

	if (dao.isTableExists()) {

		// Get current count
		long count = dao.countOf();
		TestCase.assertEquals(count, dao.getTileTables().size());

		// Retrieve a random srs
		List<SpatialReferenceSystem> results = srsDao.queryForAll();
		SpatialReferenceSystem srs = null;
		if (!results.isEmpty()) {
			int random = (int) (Math.random() * results.size());
			srs = results.get(random);
		}

		// Create a new contents
		Contents contents = new Contents();
		contents.setTableName("test_contents");
		contents.setDataType(ContentsDataType.TILES);
		contents.setIdentifier("test_contents");
		contents.setDescription("");
		// contents.setLastChange(new Date());
		contents.setMinX(-180.0);
		contents.setMinY(-90.0);
		contents.setMaxX(180.0);
		contents.setMaxY(90.0);
		contents.setSrs(srs);

		// Create the user tile table
		geoPackage.createTileTable(TestUtils.buildTileTable(contents
				.getTableName()));

		contentsDao.create(contents);

		// Create new matrix tile set
		TileMatrixSet tileMatrixSet = new TileMatrixSet();
		tileMatrixSet.setContents(contents);
		tileMatrixSet.setSrs(contents.getSrs());
		tileMatrixSet.setMinX(contents.getMinX());
		tileMatrixSet.setMinY(contents.getMinY());
		tileMatrixSet.setMaxX(contents.getMaxX());
		tileMatrixSet.setMaxY(contents.getMaxY());
		dao.create(tileMatrixSet);

		// Verify count
		long newCount = dao.countOf();
		TestCase.assertEquals(count + 1, newCount);
		TestCase.assertEquals(newCount, dao.getTileTables().size());
		TestCase.assertTrue(dao.getTileTables().contains(
				contents.getTableName()));

		// Verify saved matrix tile set
		TileMatrixSet queryTileMatrixSet = dao.queryForId(tileMatrixSet
				.getId());
		TestCase.assertEquals(contents.getId(),
				queryTileMatrixSet.getTableName());
		TestCase.assertEquals(contents.getSrsId().longValue(),
				queryTileMatrixSet.getSrsId());
		TestCase.assertEquals(contents.getMinX(),
				queryTileMatrixSet.getMinX());
		TestCase.assertEquals(contents.getMinY(),
				queryTileMatrixSet.getMinY());
		TestCase.assertEquals(contents.getMaxX(),
				queryTileMatrixSet.getMaxX());
		TestCase.assertEquals(contents.getMaxY(),
				queryTileMatrixSet.getMaxY());
		TestCase.assertEquals(contents.getId(), queryTileMatrixSet
				.getContents().getId());
		TestCase.assertEquals(contents.getSrsId().longValue(),
				queryTileMatrixSet.getSrs().getId());
	}
}