_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q176000
GoogleAPIGeoPackageTileRetriever.retrieveTileRow
test
private TileRow retrieveTileRow(int x, int y, int zoom) { return tileDao.queryForTile(x, y, zoom); }
java
{ "resource": "" }
q176001
CoverageData.getCoverageData
test
public static CoverageData<?> getCoverageData(GeoPackage geoPackage, TileDao tileDao, Integer width, Integer height, Projection requestProjection) { TileMatrixSet tileMatrixSet = tileDao.getTileMatrixSet(); GriddedCoverageDao griddedCoverageDao = geoPackage .getGriddedCoverageDao(); GriddedCoverage griddedCoverage = null; try { if (griddedCoverageDao.isTableExists()) { griddedCoverage = griddedCoverageDao.query(tileMatrixSet); } } catch (SQLException e) { throw new GeoPackageException( "Failed to get Gridded Coverage for table name: " + tileMatrixSet.getTableName(), e); } CoverageData<?> coverageData = null; GriddedCoverageDataType dataType = griddedCoverage.getDataType(); switch (dataType) { case INTEGER: coverageData = new CoverageDataPng(geoPackage, tileDao, width, height, requestProjection); break; case FLOAT: coverageData = new CoverageDataTiff(geoPackage, tileDao, width, height, requestProjection); break; default: throw new GeoPackageException( "Unsupported Gridded Coverage Data Type: " + dataType); } return coverageData; }
java
{ "resource": "" }
q176002
CoverageData.getCoverageData
test
public static CoverageData<?> getCoverageData(GeoPackage geoPackage, TileDao tileDao) { return getCoverageData(geoPackage, tileDao, null, null, tileDao.getProjection()); }
java
{ "resource": "" }
q176003
CoverageData.getCoverageData
test
public static CoverageData<?> getCoverageData(GeoPackage geoPackage, TileDao tileDao, Projection requestProjection) { return getCoverageData(geoPackage, tileDao, null, null, requestProjection); }
java
{ "resource": "" }
q176004
CoverageData.getResults
test
private CoverageDataTileMatrixResults getResults(CoverageDataRequest request, BoundingBox requestProjectedBoundingBox, int overlappingPixels) { // Try to get the coverage data from the current zoom level TileMatrix tileMatrix = getTileMatrix(request); CoverageDataTileMatrixResults results = null; if (tileMatrix != null) { results = getResults(requestProjectedBoundingBox, tileMatrix, overlappingPixels); // Try to zoom in or out to find a matching coverage data if (results == null) { results = getResultsZoom(requestProjectedBoundingBox, tileMatrix, overlappingPixels); } } return results; }
java
{ "resource": "" }
q176005
CoverageData.getResultsZoom
test
private CoverageDataTileMatrixResults getResultsZoom( BoundingBox requestProjectedBoundingBox, TileMatrix tileMatrix, int overlappingPixels) { CoverageDataTileMatrixResults results = null; if (zoomIn && zoomInBeforeOut) { results = getResultsZoomIn(requestProjectedBoundingBox, tileMatrix, overlappingPixels); } if (results == null && zoomOut) { results = getResultsZoomOut(requestProjectedBoundingBox, tileMatrix, overlappingPixels); } if (results == null && zoomIn && !zoomInBeforeOut) { results = getResultsZoomIn(requestProjectedBoundingBox, tileMatrix, overlappingPixels); } return results; }
java
{ "resource": "" }
q176006
CoverageData.getResultsZoomIn
test
private CoverageDataTileMatrixResults getResultsZoomIn( BoundingBox requestProjectedBoundingBox, TileMatrix tileMatrix, int overlappingPixels) { CoverageDataTileMatrixResults results = null; for (long zoomLevel = tileMatrix.getZoomLevel() + 1; zoomLevel <= tileDao .getMaxZoom(); zoomLevel++) { TileMatrix zoomTileMatrix = tileDao.getTileMatrix(zoomLevel); if (zoomTileMatrix != null) { results = getResults(requestProjectedBoundingBox, zoomTileMatrix, overlappingPixels); if (results != null) { break; } } } return results; }
java
{ "resource": "" }
q176007
CoverageData.getResultsZoomOut
test
private CoverageDataTileMatrixResults getResultsZoomOut( BoundingBox requestProjectedBoundingBox, TileMatrix tileMatrix, int overlappingPixels) { CoverageDataTileMatrixResults results = null; for (long zoomLevel = tileMatrix.getZoomLevel() - 1; zoomLevel >= tileDao .getMinZoom(); zoomLevel--) { TileMatrix zoomTileMatrix = tileDao.getTileMatrix(zoomLevel); if (zoomTileMatrix != null) { results = getResults(requestProjectedBoundingBox, zoomTileMatrix, overlappingPixels); if (results != null) { break; } } } return results; }
java
{ "resource": "" }
q176008
CoverageData.getTileMatrix
test
private TileMatrix getTileMatrix(CoverageDataRequest request) { TileMatrix tileMatrix = null; // Check if the request overlaps coverage data bounding box if (request.overlap(coverageBoundingBox) != null) { // Get the tile distance BoundingBox projectedBoundingBox = request .getProjectedBoundingBox(); double distanceWidth = projectedBoundingBox.getMaxLongitude() - projectedBoundingBox.getMinLongitude(); double distanceHeight = projectedBoundingBox.getMaxLatitude() - projectedBoundingBox.getMinLatitude(); // Get the zoom level to request based upon the tile size Long zoomLevel = tileDao.getClosestZoomLevel(distanceWidth, distanceHeight); // If there is a matching zoom level if (zoomLevel != null) { tileMatrix = tileDao.getTileMatrix(zoomLevel); } } return tileMatrix; }
java
{ "resource": "" }
q176009
CoverageData.getValue
test
public double getValue(TileRow tileRow, int x, int y) { GriddedTile griddedTile = getGriddedTile(tileRow.getId()); double value = getValue(griddedTile, tileRow, x, y); return value; }
java
{ "resource": "" }
q176010
Icons.setIcon
test
public void setIcon(IconRow iconRow, GeometryType geometryType) { if (geometryType != null) { if (iconRow != null) { icons.put(geometryType, iconRow); } else { icons.remove(geometryType); } } else { defaultIcon = iconRow; } }
java
{ "resource": "" }
q176011
Icons.getIcon
test
public IconRow getIcon(GeometryType geometryType) { IconRow iconRow = null; if (geometryType != null && !icons.isEmpty()) { List<GeometryType> geometryTypes = GeometryUtils .parentHierarchy(geometryType); geometryTypes.add(0, geometryType); for (GeometryType type : geometryTypes) { iconRow = icons.get(type); if (iconRow != null) { break; } } } if (iconRow == null) { iconRow = defaultIcon; } if (iconRow == null && geometryType == null && icons.size() == 1) { iconRow = icons.values().iterator().next(); } return iconRow; }
java
{ "resource": "" }
q176012
GeoPackageDatabase.openOrGetBindingsDb
test
public org.sqlite.database.sqlite.SQLiteDatabase openOrGetBindingsDb() { if (bindingsDb == null) { synchronized (db) { if (bindingsDb == null) { System.loadLibrary("sqliteX"); bindingsDb = org.sqlite.database.sqlite.SQLiteDatabase.openDatabase(db.getPath(), null, org.sqlite.database.sqlite.SQLiteDatabase.OPEN_READWRITE); } } } return bindingsDb; }
java
{ "resource": "" }
q176013
BitmapConverter.toBitmap
test
public static Bitmap toBitmap(byte[] bytes, Options options) { Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); return bitmap; }
java
{ "resource": "" }
q176014
BitmapConverter.toBytes
test
public static byte[] toBytes(Bitmap bitmap, CompressFormat format, int quality) throws IOException { byte[] bytes = null; ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); try { bitmap.compress(format, quality, byteStream); bytes = byteStream.toByteArray(); } finally { byteStream.close(); } return bytes; }
java
{ "resource": "" }
q176015
TableMetadataDataSource.create
test
public void create(TableMetadata metadata) { ContentValues values = new ContentValues(); values.put(TableMetadata.COLUMN_GEOPACKAGE_ID, metadata.getGeoPackageId()); values.put(TableMetadata.COLUMN_TABLE_NAME, metadata.getTableName()); values.put(TableMetadata.COLUMN_LAST_INDEXED, metadata.getLastIndexed()); long insertId = db.insert( TableMetadata.TABLE_NAME, null, values); if (insertId == -1) { throw new GeoPackageException( "Failed to insert table metadata. GeoPackage Id: " + metadata.getGeoPackageId() + ", Table Name: " + metadata.getTableName() + ", Last Indexed: " + metadata.getLastIndexed()); } }
java
{ "resource": "" }
q176016
TableMetadataDataSource.delete
test
public boolean delete(long geoPackageId, String tableName) { GeometryMetadataDataSource geomDs = new GeometryMetadataDataSource(db); geomDs.delete(geoPackageId, tableName); String whereClause = TableMetadata.COLUMN_GEOPACKAGE_ID + " = ? AND " + TableMetadata.COLUMN_TABLE_NAME + " = ?"; String[] whereArgs = new String[]{String.valueOf(geoPackageId), tableName}; int deleteCount = db.delete( TableMetadata.TABLE_NAME, whereClause, whereArgs); return deleteCount > 0; }
java
{ "resource": "" }
q176017
TableMetadataDataSource.getOrCreate
test
public TableMetadata getOrCreate(String geoPackage, String tableName) { GeoPackageMetadataDataSource ds = new GeoPackageMetadataDataSource(db); GeoPackageMetadata geoPackageMetadata = ds.getOrCreate(geoPackage); TableMetadata metadata = get(geoPackageMetadata.getId(), tableName); if (metadata == null) { metadata = new TableMetadata(); metadata.setGeoPackageId(geoPackageMetadata.getId()); metadata.setTableName(tableName); create(metadata); } return metadata; }
java
{ "resource": "" }
q176018
TableMetadataDataSource.getGeoPackageId
test
public long getGeoPackageId(String geoPackage) { long id = -1; GeoPackageMetadataDataSource ds = new GeoPackageMetadataDataSource(db); GeoPackageMetadata metadata = ds.get(geoPackage); if (metadata != null) { id = metadata.getId(); } return id; }
java
{ "resource": "" }
q176019
TableMetadataDataSource.createTableMetadata
test
private TableMetadata createTableMetadata(Cursor cursor) { TableMetadata metadata = new TableMetadata(); metadata.setGeoPackageId(cursor.getLong(0)); metadata.setTableName(cursor.getString(1)); if (!cursor.isNull(2)) { metadata.setLastIndexed(cursor.getLong(2)); } return metadata; }
java
{ "resource": "" }
q176020
RTreeIndexTableDao.create
test
public Extensions create() { Extensions extension = null; if (!has()) { extension = rTree.create(featureDao.getTable()); if (progress != null) { progress.addProgress(count()); } } return extension; }
java
{ "resource": "" }
q176021
RTreeIndexTableDao.getFeatureRow
test
public FeatureRow getFeatureRow(UserCustomCursor cursor) { RTreeIndexTableRow row = getRow(cursor); return getFeatureRow(row); }
java
{ "resource": "" }
q176022
RTreeIndexTableDao.rawQuery
test
public UserCustomCursor rawQuery(String sql, String[] selectionArgs) { validateRTree(); Cursor cursor = database.rawQuery(sql, selectionArgs); UserCustomCursor customCursor = new UserCustomCursor(getTable(), cursor); return customCursor; }
java
{ "resource": "" }
q176023
RTreeIndexTableDao.query
test
public UserCustomCursor query(BoundingBox boundingBox, Projection projection) { BoundingBox featureBoundingBox = projectBoundingBox(boundingBox, projection); return query(featureBoundingBox); }
java
{ "resource": "" }
q176024
RTreeIndexTableDao.query
test
public UserCustomCursor query(GeometryEnvelope envelope) { return query(envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(), envelope.getMaxY()); }
java
{ "resource": "" }
q176025
RTreeIndexTableDao.count
test
public long count(GeometryEnvelope envelope) { return count(envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(), envelope.getMaxY()); }
java
{ "resource": "" }
q176026
RTreeIndexTableDao.query
test
public UserCustomCursor query(double minX, double minY, double maxX, double maxY) { String where = buildWhere(minX, minY, maxX, maxY); String[] whereArgs = buildWhereArgs(minX, minY, maxX, maxY); return query(where, whereArgs); }
java
{ "resource": "" }
q176027
RTreeIndexTableDao.buildWhere
test
private String buildWhere(double minX, double minY, double maxX, double maxY) { StringBuilder where = new StringBuilder(); where.append(buildWhere(RTreeIndexExtension.COLUMN_MIN_X, maxX, "<=")); where.append(" AND "); where.append(buildWhere(RTreeIndexExtension.COLUMN_MIN_Y, maxY, "<=")); where.append(" AND "); where.append(buildWhere(RTreeIndexExtension.COLUMN_MAX_X, minX, ">=")); where.append(" AND "); where.append(buildWhere(RTreeIndexExtension.COLUMN_MAX_Y, minY, ">=")); return where.toString(); }
java
{ "resource": "" }
q176028
ManualFeatureQuery.query
test
public ManualFeatureQueryResults query(BoundingBox boundingBox, Projection projection) { BoundingBox featureBoundingBox = featureDao.projectBoundingBox( boundingBox, projection); return query(featureBoundingBox); }
java
{ "resource": "" }
q176029
ManualFeatureQuery.count
test
public long count(BoundingBox boundingBox, Projection projection) { BoundingBox featureBoundingBox = featureDao.projectBoundingBox( boundingBox, projection); return count(featureBoundingBox); }
java
{ "resource": "" }
q176030
ManualFeatureQuery.query
test
public ManualFeatureQueryResults query(GeometryEnvelope envelope) { return query(envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(), envelope.getMaxY()); }
java
{ "resource": "" }
q176031
ManualFeatureQuery.query
test
public ManualFeatureQueryResults query(double minX, double minY, double maxX, double maxY) { List<Long> featureIds = new ArrayList<>(); long offset = 0; boolean hasResults = true; minX -= tolerance; maxX += tolerance; minY -= tolerance; maxY += tolerance; while (hasResults) { hasResults = false; FeatureCursor featureCursor = featureDao.queryForChunk(chunkLimit, offset); try { while (featureCursor.moveToNext()) { hasResults = true; FeatureRow featureRow = featureCursor.getRow(); GeometryEnvelope envelope = featureRow .getGeometryEnvelope(); if (envelope != null) { double minXMax = Math.max(minX, envelope.getMinX()); double maxXMin = Math.min(maxX, envelope.getMaxX()); double minYMax = Math.max(minY, envelope.getMinY()); double maxYMin = Math.min(maxY, envelope.getMaxY()); if (minXMax <= maxXMin && minYMax <= maxYMin) { featureIds.add(featureRow.getId()); } } } } finally { featureCursor.close(); } offset += chunkLimit; } ManualFeatureQueryResults results = new ManualFeatureQueryResults( featureDao, featureIds); return results; }
java
{ "resource": "" }
q176032
ManualFeatureQuery.count
test
public long count(double minX, double minY, double maxX, double maxY) { return query(minX, minY, maxX, maxY).count(); }
java
{ "resource": "" }
q176033
MediaRow.setData
test
public void setData(Bitmap bitmap, Bitmap.CompressFormat format) throws IOException { setData(bitmap, format, 100); }
java
{ "resource": "" }
q176034
MediaRow.setData
test
public void setData(Bitmap bitmap, Bitmap.CompressFormat format, int quality) throws IOException { setData(BitmapConverter.toBytes(bitmap, format, quality)); }
java
{ "resource": "" }
q176035
TileGenerator.setBitmapCompressionConfig
test
public void setBitmapCompressionConfig(Config config) { if (options == null) { options = new Options(); } options.inPreferredConfig = config; }
java
{ "resource": "" }
q176036
TileGenerator.getTileCount
test
public int getTileCount() { if (tileCount == null) { long count = 0; boolean degrees = projection.isUnit(Units.DEGREES); ProjectionTransform transformToWebMercator = null; if (!degrees) { transformToWebMercator = projection.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR); } for (int zoom = minZoom; zoom <= maxZoom; zoom++) { BoundingBox expandedBoundingBox = getBoundingBox(zoom); // Get the tile grid that includes the entire bounding box TileGrid tileGrid = null; if (degrees) { tileGrid = TileBoundingBoxUtils.getTileGridWGS84(expandedBoundingBox, zoom); } else { tileGrid = TileBoundingBoxUtils.getTileGrid(expandedBoundingBox.transform(transformToWebMercator), zoom); } count += tileGrid.count(); tileGrids.put(zoom, tileGrid); tileBounds.put(zoom, expandedBoundingBox); } tileCount = (int) Math.min(count, Integer.MAX_VALUE); } return tileCount; }
java
{ "resource": "" }
q176037
TileGenerator.adjustBounds
test
private void adjustBounds(BoundingBox boundingBox, int zoom) { // Google Tile Format if (googleTiles) { adjustGoogleBounds(); } else if (projection.isUnit(Units.DEGREES)) { adjustGeoPackageBoundsWGS84(boundingBox, zoom); } else { adjustGeoPackageBounds(boundingBox, zoom); } }
java
{ "resource": "" }
q176038
TileGenerator.adjustGoogleBounds
test
private void adjustGoogleBounds() { // Set the tile matrix set bounding box to be the world BoundingBox standardWgs84Box = new BoundingBox(-ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH, ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE, ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH, ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE); ProjectionTransform wgs84ToWebMercatorTransform = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM) .getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR); tileGridBoundingBox = standardWgs84Box.transform(wgs84ToWebMercatorTransform); }
java
{ "resource": "" }
q176039
TileGenerator.adjustGeoPackageBoundsWGS84
test
private void adjustGeoPackageBoundsWGS84(BoundingBox boundingBox, int zoom) { // Get the fitting tile grid and determine the bounding box that fits it TileGrid tileGrid = TileBoundingBoxUtils.getTileGridWGS84(boundingBox, zoom); tileGridBoundingBox = TileBoundingBoxUtils.getWGS84BoundingBox(tileGrid, zoom); matrixWidth = tileGrid.getMaxX() + 1 - tileGrid.getMinX(); matrixHeight = tileGrid.getMaxY() + 1 - tileGrid.getMinY(); }
java
{ "resource": "" }
q176040
TileGenerator.adjustGeoPackageBounds
test
private void adjustGeoPackageBounds( BoundingBox requestWebMercatorBoundingBox, int zoom) { // Get the fitting tile grid and determine the bounding box that // fits it TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid( requestWebMercatorBoundingBox, zoom); tileGridBoundingBox = TileBoundingBoxUtils.getWebMercatorBoundingBox(tileGrid, zoom); matrixWidth = tileGrid.getMaxX() + 1 - tileGrid.getMinX(); matrixHeight = tileGrid.getMaxY() + 1 - tileGrid.getMinY(); }
java
{ "resource": "" }
q176041
TileDao.getBoundingBox
test
public BoundingBox getBoundingBox(long zoomLevel) { BoundingBox boundingBox = null; TileMatrix tileMatrix = getTileMatrix(zoomLevel); if (tileMatrix != null) { TileGrid tileGrid = queryForTileGrid(zoomLevel); if (tileGrid != null) { BoundingBox matrixSetBoundingBox = getBoundingBox(); boundingBox = TileBoundingBoxUtils.getBoundingBox( matrixSetBoundingBox, tileMatrix, tileGrid); } } return boundingBox; }
java
{ "resource": "" }
q176042
TileDao.getTileGrid
test
public TileGrid getTileGrid(long zoomLevel) { TileGrid tileGrid = null; TileMatrix tileMatrix = getTileMatrix(zoomLevel); if (tileMatrix != null) { tileGrid = new TileGrid(0, 0, tileMatrix.getMatrixWidth() - 1, tileMatrix.getMatrixHeight() - 1); } return tileGrid; }
java
{ "resource": "" }
q176043
TileDao.queryForTile
test
public TileRow queryForTile(long column, long row, long zoomLevel) { Map<String, Object> fieldValues = new HashMap<String, Object>(); fieldValues.put(TileTable.COLUMN_TILE_COLUMN, column); fieldValues.put(TileTable.COLUMN_TILE_ROW, row); fieldValues.put(TileTable.COLUMN_ZOOM_LEVEL, zoomLevel); TileCursor cursor = queryForFieldValues(fieldValues); TileRow tileRow = null; try { if (cursor.moveToNext()) { tileRow = cursor.getRow(); } } finally { cursor.close(); } return tileRow; }
java
{ "resource": "" }
q176044
TileDao.queryForTileDescending
test
public TileCursor queryForTileDescending(long zoomLevel) { return queryForEq(TileTable.COLUMN_ZOOM_LEVEL, zoomLevel, null, null, TileTable.COLUMN_TILE_ROW + " DESC, " + TileTable.COLUMN_TILE_COLUMN + " DESC"); }
java
{ "resource": "" }
q176045
TileDao.getClosestZoomLevel
test
public Long getClosestZoomLevel(double length) { Long zoomLevel = TileDaoUtils.getClosestZoomLevel(widths, heights, tileMatrices, length); return zoomLevel; }
java
{ "resource": "" }
q176046
TileDao.getApproximateZoomLevel
test
public Long getApproximateZoomLevel(double length) { Long zoomLevel = TileDaoUtils.getApproximateZoomLevel(widths, heights, tileMatrices, length); return zoomLevel; }
java
{ "resource": "" }
q176047
TileDao.queryForTileGrid
test
public TileGrid queryForTileGrid(long zoomLevel) { String where = buildWhere(TileTable.COLUMN_ZOOM_LEVEL, zoomLevel); String[] whereArgs = buildWhereArgs(new Object[]{zoomLevel}); Integer minX = min(TileTable.COLUMN_TILE_COLUMN, where, whereArgs); Integer maxX = max(TileTable.COLUMN_TILE_COLUMN, where, whereArgs); Integer minY = min(TileTable.COLUMN_TILE_ROW, where, whereArgs); Integer maxY = max(TileTable.COLUMN_TILE_ROW, where, whereArgs); TileGrid tileGrid = null; if (minX != null && maxX != null && minY != null && maxY != null) { tileGrid = new TileGrid(minX, minY, maxX, maxY); } return tileGrid; }
java
{ "resource": "" }
q176048
TileDao.deleteTile
test
public int deleteTile(long column, long row, long zoomLevel) { StringBuilder where = new StringBuilder(); where.append(buildWhere(TileTable.COLUMN_ZOOM_LEVEL, zoomLevel)); where.append(" AND "); where.append(buildWhere(TileTable.COLUMN_TILE_COLUMN, column)); where.append(" AND "); where.append(buildWhere(TileTable.COLUMN_TILE_ROW, row)); String[] whereArgs = buildWhereArgs(new Object[]{zoomLevel, column, row}); int deleted = delete(where.toString(), whereArgs); return deleted; }
java
{ "resource": "" }
q176049
TileDao.count
test
public int count(long zoomLevel) { String where = buildWhere(TileTable.COLUMN_ZOOM_LEVEL, zoomLevel); String[] whereArgs = buildWhereArgs(zoomLevel); return count(where, whereArgs); }
java
{ "resource": "" }
q176050
TileDao.isGoogleTiles
test
public boolean isGoogleTiles() { // Convert the bounding box to wgs84 BoundingBox boundingBox = tileMatrixSet.getBoundingBox(); BoundingBox wgs84BoundingBox = boundingBox.transform( projection.getTransformation( ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM)); boolean googleTiles = false; // Verify the bounds are the entire world if (wgs84BoundingBox.getMinLatitude() <= ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE && wgs84BoundingBox.getMaxLatitude() >= ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE && wgs84BoundingBox.getMinLongitude() <= -ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH && wgs84BoundingBox.getMaxLongitude() >= ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH) { googleTiles = true; // Verify each tile matrix is the correct width and height for (TileMatrix tileMatrix : tileMatrices) { long zoomLevel = tileMatrix.getZoomLevel(); long tilesPerSide = TileBoundingBoxUtils .tilesPerSide((int) zoomLevel); if (tileMatrix.getMatrixWidth() != tilesPerSide || tileMatrix.getMatrixHeight() != tilesPerSide) { googleTiles = false; break; } } } return googleTiles; }
java
{ "resource": "" }
q176051
CoverageDataTiff.getPixelValue
test
public float getPixelValue(byte[] imageBytes, int x, int y) { TIFFImage tiffImage = TiffReader.readTiff(imageBytes); FileDirectory directory = tiffImage.getFileDirectory(); validateImageType(directory); Rasters rasters = directory.readRasters(); float pixelValue = rasters.getFirstPixelSample(x, y).floatValue(); return pixelValue; }
java
{ "resource": "" }
q176052
CoverageDataTiff.getPixelValues
test
public float[] getPixelValues(byte[] imageBytes) { TIFFImage tiffImage = TiffReader.readTiff(imageBytes); FileDirectory directory = tiffImage.getFileDirectory(); validateImageType(directory); Rasters rasters = directory.readRasters(); float[] pixels = new float[rasters.getWidth() * rasters.getHeight()]; for (int y = 0; y < rasters.getHeight(); y++) { for (int x = 0; x < rasters.getWidth(); x++) { int index = rasters.getSampleIndex(x, y); pixels[index] = rasters.getPixelSample(0, x, y).floatValue(); } } return pixels; }
java
{ "resource": "" }
q176053
CoverageDataTiff.validateImageType
test
public static void validateImageType(FileDirectory directory) { if (directory == null) { throw new GeoPackageException("The image is null"); } int samplesPerPixel = directory.getSamplesPerPixel(); Integer bitsPerSample = null; if (directory.getBitsPerSample() != null && !directory.getBitsPerSample().isEmpty()) { bitsPerSample = directory.getBitsPerSample().get(0); } Integer sampleFormat = null; if (directory.getSampleFormat() != null && !directory.getSampleFormat().isEmpty()) { sampleFormat = directory.getSampleFormat().get(0); } if (samplesPerPixel != SAMPLES_PER_PIXEL || bitsPerSample == null || bitsPerSample != BITS_PER_SAMPLE || sampleFormat == null || sampleFormat != TiffConstants.SAMPLE_FORMAT_FLOAT) { throw new GeoPackageException( "The coverage data tile is expected to be a single sample 32 bit float. Samples Per Pixel: " + samplesPerPixel + ", Bits Per Sample: " + bitsPerSample + ", Sample Format: " + sampleFormat); } }
java
{ "resource": "" }
q176054
CoverageDataTiff.createImage
test
public CoverageDataTiffImage createImage(int tileWidth, int tileHeight) { Rasters rasters = new Rasters(tileWidth, tileHeight, 1, BITS_PER_SAMPLE, TiffConstants.SAMPLE_FORMAT_FLOAT); int rowsPerStrip = rasters.calculateRowsPerStrip(TiffConstants.PLANAR_CONFIGURATION_CHUNKY); FileDirectory fileDirectory = new FileDirectory(); fileDirectory.setImageWidth(tileWidth); fileDirectory.setImageHeight(tileHeight); fileDirectory.setBitsPerSample(BITS_PER_SAMPLE); fileDirectory.setCompression(TiffConstants.COMPRESSION_NO); fileDirectory.setPhotometricInterpretation(TiffConstants.PHOTOMETRIC_INTERPRETATION_BLACK_IS_ZERO); fileDirectory.setSamplesPerPixel(SAMPLES_PER_PIXEL); fileDirectory.setRowsPerStrip(rowsPerStrip); fileDirectory.setPlanarConfiguration(TiffConstants.PLANAR_CONFIGURATION_CHUNKY); fileDirectory.setSampleFormat(TiffConstants.SAMPLE_FORMAT_FLOAT); fileDirectory.setWriteRasters(rasters); CoverageDataTiffImage image = new CoverageDataTiffImage(fileDirectory); return image; }
java
{ "resource": "" }
q176055
CoverageDataTiff.setPixelValue
test
public void setPixelValue(CoverageDataTiffImage image, int x, int y, float pixelValue) { image.getRasters().setFirstPixelSample(x, y, pixelValue); }
java
{ "resource": "" }
q176056
GeoPackageCache.getOrOpen
test
private GeoPackage getOrOpen(String name, boolean writable, boolean cache) { GeoPackage geoPackage = get(name); if (geoPackage == null) { geoPackage = manager.open(name, writable); if (cache) { add(geoPackage); } } return geoPackage; }
java
{ "resource": "" }
q176057
UserCursor.getCurrentRow
test
private TRow getCurrentRow() { TRow row = null; if (table != null) { int[] columnTypes = new int[table.columnCount()]; Object[] values = new Object[table.columnCount()]; boolean valid = true; for (TColumn column : table.getColumns()) { int index = column.getIndex(); int columnType = getType(index); if (column.isPrimaryKey() && columnType == FIELD_TYPE_NULL) { valid = false; } columnTypes[index] = columnType; values[index] = getValue(column); } row = getRow(columnTypes, values); if (!valid) { invalidPositions.add(getPosition()); row.setValid(false); } } return row; }
java
{ "resource": "" }
q176058
UserCursor.moveToNextInvalid
test
private boolean moveToNextInvalid() { boolean hasNext = false; // If requery has not been performed, a requery dao has been set, and there are invalid positions if (invalidCursor == null && dao != null && hasInvalidPositions()) { // Close the original cursor when performing an invalid cursor query super.close(); // Set the blob columns to return as null List<TColumn> blobColumns = dao.getTable().columnsOfType(GeoPackageDataType.BLOB); String[] columnsAs = dao.buildColumnsAsNull(blobColumns); query.set(UserQueryParamType.COLUMNS_AS, columnsAs); // Query without blob columns and create an invalid cursor UserCursor<TColumn, TTable, TRow> requeryCursor = dao.query(query); invalidCursor = createInvalidCursor(dao, requeryCursor, getInvalidPositions(), blobColumns); } if (invalidCursor != null) { hasNext = invalidCursor.moveToNext(); } return hasNext; }
java
{ "resource": "" }
q176059
StyleMappingDao.queryByBaseFeatureId
test
public List<StyleMappingRow> queryByBaseFeatureId(long id) { List<StyleMappingRow> rows = new ArrayList<>(); UserCustomCursor cursor = queryByBaseId(id); try { while (cursor.moveToNext()) { rows.add(getRow(cursor)); } } finally { cursor.close(); } return rows; }
java
{ "resource": "" }
q176060
StyleMappingDao.deleteByBaseId
test
public int deleteByBaseId(long id, GeometryType geometryType) { String geometryTypeName = null; if (geometryType != null) { geometryTypeName = geometryType.getName(); } StringBuilder where = new StringBuilder(); where.append(buildWhere(StyleMappingTable.COLUMN_BASE_ID, id)); where.append(" AND "); where.append(buildWhere(StyleMappingTable.COLUMN_GEOMETRY_TYPE_NAME, geometryTypeName)); List<Object> whereArguments = new ArrayList<>(); whereArguments.add(id); if (geometryTypeName != null) { whereArguments.add(geometryTypeName); } String[] whereArgs = buildWhereArgs(whereArguments); int deleted = delete(where.toString(), whereArgs); return deleted; }
java
{ "resource": "" }
q176061
TileBoundingBoxAndroidUtils.getRectangle
test
public static Rect getRectangle(long width, long height, BoundingBox boundingBox, BoundingBox boundingBoxSection) { RectF rectF = getFloatRectangle(width, height, boundingBox, boundingBoxSection); Rect rect = new Rect(Math.round(rectF.left), Math.round(rectF.top), Math.round(rectF.right), Math.round(rectF.bottom)); return rect; }
java
{ "resource": "" }
q176062
TileBoundingBoxAndroidUtils.getRoundedFloatRectangle
test
public static RectF getRoundedFloatRectangle(long width, long height, BoundingBox boundingBox, BoundingBox boundingBoxSection) { Rect rect = getRectangle(width, height, boundingBox, boundingBoxSection); RectF rectF = new RectF(rect); return rectF; }
java
{ "resource": "" }
q176063
GeoPackageManagerImpl.deleteMissingDatabases
test
private List<String> deleteMissingDatabases(List<String> databases) { List<String> filesExist = new ArrayList<>(); for (String database : databases) { if (exists(database)) { filesExist.add(database); } } return filesExist; }
java
{ "resource": "" }
q176064
GeoPackageManagerImpl.createAndCloseGeoPackage
test
private void createAndCloseGeoPackage(GeoPackageDatabase db) { GeoPackageConnection connection = new GeoPackageConnection(db); // Set the GeoPackage application id and user version connection.setApplicationId(); connection.setUserVersion(); // Create the minimum required tables GeoPackageTableCreator tableCreator = new GeoPackageTableCreator(connection); tableCreator.createRequired(); connection.close(); }
java
{ "resource": "" }
q176065
GeoPackageManagerImpl.isValid
test
private boolean isValid(String database, boolean validateHeader, boolean validateIntegrity) { boolean valid = false; if (exists(database)) { GeoPackageCursorFactory cursorFactory = new GeoPackageCursorFactory(); String path = null; SQLiteDatabase sqlite; GeoPackageMetadata metadata = getGeoPackageMetadata(database); if (metadata != null && metadata.isExternal()) { path = metadata.getExternalPath(); try { sqlite = SQLiteDatabase.openDatabase(path, cursorFactory, SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.NO_LOCALIZED_COLLATORS); } catch (Exception e) { sqlite = SQLiteDatabase.openDatabase(path, cursorFactory, SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.NO_LOCALIZED_COLLATORS); } } else { path = context.getDatabasePath(database).getAbsolutePath(); sqlite = context.openOrCreateDatabase(database, Context.MODE_PRIVATE, cursorFactory); } try { valid = (!validateHeader || isDatabaseHeaderValid(sqlite)) && (!validateIntegrity || sqlite.isDatabaseIntegrityOk()); } catch (Exception e) { Log.e(GeoPackageManagerImpl.class.getSimpleName(), "Failed to validate database", e); } finally { sqlite.close(); } } return valid; }
java
{ "resource": "" }
q176066
GeoPackageManagerImpl.validateDatabaseAndCloseOnError
test
private void validateDatabaseAndCloseOnError(SQLiteDatabase sqliteDatabase, boolean validateHeader, boolean validateIntegrity) { validateDatabase(sqliteDatabase, validateHeader, validateIntegrity, false, true); }
java
{ "resource": "" }
q176067
GeoPackageManagerImpl.validateDatabaseAndClose
test
private void validateDatabaseAndClose(SQLiteDatabase sqliteDatabase, boolean validateHeader, boolean validateIntegrity) { validateDatabase(sqliteDatabase, validateHeader, validateIntegrity, true, true); }
java
{ "resource": "" }
q176068
GeoPackageManagerImpl.validateDatabase
test
private void validateDatabase(SQLiteDatabase sqliteDatabase, boolean validateHeader, boolean validateIntegrity, boolean close, boolean closeOnError) { try { if (validateHeader) { validateDatabaseHeader(sqliteDatabase); } if (validateIntegrity) { validateDatabaseIntegrity(sqliteDatabase); } } catch (Exception e) { if (closeOnError) { sqliteDatabase.close(); } throw e; } if (close) { sqliteDatabase.close(); } }
java
{ "resource": "" }
q176069
GeoPackageManagerImpl.validateDatabaseHeader
test
private void validateDatabaseHeader(SQLiteDatabase sqliteDatabase) { boolean validHeader = isDatabaseHeaderValid(sqliteDatabase); if (!validHeader) { throw new GeoPackageException( "GeoPackage SQLite header is not valid: " + sqliteDatabase.getPath()); } }
java
{ "resource": "" }
q176070
GeoPackageManagerImpl.isDatabaseHeaderValid
test
private boolean isDatabaseHeaderValid(SQLiteDatabase sqliteDatabase) { boolean validHeader = false; FileInputStream fis = null; try { fis = new FileInputStream(sqliteDatabase.getPath()); byte[] headerBytes = new byte[16]; if (fis.read(headerBytes) == 16) { ByteReader byteReader = new ByteReader(headerBytes); String header = byteReader.readString(headerBytes.length); String headerPrefix = header.substring(0, GeoPackageConstants.SQLITE_HEADER_PREFIX.length()); validHeader = headerPrefix.equalsIgnoreCase(GeoPackageConstants.SQLITE_HEADER_PREFIX); } } catch (Exception e) { Log.e(GeoPackageManagerImpl.class.getSimpleName(), "Failed to retrieve database header", e); } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { // eat } } } return validHeader; }
java
{ "resource": "" }
q176071
GeoPackageManagerImpl.addInternalDatabases
test
private void addInternalDatabases(Collection<String> databases) { String[] databaseArray = context.databaseList(); for (String database : databaseArray) { if (!isTemporary(database) && !database .equalsIgnoreCase(GeoPackageMetadataDb.DATABASE_NAME)) { databases.add(database); } } }
java
{ "resource": "" }
q176072
GeoPackageManagerImpl.addExternalDatabases
test
private void addExternalDatabases(Collection<String> databases) { // Get the external GeoPackages, adding those where the file exists and // deleting those with missing files List<GeoPackageMetadata> externalGeoPackages = getExternalGeoPackages(); for (GeoPackageMetadata external : externalGeoPackages) { if (new File(external.getExternalPath()).exists()) { databases.add(external.getName()); } else { delete(external.getName()); } } }
java
{ "resource": "" }
q176073
GeoPackageManagerImpl.importGeoPackage
test
private boolean importGeoPackage(String database, boolean override, InputStream geoPackageStream, GeoPackageProgress progress) { try { if (exists(database)) { if (override) { if (!delete(database)) { throw new GeoPackageException( "Failed to delete existing database: " + database); } } else { throw new GeoPackageException( "GeoPackage database already exists: " + database); } } // Copy the geopackage over as a database File newDbFile = context.getDatabasePath(database); try { SQLiteDatabase db = context.openOrCreateDatabase(database, Context.MODE_PRIVATE, null); db.close(); GeoPackageIOUtils.copyStream(geoPackageStream, newDbFile, progress); } catch (IOException e) { throw new GeoPackageException( "Failed to import GeoPackage database: " + database, e); } } finally { GeoPackageIOUtils.closeQuietly(geoPackageStream); } if (progress == null || progress.isActive()) { // Verify that the database is valid try { SQLiteDatabase sqlite = context.openOrCreateDatabase(database, Context.MODE_PRIVATE, null, new DatabaseErrorHandler() { @Override public void onCorruption(SQLiteDatabase dbObj) { } }); validateDatabaseAndClose(sqlite, importHeaderValidation, importIntegrityValidation); GeoPackageMetadataDb metadataDb = new GeoPackageMetadataDb( context); metadataDb.open(); try { GeoPackageMetadataDataSource dataSource = new GeoPackageMetadataDataSource(metadataDb); // Save in metadata GeoPackageMetadata metadata = new GeoPackageMetadata(); metadata.setName(database); dataSource.create(metadata); } finally { metadataDb.close(); } } catch (Exception e) { delete(database); throw new GeoPackageException( "Invalid GeoPackage database file", e); } GeoPackage geoPackage = open(database, false); if (geoPackage != null) { try { if (!geoPackage.getSpatialReferenceSystemDao() .isTableExists() || !geoPackage.getContentsDao().isTableExists()) { delete(database); throw new GeoPackageException( "Invalid GeoPackage database file. Does not contain required tables: " + SpatialReferenceSystem.TABLE_NAME + " & " + Contents.TABLE_NAME + ", Database: " + database); } } catch (SQLException e) { delete(database); throw new GeoPackageException( "Invalid GeoPackage database file. Could not verify existence of required tables: " + SpatialReferenceSystem.TABLE_NAME + " & " + Contents.TABLE_NAME + ", Database: " + database); } finally { geoPackage.close(); } } else { delete(database); throw new GeoPackageException( "Unable to open GeoPackage database. Database: " + database); } } return exists(database); }
java
{ "resource": "" }
q176074
GeoPackageManagerImpl.getGeoPackageMetadata
test
private GeoPackageMetadata getGeoPackageMetadata(String database) { GeoPackageMetadata metadata = null; GeoPackageMetadataDb metadataDb = new GeoPackageMetadataDb( context); metadataDb.open(); try { GeoPackageMetadataDataSource dataSource = new GeoPackageMetadataDataSource(metadataDb); metadata = dataSource.get(database); } finally { metadataDb.close(); } return metadata; }
java
{ "resource": "" }
q176075
GeoPackageManagerImpl.getGeoPackageMetadataAtExternalPath
test
private GeoPackageMetadata getGeoPackageMetadataAtExternalPath(String path) { GeoPackageMetadata metadata = null; GeoPackageMetadataDb metadataDb = new GeoPackageMetadataDb( context); metadataDb.open(); try { GeoPackageMetadataDataSource dataSource = new GeoPackageMetadataDataSource(metadataDb); metadata = dataSource.getExternalAtPath(path); } finally { metadataDb.close(); } return metadata; }
java
{ "resource": "" }
q176076
GeometryMetadataDataSource.create
test
public long create(GeometryMetadata metadata) { ContentValues values = new ContentValues(); values.put(GeometryMetadata.COLUMN_GEOPACKAGE_ID, metadata.getGeoPackageId()); values.put(GeometryMetadata.COLUMN_TABLE_NAME, metadata.getTableName()); values.put(GeometryMetadata.COLUMN_ID, metadata.getId()); values.put(GeometryMetadata.COLUMN_MIN_X, metadata.getMinX()); values.put(GeometryMetadata.COLUMN_MAX_X, metadata.getMaxX()); values.put(GeometryMetadata.COLUMN_MIN_Y, metadata.getMinY()); values.put(GeometryMetadata.COLUMN_MAX_Y, metadata.getMaxY()); values.put(GeometryMetadata.COLUMN_MIN_Z, metadata.getMinZ()); values.put(GeometryMetadata.COLUMN_MAX_Z, metadata.getMaxZ()); values.put(GeometryMetadata.COLUMN_MIN_M, metadata.getMinM()); values.put(GeometryMetadata.COLUMN_MAX_M, metadata.getMaxM()); long insertId = db.insert( GeometryMetadata.TABLE_NAME, null, values); if (insertId == -1) { throw new GeoPackageException( "Failed to insert geometry metadata. GeoPackage Id: " + metadata.getGeoPackageId() + ", Table Name: " + metadata.getTableName() + ", Geometry Id: " + metadata.getId()); } metadata.setId(insertId); return insertId; }
java
{ "resource": "" }
q176077
GeometryMetadataDataSource.populate
test
public GeometryMetadata populate(long geoPackageId, String tableName, long geomId, GeometryEnvelope envelope) { GeometryMetadata metadata = new GeometryMetadata(); metadata.setGeoPackageId(geoPackageId); metadata.setTableName(tableName); metadata.setId(geomId); metadata.setMinX(envelope.getMinX()); metadata.setMaxX(envelope.getMaxX()); metadata.setMinY(envelope.getMinY()); metadata.setMaxY(envelope.getMaxY()); if (envelope.hasZ()) { metadata.setMinZ(envelope.getMinZ()); metadata.setMaxZ(envelope.getMaxZ()); } if (envelope.hasM()) { metadata.setMinM(envelope.getMinM()); metadata.setMaxM(envelope.getMaxM()); } return metadata; }
java
{ "resource": "" }
q176078
GeometryMetadataDataSource.delete
test
public int delete(long geoPackageId) { String whereClause = GeometryMetadata.COLUMN_GEOPACKAGE_ID + " = ?"; String[] whereArgs = new String[]{String.valueOf(geoPackageId)}; int deleteCount = db.delete( GeometryMetadata.TABLE_NAME, whereClause, whereArgs); return deleteCount; }
java
{ "resource": "" }
q176079
GeometryMetadataDataSource.createOrUpdate
test
public boolean createOrUpdate(GeometryMetadata metadata) { boolean success = false; if (exists(metadata)) { success = update(metadata); } else { create(metadata); success = true; } return success; }
java
{ "resource": "" }
q176080
GeometryMetadataDataSource.update
test
public boolean update(GeometryMetadata metadata) { String whereClause = GeometryMetadata.COLUMN_GEOPACKAGE_ID + " = ? AND " + GeometryMetadata.COLUMN_TABLE_NAME + " = ? AND " + GeometryMetadata.COLUMN_ID + " = ?"; String[] whereArgs = new String[]{String.valueOf(metadata.getGeoPackageId()), metadata.getTableName(), String.valueOf(metadata.getId())}; ContentValues values = new ContentValues(); values.put(GeometryMetadata.COLUMN_MIN_X, metadata.getMinX()); values.put(GeometryMetadata.COLUMN_MAX_X, metadata.getMaxX()); values.put(GeometryMetadata.COLUMN_MIN_Y, metadata.getMinY()); values.put(GeometryMetadata.COLUMN_MAX_Y, metadata.getMaxY()); values.put(GeometryMetadata.COLUMN_MIN_Z, metadata.getMinZ()); values.put(GeometryMetadata.COLUMN_MAX_Z, metadata.getMaxZ()); values.put(GeometryMetadata.COLUMN_MIN_M, metadata.getMinM()); values.put(GeometryMetadata.COLUMN_MAX_M, metadata.getMaxM()); int updateCount = db.update( GeometryMetadata.TABLE_NAME, values, whereClause, whereArgs); return updateCount > 0; }
java
{ "resource": "" }
q176081
GeometryMetadataDataSource.count
test
public int count(String geoPackage, String tableName, BoundingBox boundingBox) { return count(getGeoPackageId(geoPackage), tableName, boundingBox); }
java
{ "resource": "" }
q176082
GeometryMetadataDataSource.createGeometryMetadata
test
public static GeometryMetadata createGeometryMetadata(Cursor cursor) { GeometryMetadata metadata = new GeometryMetadata(); metadata.setGeoPackageId(cursor.getLong(0)); metadata.setTableName(cursor.getString(1)); metadata.setId(cursor.getLong(2)); metadata.setMinX(cursor.getDouble(3)); metadata.setMaxX(cursor.getDouble(4)); metadata.setMinY(cursor.getDouble(5)); metadata.setMaxY(cursor.getDouble(6)); if (!cursor.isNull(7)) { metadata.setMinZ(cursor.getDouble(7)); } if (!cursor.isNull(8)) { metadata.setMaxZ(cursor.getDouble(8)); } if (!cursor.isNull(9)) { metadata.setMinM(cursor.getDouble(9)); } if (!cursor.isNull(10)) { metadata.setMaxM(cursor.getDouble(10)); } return metadata; }
java
{ "resource": "" }
q176083
UserDao.update
test
public int update(ContentValues values, String whereClause, String[] whereArgs) { return db.update(getTableName(), values, whereClause, whereArgs); }
java
{ "resource": "" }
q176084
NumberFeaturesTile.drawTile
test
private Bitmap drawTile(int tileWidth, int tileHeight, String text) { // Create bitmap and canvas Bitmap bitmap = Bitmap.createBitmap(tileWidth, tileHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); // Draw the tile fill paint if (tileFillPaint != null) { canvas.drawRect(0, 0, tileWidth, tileHeight, tileFillPaint); } // Draw the tile border if (tileBorderPaint != null) { canvas.drawRect(0, 0, tileWidth, tileHeight, tileBorderPaint); } // Determine the text bounds Rect textBounds = new Rect(); textPaint.getTextBounds(text, 0, text.length(), textBounds); // Determine the center of the tile int centerX = (int) (bitmap.getWidth() / 2.0f); int centerY = (int) (bitmap.getHeight() / 2.0f); // Draw the circle if (circlePaint != null || circleFillPaint != null) { int diameter = Math.max(textBounds.width(), textBounds.height()); float radius = diameter / 2.0f; radius = radius + (diameter * circlePaddingPercentage); // Draw the filled circle if (circleFillPaint != null) { canvas.drawCircle(centerX, centerY, radius, circleFillPaint); } // Draw the circle if (circlePaint != null) { canvas.drawCircle(centerX, centerY, radius, circlePaint); } } // Draw the text canvas.drawText(text, centerX - textBounds.exactCenterX(), centerY - textBounds.exactCenterY(), textPaint); return bitmap; }
java
{ "resource": "" }
q176085
SimpleAttributesDao.getRows
test
public List<SimpleAttributesRow> getRows(List<Long> ids) { List<SimpleAttributesRow> simpleAttributesRows = new ArrayList<>(); for (long id : ids) { UserCustomRow userCustomRow = queryForIdRow(id); if (userCustomRow != null) { simpleAttributesRows.add(getRow(userCustomRow)); } } return simpleAttributesRows; }
java
{ "resource": "" }
q176086
GeoPackageImpl.integrityCheck
test
private Cursor integrityCheck(Cursor cursor) { if (cursor.moveToNext()) { String value = cursor.getString(0); if (value.equals("ok")) { cursor.close(); cursor = null; } } return cursor; }
java
{ "resource": "" }
q176087
RelatedTablesExtension.getMappingDao
test
public UserMappingDao getMappingDao(String tableName) { UserMappingDao userMappingDao = new UserMappingDao(getUserDao(tableName)); userMappingDao.registerCursorWrapper(getGeoPackage()); return userMappingDao; }
java
{ "resource": "" }
q176088
RelatedTablesExtension.getSimpleAttributesDao
test
public SimpleAttributesDao getSimpleAttributesDao(String tableName) { SimpleAttributesDao simpleAttributesDao = new SimpleAttributesDao( getUserDao(tableName)); simpleAttributesDao.registerCursorWrapper(getGeoPackage()); setContents(simpleAttributesDao.getTable()); return simpleAttributesDao; }
java
{ "resource": "" }
q176089
RelatedTablesExtension.getMappingsForBase
test
public List<Long> getMappingsForBase(ExtendedRelation extendedRelation, long baseId) { return getMappingsForBase(extendedRelation.getMappingTableName(), baseId); }
java
{ "resource": "" }
q176090
RelatedTablesExtension.getMappingsForRelated
test
public List<Long> getMappingsForRelated(ExtendedRelation extendedRelation, long relatedId) { return getMappingsForRelated(extendedRelation.getMappingTableName(), relatedId); }
java
{ "resource": "" }
q176091
RelatedTablesExtension.hasMapping
test
public boolean hasMapping(String tableName, long baseId, long relatedId) { boolean has = false; UserMappingDao userMappingDao = getMappingDao(tableName); UserCustomCursor cursor = userMappingDao.queryByIds(baseId, relatedId); try { has = cursor.getCount() > 0; } finally { cursor.close(); } return has; }
java
{ "resource": "" }
q176092
UserCustomDao.count
test
protected int count(UserCustomCursor cursor) { int count = 0; try { count = cursor.getCount(); } finally { cursor.close(); } return count; }
java
{ "resource": "" }
q176093
UserCustomDao.registerCursorWrapper
test
public void registerCursorWrapper(GeoPackage geoPackage) { geoPackage.registerCursorWrapper(getTableName(), new GeoPackageCursorWrapper() { @Override public Cursor wrapCursor(Cursor cursor) { return new UserCustomCursor(getTable(), cursor); } }); }
java
{ "resource": "" }
q176094
UserCustomDao.readTable
test
public static UserCustomDao readTable(GeoPackage geoPackage, String tableName) { UserCustomConnection userDb = new UserCustomConnection(geoPackage.getConnection()); final UserCustomTable userCustomTable = UserCustomTableReader.readTable( geoPackage.getConnection(), tableName); UserCustomDao dao = new UserCustomDao(geoPackage.getName(), geoPackage.getConnection(), userDb, userCustomTable); dao.registerCursorWrapper(geoPackage); return dao; }
java
{ "resource": "" }
q176095
TileCreator.getTile
test
public GeoPackageTile getTile(BoundingBox requestBoundingBox) { GeoPackageTile tile = null; // Transform to the projection of the tiles ProjectionTransform transformRequestToTiles = requestProjection.getTransformation(tilesProjection); BoundingBox tilesBoundingBox = requestBoundingBox.transform(transformRequestToTiles); List<TileMatrix> tileMatrices = getTileMatrices(tilesBoundingBox); for (int i = 0; tile == null && i < tileMatrices.size(); i++) { TileMatrix tileMatrix = tileMatrices.get(i); TileCursor tileResults = retrieveTileResults(tilesBoundingBox, tileMatrix); if (tileResults != null) { try { if (tileResults.getCount() > 0) { BoundingBox requestProjectedBoundingBox = requestBoundingBox.transform(transformRequestToTiles); // Determine the requested tile dimensions, or use the dimensions of a single tile matrix tile int requestedTileWidth = width != null ? width : (int) tileMatrix .getTileWidth(); int requestedTileHeight = height != null ? height : (int) tileMatrix .getTileHeight(); // Determine the size of the tile to initially draw int tileWidth = requestedTileWidth; int tileHeight = requestedTileHeight; if (!sameProjection) { tileWidth = (int) Math.round( (requestProjectedBoundingBox.getMaxLongitude() - requestProjectedBoundingBox.getMinLongitude()) / tileMatrix.getPixelXSize()); tileHeight = (int) Math.round( (requestProjectedBoundingBox.getMaxLatitude() - requestProjectedBoundingBox.getMinLatitude()) / tileMatrix.getPixelYSize()); } // Draw the resulting bitmap with the matching tiles Bitmap tileBitmap = drawTile(tileMatrix, tileResults, requestProjectedBoundingBox, tileWidth, tileHeight); // Create the tile if (tileBitmap != null) { // Project the tile if needed if (!sameProjection) { Bitmap reprojectTile = reprojectTile(tileBitmap, requestedTileWidth, requestedTileHeight, requestBoundingBox, transformRequestToTiles, tilesBoundingBox); tileBitmap.recycle(); tileBitmap = reprojectTile; } try { byte[] tileData = BitmapConverter.toBytes( tileBitmap, COMPRESS_FORMAT); tileBitmap.recycle(); tile = new GeoPackageTile(requestedTileWidth, requestedTileHeight, tileData); } catch (IOException e) { Log.e(TileCreator.class.getSimpleName(), "Failed to create tile. min lat: " + requestBoundingBox.getMinLatitude() + ", max lat: " + requestBoundingBox.getMaxLatitude() + ", min lon: " + requestBoundingBox.getMinLongitude() + ", max lon: " + requestBoundingBox.getMaxLongitude(), e); } } } } finally { tileResults.close(); } } } return tile; }
java
{ "resource": "" }
q176096
TileCreator.drawTile
test
private Bitmap drawTile(TileMatrix tileMatrix, TileCursor tileResults, BoundingBox requestProjectedBoundingBox, int tileWidth, int tileHeight) { // Draw the resulting bitmap with the matching tiles Bitmap tileBitmap = null; Canvas canvas = null; Paint paint = null; while (tileResults.moveToNext()) { // Get the next tile TileRow tileRow = tileResults.getRow(); Bitmap tileDataBitmap = tileRow.getTileDataBitmap(); // Get the bounding box of the tile BoundingBox tileBoundingBox = TileBoundingBoxUtils .getBoundingBox( tileSetBoundingBox, tileMatrix, tileRow.getTileColumn(), tileRow.getTileRow()); // Get the bounding box where the requested image and // tile overlap BoundingBox overlap = requestProjectedBoundingBox.overlap( tileBoundingBox); // If the tile overlaps with the requested box if (overlap != null) { // Get the rectangle of the tile image to draw Rect src = TileBoundingBoxAndroidUtils .getRectangle(tileMatrix.getTileWidth(), tileMatrix.getTileHeight(), tileBoundingBox, overlap); // Get the rectangle of where to draw the tile in // the resulting image RectF dest = TileBoundingBoxAndroidUtils .getRoundedFloatRectangle(tileWidth, tileHeight, requestProjectedBoundingBox, overlap); // Create the bitmap first time through if (tileBitmap == null) { tileBitmap = Bitmap.createBitmap(tileWidth, tileHeight, Bitmap.Config.ARGB_8888); canvas = new Canvas(tileBitmap); paint = new Paint(Paint.ANTI_ALIAS_FLAG); } // Draw the tile to the bitmap canvas.drawBitmap(tileDataBitmap, src, dest, paint); } } return tileBitmap; }
java
{ "resource": "" }
q176097
TileCreator.reprojectTile
test
private Bitmap reprojectTile(Bitmap tile, int requestedTileWidth, int requestedTileHeight, BoundingBox requestBoundingBox, ProjectionTransform transformRequestToTiles, BoundingBox tilesBoundingBox) { final double requestedWidthUnitsPerPixel = (requestBoundingBox.getMaxLongitude() - requestBoundingBox.getMinLongitude()) / requestedTileWidth; final double requestedHeightUnitsPerPixel = (requestBoundingBox.getMaxLatitude() - requestBoundingBox.getMinLatitude()) / requestedTileHeight; final double tilesDistanceWidth = tilesBoundingBox.getMaxLongitude() - tilesBoundingBox.getMinLongitude(); final double tilesDistanceHeight = tilesBoundingBox.getMaxLatitude() - tilesBoundingBox.getMinLatitude(); final int width = tile.getWidth(); final int height = tile.getHeight(); // Tile pixels of the tile matrix tiles int[] pixels = new int[width * height]; tile.getPixels(pixels, 0, width, 0, 0, width, height); // Projected tile pixels to draw the reprojected tile int[] projectedPixels = new int[requestedTileWidth * requestedTileHeight]; // Retrieve each pixel in the new tile from the unprojected tile for (int y = 0; y < requestedTileHeight; y++) { for (int x = 0; x < requestedTileWidth; x++) { double longitude = requestBoundingBox.getMinLongitude() + (x * requestedWidthUnitsPerPixel); double latitude = requestBoundingBox.getMaxLatitude() - (y * requestedHeightUnitsPerPixel); ProjCoordinate fromCoord = new ProjCoordinate(longitude, latitude); ProjCoordinate toCoord = transformRequestToTiles.transform(fromCoord); double projectedLongitude = toCoord.x; double projectedLatitude = toCoord.y; int xPixel = (int) Math.round(((projectedLongitude - tilesBoundingBox.getMinLongitude()) / tilesDistanceWidth) * width); int yPixel = (int) Math.round(((tilesBoundingBox.getMaxLatitude() - projectedLatitude) / tilesDistanceHeight) * height); xPixel = Math.max(0, xPixel); xPixel = Math.min(width - 1, xPixel); yPixel = Math.max(0, yPixel); yPixel = Math.min(height - 1, yPixel); int color = pixels[(yPixel * width) + xPixel]; projectedPixels[(y * requestedTileWidth) + x] = color; } } // Draw the new tile bitmap Bitmap projectedTileBitmap = Bitmap.createBitmap(requestedTileWidth, requestedTileHeight, tile.getConfig()); projectedTileBitmap.setPixels(projectedPixels, 0, requestedTileWidth, 0, 0, requestedTileWidth, requestedTileHeight); return projectedTileBitmap; }
java
{ "resource": "" }
q176098
TileCreator.retrieveTileResults
test
private TileCursor retrieveTileResults(BoundingBox projectedRequestBoundingBox, TileMatrix tileMatrix) { TileCursor tileResults = null; if (tileMatrix != null) { // Get the tile grid TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid( tileSetBoundingBox, tileMatrix.getMatrixWidth(), tileMatrix.getMatrixHeight(), projectedRequestBoundingBox); // Query for matching tiles in the tile grid tileResults = tileDao.queryByTileGrid(tileGrid, tileMatrix.getZoomLevel()); } return tileResults; }
java
{ "resource": "" }
q176099
FeatureTiles.calculateDrawOverlap
test
public void calculateDrawOverlap() { if (pointIcon != null) { heightOverlap = this.density * pointIcon.getHeight(); widthOverlap = this.density * pointIcon.getWidth(); } else { heightOverlap = this.density * pointRadius; widthOverlap = this.density * pointRadius; } float linePaintHalfStroke = this.density * lineStrokeWidth / 2.0f; heightOverlap = Math.max(heightOverlap, linePaintHalfStroke); widthOverlap = Math.max(widthOverlap, linePaintHalfStroke); float polygonPaintHalfStroke = this.density * polygonStrokeWidth / 2.0f; heightOverlap = Math.max(heightOverlap, polygonPaintHalfStroke); widthOverlap = Math.max(widthOverlap, polygonPaintHalfStroke); if (featureTableStyles != null && featureTableStyles.has()) { // Style Rows Set<Long> styleRowIds = new HashSet<>(); List<Long> tableStyleIds = featureTableStyles.getAllTableStyleIds(); if (tableStyleIds != null) { styleRowIds.addAll(tableStyleIds); } List<Long> styleIds = featureTableStyles.getAllStyleIds(); if (styleIds != null) { styleRowIds.addAll(styleIds); } StyleDao styleDao = featureTableStyles.getStyleDao(); for (long styleRowId : styleRowIds) { StyleRow styleRow = styleDao.getRow(styleDao.queryForIdRow(styleRowId)); float styleHalfWidth = this.density * (float) (styleRow.getWidthOrDefault() / 2.0f); widthOverlap = Math.max(widthOverlap, styleHalfWidth); heightOverlap = Math.max(heightOverlap, styleHalfWidth); } // Icon Rows Set<Long> iconRowIds = new HashSet<>(); List<Long> tableIconIds = featureTableStyles.getAllTableIconIds(); if (tableIconIds != null) { iconRowIds.addAll(tableIconIds); } List<Long> iconIds = featureTableStyles.getAllIconIds(); if (iconIds != null) { iconRowIds.addAll(iconIds); } IconDao iconDao = featureTableStyles.getIconDao(); for (long iconRowId : iconRowIds) { IconRow iconRow = iconDao.getRow(iconDao.queryForIdRow(iconRowId)); double[] iconDimensions = iconRow.getDerivedDimensions(); float iconWidth = this.density * (float) Math.ceil(iconDimensions[0]); float iconHeight = this.density * (float) Math.ceil(iconDimensions[1]); widthOverlap = Math.max(widthOverlap, iconWidth); heightOverlap = Math.max(heightOverlap, iconHeight); } } }
java
{ "resource": "" }