signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean existsAtExternalPath ( String path ) { } }

implementation: GeoPackageMetadata metadata = getGeoPackageMetadataAtExternalPath ( path ) ; return metadata != null ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public String getPath ( String database ) { } }

implementation: File dbFile = getFile ( database ) ; String path = dbFile . getAbsolutePath ( ) ; return path ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public File getFile ( String database ) { } }

implementation: File dbFile = null ; GeoPackageMetadata metadata = getGeoPackageMetadata ( database ) ; if ( metadata != null && metadata . isExternal ( ) ) { dbFile = new File ( metadata . getExternalPath ( ) ) ; } else { dbFile = context . getDatabasePath ( database ) ; } if ( dbFile == null || ! dbFile . exists ( ) ) { throw new GeoPackageException ( "GeoPackage does not exist: " + database ) ; } return dbFile ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public String getDatabaseAtExternalPath ( String path ) { } }

implementation: String database = null ; GeoPackageMetadata metadata = getGeoPackageMetadataAtExternalPath ( path ) ; if ( metadata != null ) { database = metadata . getName ( ) ; } return database ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public String readableSize ( String database ) { } }

implementation: long size = size ( database ) ; return GeoPackageIOUtils . formatBytes ( size ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean delete ( String database ) { } }

implementation: boolean deleted = false ; boolean external = isExternal ( database ) ; GeoPackageMetadataDb metadataDb = new GeoPackageMetadataDb ( context ) ; metadataDb . open ( ) ; try { GeoPackageMetadataDataSource dataSource = new GeoPackageMetadataDataSource ( metadataDb ) ; deleted = dataSource . delete ( database ) ; } finally { metadataDb . close ( ) ; } if ( ! external ) { deleted = context . deleteDatabase ( database ) ; } return deleted ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean deleteAll ( ) { } }

implementation: boolean deleted = true ; for ( String database : databaseSet ( ) ) { deleted = delete ( database ) && deleted ; } return deleted ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean deleteAllExternal ( ) { } }

implementation: boolean deleted = true ; for ( String database : externalDatabaseSet ( ) ) { deleted = delete ( database ) && deleted ; } return deleted ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean deleteAllMissingExternal ( ) { } }

implementation: boolean deleted = false ; List < GeoPackageMetadata > externalGeoPackages = getExternalGeoPackages ( ) ; for ( GeoPackageMetadata external : externalGeoPackages ) { if ( ! new File ( external . getExternalPath ( ) ) . exists ( ) ) { deleted = delete ( external . getName ( ) ) || deleted ; } } return deleted ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean create ( String database ) { } }

implementation:
boolean created = false ; if ( exists ( database ) ) { throw new GeoPackageException ( "GeoPackage already exists: " + database ) ; } else { GeoPackageDatabase db = new GeoPackageDatabase ( context . openOrCreateDatabase ( database , Context . MODE_PRIVATE , null ) ) ; createAndCloseGeoPackage ( db ) ; 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 ( ) ; } created = true ; } return created ;


signature:
public class GeoPackageManagerImpl { /** * Create the required GeoPackage application id and tables in the newly created and open database connection . Then close the connection .
 * @ param db */
private void createAndCloseGeoPackage ( GeoPackageDatabase db ) { } }

implementation:
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 ( ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean createAtPath ( String database , File path ) { } }

implementation:
// Create the absolute file path
File file = new File ( path , database + "." + GeoPackageConstants . GEOPACKAGE_EXTENSION ) ; // Create the GeoPackage
boolean created = createFile ( database , file ) ; return created ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean createFile ( File file ) { } }

implementation:
// Get the database name
String database = GeoPackageIOUtils . getFileNameWithoutExtension ( file ) ; // Create the GeoPackage
boolean created = createFile ( database , file ) ; return created ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean createFile ( String database , File file ) { } }

implementation:
boolean created = false ; if ( exists ( database ) ) { throw new GeoPackageException ( "GeoPackage already exists: " + database ) ; } else { // Check if the path is an absolute path to the GeoPackage file to create
if ( ! GeoPackageValidate . hasGeoPackageExtension ( file ) ) { // Make sure this isn ' t a path to another file extension
if ( GeoPackageIOUtils . getFileExtension ( file ) != null ) { throw new GeoPackageException ( "File can not have a non GeoPackage extension. Invalid File: " + file . getAbsolutePath ( ) ) ; } // Add the extension
file = new File ( file . getParentFile ( ) , file . getName ( ) + "." + GeoPackageConstants . GEOPACKAGE_EXTENSION ) ; } // Make sure the file does not already exist
if ( file . exists ( ) ) { throw new GeoPackageException ( "GeoPackage file already exists: " + file . getAbsolutePath ( ) ) ; } // Create the new GeoPackage file
GeoPackageDatabase db = new GeoPackageDatabase ( SQLiteDatabase . openOrCreateDatabase ( file , null ) ) ; createAndCloseGeoPackage ( db ) ; // Import the GeoPackage
created = importGeoPackageAsExternalLink ( file , database ) ; } return created ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackage ( String database , InputStream stream ) { } }

implementation: return importGeoPackage ( database , stream , false , null ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackage ( String database , InputStream stream , GeoPackageProgress progress ) { } }

implementation: return importGeoPackage ( database , stream , false , progress ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackage ( String database , InputStream stream , boolean override ) { } }

implementation: return importGeoPackage ( database , stream , override , null ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackage ( String database , InputStream stream , boolean override , GeoPackageProgress progress ) { } }

implementation: if ( progress != null ) { try { int streamLength = stream . available ( ) ; if ( streamLength > 0 ) { progress . setMax ( streamLength ) ; } } catch ( IOException e ) { Log . w ( GeoPackageManagerImpl . class . getSimpleName ( ) , "Could not determine stream available size. Database: " + database , e ) ; } } boolean success = importGeoPackage ( database , override , stream , progress ) ; return success ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackage ( String name , File file ) { } }

implementation: return importGeoPackage ( name , file , false ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackage ( String name , File file , boolean override ) { } }

implementation:
// Verify the file has the right extension
GeoPackageValidate . validateGeoPackageExtension ( file ) ; // Use the provided name or the base file name as the database name
String database ; if ( name != null ) { database = name ; } else { database = GeoPackageIOUtils . getFileNameWithoutExtension ( file ) ; } boolean success = false ; try { FileInputStream geoPackageStream = new FileInputStream ( file ) ; success = importGeoPackage ( database , override , geoPackageStream , null ) ; } catch ( FileNotFoundException e ) { throw new GeoPackageException ( "Failed read or write GeoPackage file '" + file + "' to database: '" + database + "'" , e ) ; } return success ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackage ( String name , URL url ) { } }

implementation: return importGeoPackage ( name , url , false , null ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackage ( String name , URL url , GeoPackageProgress progress ) { } }

implementation: return importGeoPackage ( name , url , false , progress ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackage ( String name , URL url , boolean override ) { } }

implementation: return importGeoPackage ( name , url , override , null ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackage ( String name , URL url , boolean override , GeoPackageProgress progress ) { } }

implementation: boolean success = false ; HttpURLConnection connection = null ; try { connection = ( HttpURLConnection ) url . openConnection ( ) ; connection . connect ( ) ; int responseCode = connection . getResponseCode ( ) ; if ( responseCode == HttpURLConnection . HTTP_MOVED_PERM || responseCode == HttpURLConnection . HTTP_MOVED_TEMP || responseCode == HttpURLConnection . HTTP_SEE_OTHER ) { String redirect = connection . getHeaderField ( "Location" ) ; connection . disconnect ( ) ; url = new URL ( redirect ) ; connection = ( HttpURLConnection ) url . openConnection ( ) ; connection . connect ( ) ; } if ( connection . getResponseCode ( ) != HttpURLConnection . HTTP_OK ) { throw new GeoPackageException ( "Failed to import GeoPackage " + name + " from URL: '" + url . toString ( ) + "'. HTTP " + connection . getResponseCode ( ) + " " + connection . getResponseMessage ( ) ) ; } int fileLength = connection . getContentLength ( ) ; if ( fileLength != - 1 && progress != null ) { progress . setMax ( fileLength ) ; } InputStream geoPackageStream = connection . getInputStream ( ) ; success = importGeoPackage ( name , override , geoPackageStream , progress ) ; } catch ( IOException e ) { throw new GeoPackageException ( "Failed to import GeoPackage " + name + " from URL: '" + url . toString ( ) + "'" , e ) ; } finally { if ( connection != null ) { connection . disconnect ( ) ; } } return success ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public void exportGeoPackage ( String database , File directory ) { } }

implementation: exportGeoPackage ( database , database , directory ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public void exportGeoPackage ( String database , String name , File directory ) { } }

implementation:
File file = new File ( directory , name ) ; // Add the extension if not on the name
if ( ! GeoPackageValidate . hasGeoPackageExtension ( file ) ) { name += "." + GeoPackageConstants . GEOPACKAGE_EXTENSION ; file = new File ( directory , name ) ; } // Copy the geopackage database to the new file location
File dbFile = getFile ( database ) ; try { GeoPackageIOUtils . copyFile ( dbFile , file ) ; } catch ( IOException e ) { throw new GeoPackageException ( "Failed read or write GeoPackage database '" + database + "' to file: '" + file , e ) ; }


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public GeoPackage open ( String database , boolean writable ) { } }

implementation:
GeoPackage db = null ; if ( exists ( database ) ) { GeoPackageCursorFactory cursorFactory = new GeoPackageCursorFactory ( ) ; String path = null ; SQLiteDatabase sqlite = null ; GeoPackageMetadata metadata = getGeoPackageMetadata ( database ) ; if ( metadata != null && metadata . isExternal ( ) ) { path = metadata . getExternalPath ( ) ; if ( writable ) { try { sqlite = SQLiteDatabase . openDatabase ( path , cursorFactory , SQLiteDatabase . OPEN_READWRITE | SQLiteDatabase . NO_LOCALIZED_COLLATORS ) ; } catch ( Exception e ) { Log . e ( GeoPackageManagerImpl . class . getSimpleName ( ) , "Failed to open database as writable: " + database , e ) ; } } if ( sqlite == null ) { sqlite = SQLiteDatabase . openDatabase ( path , cursorFactory , SQLiteDatabase . OPEN_READONLY | SQLiteDatabase . NO_LOCALIZED_COLLATORS ) ; writable = false ; } } else { sqlite = context . openOrCreateDatabase ( database , Context . MODE_PRIVATE , cursorFactory ) ; } if ( sqliteWriteAheadLogging ) { sqlite . enableWriteAheadLogging ( ) ; } else { sqlite . disableWriteAheadLogging ( ) ; } // Validate the database if validation is enabled
validateDatabaseAndCloseOnError ( sqlite , openHeaderValidation , openIntegrityValidation ) ; GeoPackageConnection connection = new GeoPackageConnection ( new GeoPackageDatabase ( sqlite ) ) ; GeoPackageTableCreator tableCreator = new GeoPackageTableCreator ( connection ) ; db = new GeoPackageImpl ( context , database , path , connection , cursorFactory , tableCreator , writable ) ; // Validate the GeoPackage has the minimum required tables
try { GeoPackageValidate . validateMinimumTables ( db ) ; } catch ( RuntimeException e ) { db . close ( ) ; throw e ; } } return db ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean validate ( String database ) { } }

implementation: boolean valid = isValid ( database , true , true ) ; return valid ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean validateHeader ( String database ) { } }

implementation: boolean valid = isValid ( database , true , false ) ; return valid ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean validateIntegrity ( String database ) { } }

implementation: boolean valid = isValid ( database , false , true ) ; return valid ;


signature:
public class GeoPackageManagerImpl { /** * Validate the GeoPackage database
 * @ param database
 * @ param validateHeader true to validate the header of the database
 * @ param validateIntegrity true to validate the integrity of the database
 * @ return true if valid */
private boolean isValid ( String database , boolean validateHeader , boolean validateIntegrity ) { } }

implementation: 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 ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean copy ( String database , String databaseCopy ) { } }

implementation:
// Copy the database as a new file
File dbFile = getFile ( database ) ; File dbCopyFile = context . getDatabasePath ( databaseCopy ) ; try { GeoPackageIOUtils . copyFile ( dbFile , dbCopyFile ) ; } catch ( IOException e ) { throw new GeoPackageException ( "Failed to copy GeoPackage database '" + database + "' to '" + databaseCopy + "'" , e ) ; } return exists ( databaseCopy ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean rename ( String database , String newDatabase ) { } }

implementation: GeoPackageMetadata metadata = getGeoPackageMetadata ( database ) ; if ( metadata != null ) { GeoPackageMetadataDb metadataDb = new GeoPackageMetadataDb ( context ) ; metadataDb . open ( ) ; try { GeoPackageMetadataDataSource dataSource = new GeoPackageMetadataDataSource ( metadataDb ) ; dataSource . rename ( metadata , newDatabase ) ; } finally { metadataDb . close ( ) ; } } if ( ( metadata == null || ! metadata . isExternal ( ) ) && copy ( database , newDatabase ) ) { delete ( database ) ; } return exists ( newDatabase ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackageAsExternalLink ( File path , String database ) { } }

implementation: return importGeoPackageAsExternalLink ( path , database , false ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackageAsExternalLink ( File path , String database , boolean override ) { } }

implementation: return importGeoPackageAsExternalLink ( path . getAbsolutePath ( ) , database , override ) ;


signature:
public class GeoPackageManagerImpl { /** * { @ inheritDoc } */
@ Override public boolean importGeoPackageAsExternalLink ( String path , String database , boolean override ) { } }

implementation:
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 ) ; } } // Verify the file is a database and can be opened
try { SQLiteDatabase sqlite = SQLiteDatabase . openDatabase ( path , null , SQLiteDatabase . OPEN_READONLY | SQLiteDatabase . NO_LOCALIZED_COLLATORS ) ; validateDatabaseAndClose ( sqlite , importHeaderValidation , importIntegrityValidation ) ; } catch ( SQLiteException e ) { throw new GeoPackageException ( "Failed to import GeoPackage database as external link: " + database + ", Path: " + path , e ) ; } GeoPackageMetadataDb metadataDb = new GeoPackageMetadataDb ( context ) ; metadataDb . open ( ) ; try { GeoPackageMetadataDataSource dataSource = new GeoPackageMetadataDataSource ( metadataDb ) ; // Save the external link in metadata
GeoPackageMetadata metadata = new GeoPackageMetadata ( ) ; metadata . setName ( database ) ; metadata . setExternalPath ( path ) ; dataSource . create ( metadata ) ; GeoPackage geoPackage = open ( database , false ) ; if ( geoPackage != null ) { try { GeoPackageValidate . validateMinimumTables ( geoPackage ) ; } catch ( RuntimeException e ) { dataSource . delete ( database ) ; throw e ; } finally { geoPackage . close ( ) ; } } else { dataSource . delete ( database ) ; throw new GeoPackageException ( "Unable to open GeoPackage database. Database: " + database ) ; } } finally { metadataDb . close ( ) ; } return exists ( database ) ;


signature:
public class GeoPackageManagerImpl { /** * Validate the database and close when validation fails . Throw an error when not valid .
 * @ param sqliteDatabase database
 * @ param validateHeader validate the header
 * @ param validateIntegrity validate the integrity */
private void validateDatabaseAndCloseOnError ( SQLiteDatabase sqliteDatabase , boolean validateHeader , boolean validateIntegrity ) { } }

implementation: validateDatabase ( sqliteDatabase , validateHeader , validateIntegrity , false , true ) ;


signature:
public class GeoPackageManagerImpl { /** * Validate the database and close it . Throw an error when not valid .
 * @ param sqliteDatabase database
 * @ param validateHeader validate the header
 * @ param validateIntegrity validate the integrity */
private void validateDatabaseAndClose ( SQLiteDatabase sqliteDatabase , boolean validateHeader , boolean validateIntegrity ) { } }

implementation: validateDatabase ( sqliteDatabase , validateHeader , validateIntegrity , true , true ) ;


signature:
public class GeoPackageManagerImpl { /** * Validate the database header and integrity . Throw an error when not valid .
 * @ param sqliteDatabase database
 * @ param validateHeader validate the header
 * @ param validateIntegrity validate the integrity
 * @ param close close the database after validation
 * @ param closeOnError close the database if validation fails */
private void validateDatabase ( SQLiteDatabase sqliteDatabase , boolean validateHeader , boolean validateIntegrity , boolean close , boolean closeOnError ) { } }

implementation: try { if ( validateHeader ) { validateDatabaseHeader ( sqliteDatabase ) ; } if ( validateIntegrity ) { validateDatabaseIntegrity ( sqliteDatabase ) ; } } catch ( Exception e ) { if ( closeOnError ) { sqliteDatabase . close ( ) ; } throw e ; } if ( close ) { sqliteDatabase . close ( ) ; }


signature:
public class GeoPackageManagerImpl { /** * Validate the header of the database file to verify it is a sqlite database
 * @ param sqliteDatabase database */
private void validateDatabaseHeader ( SQLiteDatabase sqliteDatabase ) { } }

implementation: boolean validHeader = isDatabaseHeaderValid ( sqliteDatabase ) ; if ( ! validHeader ) { throw new GeoPackageException ( "GeoPackage SQLite header is not valid: " + sqliteDatabase . getPath ( ) ) ; }


signature:
public class GeoPackageManagerImpl { /** * Determine if the header of the database file is valid
 * @ param sqliteDatabase database
 * @ return true if valid */
private boolean isDatabaseHeaderValid ( SQLiteDatabase sqliteDatabase ) { } }

implementation:
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 ;


signature:
public class GeoPackageManagerImpl { /** * Add all internal databases to the collection
 * @ param databases */
private void addInternalDatabases ( Collection < String > databases ) { } }

implementation: String [ ] databaseArray = context . databaseList ( ) ; for ( String database : databaseArray ) { if ( ! isTemporary ( database ) && ! database . equalsIgnoreCase ( GeoPackageMetadataDb . DATABASE_NAME ) ) { databases . add ( database ) ; } }


signature:
public class GeoPackageManagerImpl { /** * Add all external databases to the collection
 * @ param databases */
private void addExternalDatabases ( Collection < String > databases ) { } }

implementation:
// 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 ( ) ) ; } }


signature:
public class GeoPackageManagerImpl { /** * Import the GeoPackage stream
 * @ param database
 * @ param override
 * @ param geoPackageStream
 * @ param progress
 * @ return true if imported successfully */
private boolean importGeoPackage ( String database , boolean override , InputStream geoPackageStream , GeoPackageProgress progress ) { } }

implementation:
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 ) ;


signature:
public class GeoPackageManagerImpl { /** * Get all external GeoPackage metadata
 * @ return */
private List < GeoPackageMetadata > getExternalGeoPackages ( ) { } }

implementation: List < GeoPackageMetadata > metadata = null ; GeoPackageMetadataDb metadataDb = new GeoPackageMetadataDb ( context ) ; metadataDb . open ( ) ; try { GeoPackageMetadataDataSource dataSource = new GeoPackageMetadataDataSource ( metadataDb ) ; metadata = dataSource . getAllExternal ( ) ; } finally { metadataDb . close ( ) ; } return metadata ;


signature:
public class GeoPackageManagerImpl { /** * Get the GeoPackage metadata
 * @ param database
 * @ return */
private GeoPackageMetadata getGeoPackageMetadata ( String database ) { } }

implementation: 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 ;


signature:
public class GeoPackageManagerImpl { /** * Get the GeoPackage metadata of the database at the external path
 * @ param path external database path
 * @ return metadata or null */
private GeoPackageMetadata getGeoPackageMetadataAtExternalPath ( String path ) { } }

implementation: 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 ;


signature:
public class GeoPackageManagerImpl { /** * Check if the database is temporary ( rollback journal )
 * @ param database
 * @ return */
private boolean isTemporary ( String database ) { } }

implementation: return database . endsWith ( context . getString ( R . string . geopackage_db_rollback_journal_suffix ) ) || database . endsWith ( context . getString ( R . string . geopackage_db_write_ahead_log_suffix ) ) || database . endsWith ( context . getString ( R . string . geopackage_db_shared_memory_suffix ) ) ;


signature:
public class GeometryMetadataDataSource { /** * Create a new geometry metadata
 * @ param metadata geometry metadata
 * @ return id */
public long create ( GeometryMetadata metadata ) { } }

implementation: 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 ;


signature:
public class GeometryMetadataDataSource { /** * Create a new geometry metadata from an envelope
 * @ param geoPackage GeoPackage name
 * @ param tableName table name
 * @ param geomId geometry id
 * @ param envelope geometry envelope
 * @ return geometry metadata */
public GeometryMetadata create ( String geoPackage , String tableName , long geomId , GeometryEnvelope envelope ) { } }

implementation: return create ( getGeoPackageId ( geoPackage ) , tableName , geomId , envelope ) ;


signature:
public class GeometryMetadataDataSource { /** * Create a new geometry metadata from an envelope
 * @ param geoPackageId GeoPackage id
 * @ param tableName table name
 * @ param geomId geometry id
 * @ param envelope geometry envelope
 * @ return geometry metadata */
public GeometryMetadata create ( long geoPackageId , String tableName , long geomId , GeometryEnvelope envelope ) { } }

implementation: GeometryMetadata metadata = populate ( geoPackageId , tableName , geomId , envelope ) ; create ( metadata ) ; return metadata ;


signature:
public class GeometryMetadataDataSource { /** * Populate a new geometry metadata from an envelope
 * @ param geoPackageId GeoPackage id
 * @ param tableName table name
 * @ param geomId geometry id
 * @ param envelope geometry envelope
 * @ return geometry metadata */
public GeometryMetadata populate ( long geoPackageId , String tableName , long geomId , GeometryEnvelope envelope ) { } }

implementation: 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 ;


signature:
public class GeometryMetadataDataSource { /** * Delete the geometry metadata
 * @ param metadata geometry metadata
 * @ return deleted count */
public boolean delete ( GeometryMetadata metadata ) { } }

implementation: return delete ( metadata . getGeoPackageId ( ) , metadata . getTableName ( ) , metadata . getId ( ) ) ;


signature:
public class GeometryMetadataDataSource { /** * Delete geometry metadata by database
 * @ param geoPackageId GeoPackage id
 * @ return deleted count */
public int delete ( long geoPackageId ) { } }

implementation: String whereClause = GeometryMetadata . COLUMN_GEOPACKAGE_ID + " = ?" ; String [ ] whereArgs = new String [ ] { String . valueOf ( geoPackageId ) } ; int deleteCount = db . delete ( GeometryMetadata . TABLE_NAME , whereClause , whereArgs ) ; return deleteCount ;


signature:
public class GeometryMetadataDataSource { /** * Delete the geometry metadata
 * @ param geoPackage GeoPackage name
 * @ param tableName table name
 * @ param id id
 * @ return deleted flag */
public boolean delete ( String geoPackage , String tableName , long id ) { } }

implementation: return delete ( getGeoPackageId ( geoPackage ) , tableName , id ) ;


signature:
public class GeometryMetadataDataSource { /** * Create the geometry metadata or update if it already exists
 * @ param metadata geometry metadata
 * @ return created flag */
public boolean createOrUpdate ( GeometryMetadata metadata ) { } }

implementation: boolean success = false ; if ( exists ( metadata ) ) { success = update ( metadata ) ; } else { create ( metadata ) ; success = true ; } return success ;


signature:
public class GeometryMetadataDataSource { /** * Update the geometry metadata
 * @ param metadata geometry metadata
 * @ return updated flag */
public boolean update ( GeometryMetadata metadata ) { } }

implementation: 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 ;


signature:
public class GeometryMetadataDataSource { /** * Get a table metadata
 * @ param metadata geometry metadata
 * @ return geometry metadata */
public GeometryMetadata get ( GeometryMetadata metadata ) { } }

implementation: return get ( metadata . getGeoPackageId ( ) , metadata . getTableName ( ) , metadata . getId ( ) ) ;


signature:
public class GeometryMetadataDataSource { /** * Get a table metadata
 * @ param geoPackage GeoPackage name
 * @ param tableName table name
 * @ param id id
 * @ return geometry metadata */
public GeometryMetadata get ( String geoPackage , String tableName , long id ) { } }

implementation: return get ( getGeoPackageId ( geoPackage ) , tableName , id ) ;


signature:
public class GeometryMetadataDataSource { /** * Get a table metadata
 * @ param geoPackageId GeoPackage id
 * @ param tableName table name
 * @ param id id
 * @ return geometry metadata */
public GeometryMetadata get ( long geoPackageId , String tableName , long id ) { } }

implementation: String selection = GeometryMetadata . COLUMN_GEOPACKAGE_ID + " = ? AND " + GeometryMetadata . COLUMN_TABLE_NAME + " = ? AND " + GeometryMetadata . COLUMN_ID + " = ?" ; String [ ] selectionArgs = new String [ ] { String . valueOf ( geoPackageId ) , tableName , String . valueOf ( id ) } ; Cursor cursor = db . query ( GeometryMetadata . TABLE_NAME , GeometryMetadata . COLUMNS , selection , selectionArgs , null , null , null ) ; GeometryMetadata metadata = null ; try { if ( cursor . moveToNext ( ) ) { metadata = createGeometryMetadata ( cursor ) ; } } finally { cursor . close ( ) ; } return metadata ;


signature:
public class GeometryMetadataDataSource { /** * Query for all table geometry metadata
 * @ param geoPackage GeoPackage name
 * @ param tableName table name
 * @ return cursor that must be closed */
public Cursor query ( String geoPackage , String tableName ) { } }

implementation: return query ( getGeoPackageId ( geoPackage ) , tableName ) ;


signature:
public class GeometryMetadataDataSource { /** * Query for the bounds of the feature table index
 * @ param geoPackage GeoPackage name
 * @ param tableName table name
 * @ return bounding box
 * @ since 3.1.0 */
public BoundingBox getBoundingBox ( String geoPackage , String tableName ) { } }

implementation: return getBoundingBox ( getGeoPackageId ( geoPackage ) , tableName ) ;


signature:
public class GeometryMetadataDataSource { /** * Query for the bounds of the feature table index
 * @ param geoPackageId GeoPackage id
 * @ param tableName table name
 * @ return bounding box
 * @ since 3.1.0 */
public BoundingBox getBoundingBox ( long geoPackageId , String tableName ) { } }

implementation: BoundingBox boundingBox = null ; Cursor result = db . rawQuery ( "SELECT MIN(" + GeometryMetadata . COLUMN_MIN_X + "), MIN(" + GeometryMetadata . COLUMN_MIN_Y + "), MAX(" + GeometryMetadata . COLUMN_MAX_X + "), MAX(" + GeometryMetadata . COLUMN_MAX_Y + ") FROM " + GeometryMetadata . TABLE_NAME + " WHERE " + GeometryMetadata . COLUMN_GEOPACKAGE_ID + " = ? AND " + GeometryMetadata . COLUMN_TABLE_NAME + " = ?" , new String [ ] { String . valueOf ( geoPackageId ) , tableName } ) ; try { if ( result . moveToNext ( ) ) { boundingBox = new BoundingBox ( result . getDouble ( 0 ) , result . getDouble ( 1 ) , result . getDouble ( 2 ) , result . getDouble ( 3 ) ) ; } } finally { result . close ( ) ; } return boundingBox ;


signature:
public class GeometryMetadataDataSource { /** * Query for all table geometry metadata
 * @ param geoPackageId GeoPackage id
 * @ param tableName table name
 * @ return cursor that must be closed */
public Cursor query ( long geoPackageId , String tableName ) { } }

implementation: String selection = GeometryMetadata . COLUMN_GEOPACKAGE_ID + " = ? AND " + GeometryMetadata . COLUMN_TABLE_NAME + " = ?" ; String [ ] selectionArgs = new String [ ] { String . valueOf ( geoPackageId ) , tableName } ; Cursor cursor = db . query ( GeometryMetadata . TABLE_NAME , GeometryMetadata . COLUMNS , selection , selectionArgs , null , null , null ) ; return cursor ;


signature:
public class GeometryMetadataDataSource { /** * Query for all table geometry metadata matching the bounding box in the same projection
 * @ param geoPackage GeoPackage name
 * @ param tableName table name
 * @ param boundingBox bounding box
 * @ return cursor that must be closed */
public Cursor query ( String geoPackage , String tableName , BoundingBox boundingBox ) { } }

implementation: return query ( getGeoPackageId ( geoPackage ) , tableName , boundingBox ) ;


signature:
public class GeometryMetadataDataSource { /** * Query for all table geometry metadata count matching the bounding box in the same projection
 * @ param geoPackage GeoPackage name
 * @ param tableName table name
 * @ param boundingBox bounding box
 * @ return count
 * @ since 1.1.0 */
public int count ( String geoPackage , String tableName , BoundingBox boundingBox ) { } }

implementation: return count ( getGeoPackageId ( geoPackage ) , tableName , boundingBox ) ;


signature:
public class GeometryMetadataDataSource { /** * Query for all table geometry metadata matching the bounding box in the same projection
 * @ param geoPackageId GeoPackage id
 * @ param tableName table name
 * @ param boundingBox bounding box
 * @ return cursor that must be closed */
public Cursor query ( long geoPackageId , String tableName , BoundingBox boundingBox ) { } }

implementation: GeometryEnvelope envelope = new GeometryEnvelope ( ) ; envelope . setMinX ( boundingBox . getMinLongitude ( ) ) ; envelope . setMaxX ( boundingBox . getMaxLongitude ( ) ) ; envelope . setMinY ( boundingBox . getMinLatitude ( ) ) ; envelope . setMaxY ( boundingBox . getMaxLatitude ( ) ) ; return query ( geoPackageId , tableName , envelope ) ;


signature:
public class GeometryMetadataDataSource { /** * Query for all table geometry metadata matching the envelope
 * @ param geoPackage GeoPackage name
 * @ param tableName table name
 * @ param envelope geometry envelope
 * @ return cursor that must be closed */
public Cursor query ( String geoPackage , String tableName , GeometryEnvelope envelope ) { } }

implementation: return query ( getGeoPackageId ( geoPackage ) , tableName , envelope ) ;


signature:
public class GeometryMetadataDataSource { /** * Query for all table geometry metadata count matching the envelope
 * @ param geoPackage GeoPackage name
 * @ param tableName table name
 * @ param envelope geometry envelope
 * @ return count
 * @ since 1.1.0 */
public int count ( String geoPackage , String tableName , GeometryEnvelope envelope ) { } }

implementation: return count ( getGeoPackageId ( geoPackage ) , tableName , envelope ) ;


signature:
public class GeometryMetadataDataSource { /** * Query for all table geometry metadata matching the envelope
 * @ param geoPackageId GeoPackage id
 * @ param tableName table name
 * @ param envelope geometry envelope
 * @ return cursor that must be closed */
public Cursor query ( long geoPackageId , String tableName , GeometryEnvelope envelope ) { } }

implementation: StringBuilder selection = new StringBuilder ( ) ; selection . append ( GeometryMetadata . COLUMN_GEOPACKAGE_ID ) . append ( " = ? AND " ) . append ( GeometryMetadata . COLUMN_TABLE_NAME ) . append ( " = ?" ) ; selection . append ( " AND " ) . append ( GeometryMetadata . COLUMN_MIN_X ) . append ( " <= ?" ) ; selection . append ( " AND " ) . append ( GeometryMetadata . COLUMN_MAX_X ) . append ( " >= ?" ) ; selection . append ( " AND " ) . append ( GeometryMetadata . COLUMN_MIN_Y ) . append ( " <= ?" ) ; selection . append ( " AND " ) . append ( GeometryMetadata . COLUMN_MAX_Y ) . append ( " >= ?" ) ; int args = 6 ; if ( envelope . hasZ ( ) ) { args += 2 ; selection . append ( " AND " ) . append ( GeometryMetadata . COLUMN_MIN_Z ) . append ( " <= ?" ) ; selection . append ( " AND " ) . append ( GeometryMetadata . COLUMN_MAX_Z ) . append ( " >= ?" ) ; } if ( envelope . hasM ( ) ) { args += 2 ; selection . append ( " AND " ) . append ( GeometryMetadata . COLUMN_MIN_M ) . append ( " <= ?" ) ; selection . append ( " AND " ) . append ( GeometryMetadata . COLUMN_MAX_M ) . append ( " >= ?" ) ; } double minX = envelope . getMinX ( ) - tolerance ; double maxX = envelope . getMaxX ( ) + tolerance ; double minY = envelope . getMinY ( ) - tolerance ; double maxY = envelope . getMaxY ( ) + tolerance ; String [ ] selectionArgs = new String [ args ] ; int argCount = 0 ; selectionArgs [ argCount ++ ] = String . valueOf ( geoPackageId ) ; selectionArgs [ argCount ++ ] = tableName ; selectionArgs [ argCount ++ ] = String . valueOf ( maxX ) ; selectionArgs [ argCount ++ ] = String . valueOf ( minX ) ; selectionArgs [ argCount ++ ] = String . valueOf ( maxY ) ; selectionArgs [ argCount ++ ] = String . valueOf ( minY ) ; if ( envelope . hasZ ( ) ) { double minZ = envelope . getMinZ ( ) - tolerance ; double maxZ = envelope . getMaxZ ( ) + tolerance ; selectionArgs [ argCount ++ ] = String . valueOf ( maxZ ) ; selectionArgs [ argCount ++ ] = String . valueOf ( minZ ) ; } if ( envelope . hasM ( ) ) { double minM = envelope . getMinM ( ) - tolerance ; double maxM = envelope . getMaxM ( ) + tolerance ; selectionArgs [ argCount ++ ] = String . valueOf ( maxM ) ; selectionArgs [ argCount ++ ] = String . valueOf ( minM ) ; } Cursor cursor = db . query ( GeometryMetadata . TABLE_NAME , GeometryMetadata . COLUMNS , selection . toString ( ) , selectionArgs , null , null , null ) ; return cursor ;


signature:
public class GeometryMetadataDataSource { /** * Query for all table geometry metadata count matching the envelope
 * @ param geoPackageId GeoPackage id
 * @ param tableName table name
 * @ param envelope geometry envelope
 * @ return count
 * @ since 1.1.0 */
public int count ( long geoPackageId , String tableName , GeometryEnvelope envelope ) { } }

implementation: Cursor cursor = query ( geoPackageId , tableName , envelope ) ; int count = cursor . getCount ( ) ; cursor . close ( ) ; return count ;


signature:
public class GeometryMetadataDataSource { /** * Create a geometry metadata from the current cursor location
 * @ param cursor cursor
 * @ return geometry metadata */
public static GeometryMetadata createGeometryMetadata ( Cursor cursor ) { } }

implementation: 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 ;


signature:
public class UserDao { /** * { @ inheritDoc }
 * Handles requery of invalid id row */
@ Override public TRow queryForIdRow ( long id ) { } }

implementation: TRow row = null ; TResult readCursor = queryForId ( id ) ; if ( readCursor . moveToNext ( ) ) { row = readCursor . getRow ( ) ; if ( ! row . isValid ( ) && readCursor . moveToNext ( ) ) { row = readCursor . getRow ( ) ; } } readCursor . close ( ) ; return row ;


signature:
public class UserDao { /** * Update all rows matching the where clause with the provided values
 * @ param values content values
 * @ param whereClause where clause
 * @ param whereArgs where arguments
 * @ return updated rows */
public int update ( ContentValues values , String whereClause , String [ ] whereArgs ) { } }

implementation: return db . update ( getTableName ( ) , values , whereClause , whereArgs ) ;


signature:
public class UserDao { /** * { @ inheritDoc } */
@ Override public long insert ( TRow row ) { } }

implementation: long id = db . insertOrThrow ( getTableName ( ) , null , row . toContentValues ( ) ) ; if ( row . hasIdColumn ( ) ) { row . setId ( id ) ; } return id ;


signature:
public class NumberFeaturesTile { /** * { @ inheritDoc } */
@ Override public Bitmap drawTile ( int tileWidth , int tileHeight , long tileFeatureCount , FeatureIndexResults featureIndexResults ) { } }

implementation: String featureText = String . valueOf ( tileFeatureCount ) ; Bitmap bitmap = drawTile ( tileWidth , tileHeight , featureText ) ; return bitmap ;


signature:
public class NumberFeaturesTile { /** * { @ inheritDoc } */
@ Override public Bitmap drawUnindexedTile ( int tileWidth , int tileHeight , long totalFeatureCount , FeatureCursor allFeatureResults ) { } }

implementation:
Bitmap bitmap = null ; if ( drawUnindexedTiles ) { // Draw a tile indicating we have no idea if there are features inside .
// The table is not indexed and more features exist than the max feature count set .
bitmap = drawTile ( tileWidth , tileHeight , "?" ) ; } return bitmap ;


signature:
public class NumberFeaturesTile { /** * Draw a tile with the provided text label in the middle
 * @ param tileWidth tile width
 * @ param tileHeight tile height
 * @ param text text
 * @ return tile bitmap */
private Bitmap drawTile ( int tileWidth , int tileHeight , String text ) { } }

implementation:
// 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 ;


signature:
public class SimpleAttributesDao { /** * Get the simple attributes rows that exist with the provided ids
 * @ param ids list of ids
 * @ return simple attributes rows */
public List < SimpleAttributesRow > getRows ( List < Long > ids ) { } }

implementation: List < SimpleAttributesRow > simpleAttributesRows = new ArrayList < > ( ) ; for ( long id : ids ) { UserCustomRow userCustomRow = queryForIdRow ( id ) ; if ( userCustomRow != null ) { simpleAttributesRows . add ( getRow ( userCustomRow ) ) ; } } return simpleAttributesRows ;


signature:
public class GeoPackageImpl { /** * { @ inheritDoc } */
@ Override protected BoundingBox getFeatureBoundingBox ( Projection projection , String table , boolean manual ) { } }

implementation: BoundingBox boundingBox = null ; FeatureIndexManager indexManager = new FeatureIndexManager ( context , this , table ) ; try { if ( manual || indexManager . isIndexed ( ) ) { boundingBox = indexManager . getBoundingBox ( projection ) ; } } finally { indexManager . close ( ) ; } return boundingBox ;


signature:
public class GeoPackageImpl { /** * { @ inheritDoc } */
@ Override public void registerCursorWrapper ( String table , GeoPackageCursorWrapper cursorWrapper ) { } }

implementation: cursorFactory . registerTable ( table , cursorWrapper ) ;


signature:
public class GeoPackageImpl { /** * { @ inheritDoc } */
@ Override public FeatureDao getFeatureDao ( GeometryColumns geometryColumns ) { } }

implementation:
if ( geometryColumns == null ) { throw new GeoPackageException ( "Non null " + GeometryColumns . class . getSimpleName ( ) + " is required to create " + FeatureDao . class . getSimpleName ( ) ) ; } // Read the existing table and create the dao
FeatureTableReader tableReader = new FeatureTableReader ( geometryColumns ) ; final FeatureTable featureTable = tableReader . readTable ( new FeatureWrapperConnection ( database ) ) ; featureTable . setContents ( geometryColumns . getContents ( ) ) ; FeatureConnection userDb = new FeatureConnection ( database ) ; FeatureDao dao = new FeatureDao ( getName ( ) , database , userDb , geometryColumns , featureTable ) ; // Register the table name ( with and without quotes ) to wrap cursors with the feature cursor
registerCursorWrapper ( geometryColumns . getTableName ( ) , new GeoPackageCursorWrapper ( ) { @ Override public Cursor wrapCursor ( Cursor cursor ) { return new FeatureCursor ( featureTable , cursor ) ; } } ) ; // If the GeoPackage is writable and the feature table has a RTree Index
// extension , drop the RTree triggers . User defined functions are currently not supported .
if ( writable ) { RTreeIndexExtension rtree = new RTreeIndexExtension ( this ) ; rtree . dropTriggers ( featureTable ) ; } return dao ;


signature:
public class GeoPackageImpl { /** * { @ inheritDoc } */
@ Override public FeatureDao getFeatureDao ( Contents contents ) { } }

implementation: if ( contents == null ) { throw new GeoPackageException ( "Non null " + Contents . class . getSimpleName ( ) + " is required to create " + FeatureDao . class . getSimpleName ( ) ) ; } GeometryColumns geometryColumns = contents . getGeometryColumns ( ) ; if ( geometryColumns == null ) { throw new GeoPackageException ( "No " + GeometryColumns . class . getSimpleName ( ) + " exists for " + Contents . class . getSimpleName ( ) + " " + contents . getId ( ) ) ; } return getFeatureDao ( geometryColumns ) ;


signature:
public class GeoPackageImpl { /** * { @ inheritDoc } */
@ Override public FeatureDao getFeatureDao ( String tableName ) { } }

implementation:
GeometryColumnsDao dao = getGeometryColumnsDao ( ) ; List < GeometryColumns > geometryColumnsList ; try { geometryColumnsList = dao . queryForEq ( GeometryColumns . COLUMN_TABLE_NAME , tableName ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to retrieve " + FeatureDao . class . getSimpleName ( ) + " for table name: " + tableName + ". Exception retrieving " + GeometryColumns . class . getSimpleName ( ) + "." , e ) ; } if ( geometryColumnsList . isEmpty ( ) ) { throw new GeoPackageException ( "No Feature Table exists for table name: " + tableName ) ; } else if ( geometryColumnsList . size ( ) > 1 ) { // This shouldn ' t happen with the table name unique constraint on
// geometry columns
throw new GeoPackageException ( "Unexpected state. More than one " + GeometryColumns . class . getSimpleName ( ) + " matched for table name: " + tableName + ", count: " + geometryColumnsList . size ( ) ) ; } return getFeatureDao ( geometryColumnsList . get ( 0 ) ) ;


signature:
public class GeoPackageImpl { /** * { @ inheritDoc } */
@ Override public TileDao getTileDao ( Contents contents ) { } }

implementation: if ( contents == null ) { throw new GeoPackageException ( "Non null " + Contents . class . getSimpleName ( ) + " is required to create " + TileDao . class . getSimpleName ( ) ) ; } TileMatrixSet tileMatrixSet = contents . getTileMatrixSet ( ) ; if ( tileMatrixSet == null ) { throw new GeoPackageException ( "No " + TileMatrixSet . class . getSimpleName ( ) + " exists for " + Contents . class . getSimpleName ( ) + " " + contents . getId ( ) ) ; } return getTileDao ( tileMatrixSet ) ;


signature:
public class GeoPackageImpl { /** * { @ inheritDoc } */
@ Override public AttributesDao getAttributesDao ( Contents contents ) { } }

implementation:
if ( contents == null ) { throw new GeoPackageException ( "Non null " + Contents . class . getSimpleName ( ) + " is required to create " + AttributesDao . class . getSimpleName ( ) ) ; } if ( contents . getDataType ( ) != ContentsDataType . ATTRIBUTES ) { throw new GeoPackageException ( Contents . class . getSimpleName ( ) + " is required to be of type " + ContentsDataType . ATTRIBUTES + ". Actual: " + contents . getDataTypeString ( ) ) ; } // Read the existing table and create the dao
AttributesTableReader tableReader = new AttributesTableReader ( contents . getTableName ( ) ) ; final AttributesTable attributesTable = tableReader . readTable ( new AttributesWrapperConnection ( database ) ) ; attributesTable . setContents ( contents ) ; AttributesConnection userDb = new AttributesConnection ( database ) ; AttributesDao dao = new AttributesDao ( getName ( ) , database , userDb , attributesTable ) ; // Register the table name ( with and without quotes ) to wrap cursors with the attributes cursor
registerCursorWrapper ( attributesTable . getTableName ( ) , new GeoPackageCursorWrapper ( ) { @ Override public Cursor wrapCursor ( Cursor cursor ) { return new AttributesCursor ( attributesTable , cursor ) ; } } ) ; return dao ;


signature:
public class GeoPackageImpl { /** * { @ inheritDoc } */
@ Override public AttributesDao getAttributesDao ( String tableName ) { } }

implementation: ContentsDao dao = getContentsDao ( ) ; Contents contents = null ; try { contents = dao . queryForId ( tableName ) ; } catch ( SQLException e ) { throw new GeoPackageException ( "Failed to retrieve " + Contents . class . getSimpleName ( ) + " for table name: " + tableName , e ) ; } if ( contents == null ) { throw new GeoPackageException ( "No Contents Table exists for table name: " + tableName ) ; } return getAttributesDao ( contents ) ;


signature:
public class GeoPackageImpl { /** * { @ inheritDoc } */
@ Override public Cursor rawQuery ( String sql , String [ ] args ) { } }

implementation: return database . rawQuery ( sql , args ) ;


signature:
public class GeoPackageImpl { /** * { @ inheritDoc } */
@ Override public Cursor foreignKeyCheck ( ) { } }

implementation: Cursor cursor = rawQuery ( "PRAGMA foreign_key_check" , null ) ; if ( ! cursor . moveToNext ( ) ) { cursor . close ( ) ; cursor = null ; } return cursor ;


signature:
public class GeoPackageImpl { /** * Check the cursor returned from the integrity check to see if things are " ok "
 * @ param cursor
 * @ return null if ok , else the open cursor */
private Cursor integrityCheck ( Cursor cursor ) { } }

implementation: if ( cursor . moveToNext ( ) ) { String value = cursor . getString ( 0 ) ; if ( value . equals ( "ok" ) ) { cursor . close ( ) ; cursor = null ; } } return cursor ;


signature:
public class RelatedTablesExtension { /** * { @ inheritDoc } */
@ Override public String getPrimaryKeyColumnName ( String tableName ) { } }

implementation: UserCustomTable table = UserCustomTableReader . readTable ( connection , tableName ) ; UserCustomColumn pkColumn = table . getPkColumn ( ) ; if ( pkColumn == null ) { throw new GeoPackageException ( "Found no primary key for table " + tableName ) ; } return pkColumn . getName ( ) ;


signature:
public class RelatedTablesExtension { /** * Get a User Mapping DAO from a table name
 * @ param tableName mapping table name
 * @ return user mapping dao */
public UserMappingDao getMappingDao ( String tableName ) { } }

implementation: UserMappingDao userMappingDao = new UserMappingDao ( getUserDao ( tableName ) ) ; userMappingDao . registerCursorWrapper ( getGeoPackage ( ) ) ; return userMappingDao ;


signature:
public class RelatedTablesExtension { /** * Get a related simple attributes table DAO
 * @ param tableName simple attributes table name
 * @ return simple attributes DAO */
public SimpleAttributesDao getSimpleAttributesDao ( String tableName ) { } }

implementation: SimpleAttributesDao simpleAttributesDao = new SimpleAttributesDao ( getUserDao ( tableName ) ) ; simpleAttributesDao . registerCursorWrapper ( getGeoPackage ( ) ) ; setContents ( simpleAttributesDao . getTable ( ) ) ; return simpleAttributesDao ;


signature:
public class RelatedTablesExtension { /** * Get the related id mappings for the base id
 * @ param extendedRelation extended relation
 * @ param baseId base id
 * @ return IDs representing the matching related IDs */
public List < Long > getMappingsForBase ( ExtendedRelation extendedRelation , long baseId ) { } }

implementation: return getMappingsForBase ( extendedRelation . getMappingTableName ( ) , baseId ) ;


signature:
public class RelatedTablesExtension { /** * Get the base id mappings for the related id
 * @ param extendedRelation extended relation
 * @ param relatedId related id
 * @ return IDs representing the matching base IDs */
public List < Long > getMappingsForRelated ( ExtendedRelation extendedRelation , long relatedId ) { } }

implementation: return getMappingsForRelated ( extendedRelation . getMappingTableName ( ) , relatedId ) ;


signature:
public class RelatedTablesExtension { /** * Determine if the base id and related id mapping exists
 * @ param tableName mapping table name
 * @ param baseId base id
 * @ param relatedId related id
 * @ return true if mapping exists
 * @ since 3.2.0 */
public boolean hasMapping ( String tableName , long baseId , long relatedId ) { } }

implementation: boolean has = false ; UserMappingDao userMappingDao = getMappingDao ( tableName ) ; UserCustomCursor cursor = userMappingDao . queryByIds ( baseId , relatedId ) ; try { has = cursor . getCount ( ) > 0 ; } finally { cursor . close ( ) ; } return has ;


signature:
public class TileCursor { /** * { @ inheritDoc } */
@ Override public TileRow getRow ( int [ ] columnTypes , Object [ ] values ) { } }

implementation: return new TileRow ( getTable ( ) , columnTypes , values ) ;


signature:
public class TileCursor { /** * { @ inheritDoc } */
@ Override protected UserInvalidCursor < TileColumn , TileTable , TileRow , ? extends UserCursor < TileColumn , TileTable , TileRow > , ? extends UserDao < TileColumn , TileTable , TileRow , ? extends UserCursor < TileColumn , TileTable , TileRow > > > createInvalidCursor ( UserDao dao , UserCursor cursor , List < Integer > invalidPositions , List < TileColumn > blobColumns ) { } }

implementation: return new TileInvalidCursor ( ( TileDao ) dao , ( TileCursor ) cursor , invalidPositions , blobColumns ) ;


signature:
public class UserCustomDao { /** * Get the count of the cursor and close it
 * @ param cursor cursor
 * @ return count */
protected int count ( UserCustomCursor cursor ) { } }

implementation: int count = 0 ; try { count = cursor . getCount ( ) ; } finally { cursor . close ( ) ; } return count ;


signature:
public class UserCustomDao { /** * Register the cursor wrapper into the GeoPackage
 * @ param geoPackage GeoPackage */
public void registerCursorWrapper ( GeoPackage geoPackage ) { } }

implementation: geoPackage . registerCursorWrapper ( getTableName ( ) , new GeoPackageCursorWrapper ( ) { @ Override public Cursor wrapCursor ( Cursor cursor ) { return new UserCustomCursor ( getTable ( ) , cursor ) ; } } ) ;


signature:
public class UserCustomDao { /** * Read the database table and create a DAO
 * @ param geoPackage GeoPackage
 * @ param tableName table name
 * @ return user custom DAO */
public static UserCustomDao readTable ( GeoPackage geoPackage , String tableName ) { } }

implementation: 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 ;


signature:
public class TileCreator { /** * Get the tile from the request bounding box in the request projection
 * @ param requestBoundingBox request bounding box in the request projection
 * @ return tile */
public GeoPackageTile getTile ( BoundingBox requestBoundingBox ) { } }

implementation:
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 ;


signature:
public class TileCreator { /** * Draw the tile from the tile results
 * @ param tileMatrix
 * @ param tileResults
 * @ param requestProjectedBoundingBox
 * @ param tileWidth
 * @ param tileHeight
 * @ return tile bitmap */
private Bitmap drawTile ( TileMatrix tileMatrix , TileCursor tileResults , BoundingBox requestProjectedBoundingBox , int tileWidth , int tileHeight ) { } }

implementation:
// 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 ;


signature:
public class TileCreator { /** * Reproject the tile to the requested projection
 * @ param tile tile in the tile matrix projection
 * @ param requestedTileWidth requested tile width
 * @ param requestedTileHeight requested tile height
 * @ param requestBoundingBox request bounding box in the request projection
 * @ param transformRequestToTiles transformation from request to tiles
 * @ param tilesBoundingBox request bounding box in the tile matrix projection
 * @ return projected tile */
private Bitmap reprojectTile ( Bitmap tile , int requestedTileWidth , int requestedTileHeight , BoundingBox requestBoundingBox , ProjectionTransform transformRequestToTiles , BoundingBox tilesBoundingBox ) { } }

implementation:
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 ;


signature:
public class TileCreator { /** * Get the tile matrices that may contain the tiles for the bounding box , matches against the bounding box and zoom level options
 * @ param projectedRequestBoundingBox bounding box projected to the tiles
 * @ return tile matrices */
private List < TileMatrix > getTileMatrices ( BoundingBox projectedRequestBoundingBox ) { } }

implementation:
List < TileMatrix > tileMatrices = new ArrayList < > ( ) ; // Check if the request overlaps the tile matrix set
if ( ! tileDao . getTileMatrices ( ) . isEmpty ( ) && projectedRequestBoundingBox . intersects ( tileSetBoundingBox ) ) { // Get the tile distance
double distanceWidth = projectedRequestBoundingBox . getMaxLongitude ( ) - projectedRequestBoundingBox . getMinLongitude ( ) ; double distanceHeight = projectedRequestBoundingBox . getMaxLatitude ( ) - projectedRequestBoundingBox . getMinLatitude ( ) ; // Get the zoom level to request based upon the tile size
Long requestZoomLevel = null ; if ( scaling != null ) { // When options are provided , get the approximate zoom level regardless of whether a tile level exists
requestZoomLevel = tileDao . getApproximateZoomLevel ( distanceWidth , distanceHeight ) ; } else { // Get the closest existing zoom level
requestZoomLevel = tileDao . getZoomLevel ( distanceWidth , distanceHeight ) ; } // If there is a matching zoom level
if ( requestZoomLevel != null ) { List < Long > zoomLevels = null ; // If options are configured , build the possible zoom levels in order to request
if ( scaling != null && scaling . getScalingType ( ) != null ) { // Find zoom in levels
List < Long > zoomInLevels = new ArrayList < > ( ) ; if ( scaling . isZoomIn ( ) ) { long zoomIn = scaling . getZoomIn ( ) != null ? requestZoomLevel + scaling . getZoomIn ( ) : tileDao . getMaxZoom ( ) ; for ( long zoomLevel = requestZoomLevel + 1 ; zoomLevel <= zoomIn ; zoomLevel ++ ) { zoomInLevels . add ( zoomLevel ) ; } } // Find zoom out levels
List < Long > zoomOutLevels = new ArrayList < > ( ) ; if ( scaling . isZoomOut ( ) ) { long zoomOut = scaling . getZoomOut ( ) != null ? requestZoomLevel - scaling . getZoomOut ( ) : tileDao . getMinZoom ( ) ; for ( long zoomLevel = requestZoomLevel - 1 ; zoomLevel >= zoomOut ; zoomLevel -- ) { zoomOutLevels . add ( zoomLevel ) ; } } if ( zoomInLevels . isEmpty ( ) ) { // Only zooming out
zoomLevels = zoomOutLevels ; } else if ( zoomOutLevels . isEmpty ( ) ) { // Only zooming in
zoomLevels = zoomInLevels ; } else { // Determine how to order the zoom in and zoom out levels
TileScalingType type = scaling . getScalingType ( ) ; switch ( type ) { case IN : case IN_OUT : // Order zoom in levels before zoom out levels
zoomLevels = zoomInLevels ; zoomLevels . addAll ( zoomOutLevels ) ; break ; case OUT : case OUT_IN : // Order zoom out levels before zoom in levels
zoomLevels = zoomOutLevels ; zoomLevels . addAll ( zoomInLevels ) ; break ; case CLOSEST_IN_OUT : case CLOSEST_OUT_IN : // Alternate the zoom in and out levels
List < Long > firstLevels ; List < Long > secondLevels ; if ( type == TileScalingType . CLOSEST_IN_OUT ) { // Alternate starting with zoom in
firstLevels = zoomInLevels ; secondLevels = zoomOutLevels ; } else { // Alternate starting with zoom out
firstLevels = zoomOutLevels ; secondLevels = zoomInLevels ; } zoomLevels = new ArrayList < > ( ) ; int maxLevels = Math . max ( firstLevels . size ( ) , secondLevels . size ( ) ) ; for ( int i = 0 ; i < maxLevels ; i ++ ) { if ( i < firstLevels . size ( ) ) { zoomLevels . add ( firstLevels . get ( i ) ) ; } if ( i < secondLevels . size ( ) ) { zoomLevels . add ( secondLevels . get ( i ) ) ; } } break ; default : throw new GeoPackageException ( "Unsupported " + TileScalingType . class . getSimpleName ( ) + ": " + type ) ; } } } else { zoomLevels = new ArrayList < > ( ) ; } // Always check the request zoom level first
zoomLevels . add ( 0 , requestZoomLevel ) ; // Build a list of tile matrices that exist for the zoom levels
for ( long zoomLevel : zoomLevels ) { TileMatrix tileMatrix = tileDao . getTileMatrix ( zoomLevel ) ; if ( tileMatrix != null ) { tileMatrices . add ( tileMatrix ) ; } } } } return tileMatrices ;


signature:
public class TileCreator { /** * Get the tile row results of tiles needed to draw the requested bounding box tile
 * @ param projectedRequestBoundingBox bounding box projected to the tiles
 * @ param tileMatrix
 * @ return tile cursor results or null */
private TileCursor retrieveTileResults ( BoundingBox projectedRequestBoundingBox , TileMatrix tileMatrix ) { } }

implementation:
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 ;


signature:
public class FeatureTiles { /** * Call after making changes to the point icon , point radius , or paint stroke widths .
 * Determines the pixel overlap between tiles */
public void calculateDrawOverlap ( ) { } }

implementation:
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 ) ; } }


signature:
public class FeatureTiles { /** * Set the density
 * @ param density density
 * @ since 3.2.0 */
public void setDensity ( float density ) { } }

implementation: this . density = density ; linePaint . setStrokeWidth ( this . density * lineStrokeWidth ) ; polygonPaint . setStrokeWidth ( this . density * polygonStrokeWidth ) ; featurePaintCache . clear ( ) ;


signature:
public class FeatureTiles { /** * Set the line paint
 * @ param linePaint line paint */
public void setLinePaint ( Paint linePaint ) { } }

implementation: if ( linePaint == null ) { throw new AssertionError ( "Line Paint can not be null" ) ; } this . linePaint = linePaint ; setLineStrokeWidth ( linePaint . getStrokeWidth ( ) ) ;


signature:
public class FeatureTiles { /** * Set the polygon paint
 * @ param polygonPaint polygon paint */
public void setPolygonPaint ( Paint polygonPaint ) { } }

implementation: if ( polygonPaint == null ) { throw new AssertionError ( "Polygon Paint can not be null" ) ; } this . polygonPaint = polygonPaint ; setPolygonStrokeWidth ( polygonPaint . getStrokeWidth ( ) ) ;


signature:
public class FeatureTiles { /** * Draw the tile and get the bytes from the x , y , and zoom level
 * @ param x x coordinate
 * @ param y y coordinate
 * @ param zoom zoom level
 * @ return tile bytes , or null */
public byte [ ] drawTileBytes ( int x , int y , int zoom ) { } }

implementation:
Bitmap bitmap = drawTile ( x , y , zoom ) ; byte [ ] tileData = null ; // Convert the bitmap to bytes
if ( bitmap != null ) { try { tileData = BitmapConverter . toBytes ( bitmap , compressFormat ) ; } catch ( IOException e ) { Log . e ( FeatureTiles . class . getSimpleName ( ) , "Failed to create tile. x: " + x + ", y: " + y + ", zoom: " + zoom , e ) ; } finally { bitmap . recycle ( ) ; } } return tileData ;


signature:
public class FeatureTiles { /** * Draw a tile bitmap from the x , y , and zoom level
 * @ param x x coordinate
 * @ param y y coordinate
 * @ param zoom zoom level
 * @ return tile bitmap , or null */
public Bitmap drawTile ( int x , int y , int zoom ) { } }

implementation: Bitmap bitmap ; if ( isIndexQuery ( ) ) { bitmap = drawTileQueryIndex ( x , y , zoom ) ; } else { bitmap = drawTileQueryAll ( x , y , zoom ) ; } return bitmap ;


signature:
public class FeatureTiles { /** * Draw a tile bitmap from the x , y , and zoom level by querying features in the tile location
 * @ param x x coordinate
 * @ param y y coordinate
 * @ param zoom zoom level
 * @ return drawn bitmap , or null */
public Bitmap drawTileQueryIndex ( int x , int y , int zoom ) { } }

implementation:
// Get the web mercator bounding box
BoundingBox webMercatorBoundingBox = TileBoundingBoxUtils . getWebMercatorBoundingBox ( x , y , zoom ) ; Bitmap bitmap = null ; // Query for geometries matching the bounds in the index
FeatureIndexResults results = queryIndexedFeatures ( webMercatorBoundingBox ) ; try { long tileCount = results . count ( ) ; // Draw if at least one geometry exists
if ( tileCount > 0 ) { if ( maxFeaturesPerTile == null || tileCount <= maxFeaturesPerTile . longValue ( ) ) { // Draw the tile bitmap
bitmap = drawTile ( zoom , webMercatorBoundingBox , results ) ; } else if ( maxFeaturesTileDraw != null ) { // Draw the max features tile
bitmap = maxFeaturesTileDraw . drawTile ( tileWidth , tileHeight , tileCount , results ) ; } } } finally { results . close ( ) ; } return bitmap ;


signature:
public class FeatureTiles { /** * Query for feature result count in the x , y , and zoom
 * @ param x x coordinate
 * @ param y y coordinate
 * @ param zoom zoom level
 * @ return feature count
 * @ since 1.1.0 */
public long queryIndexedFeaturesCount ( int x , int y , int zoom ) { } }

implementation:
// Get the web mercator bounding box
BoundingBox webMercatorBoundingBox = TileBoundingBoxUtils . getWebMercatorBoundingBox ( x , y , zoom ) ; // Query for the count of geometries matching the bounds in the index
long count = queryIndexedFeaturesCount ( webMercatorBoundingBox ) ; return count ;


signature:
public class FeatureTiles { /** * Query for feature result count in the bounding box
 * @ param webMercatorBoundingBox web mercator bounding box
 * @ return feature count
 * @ since 3.2.0 */
public long queryIndexedFeaturesCount ( BoundingBox webMercatorBoundingBox ) { } }

implementation:
// Query for geometries matching the bounds in the index
FeatureIndexResults results = queryIndexedFeatures ( webMercatorBoundingBox ) ; long count = 0 ; try { count = results . count ( ) ; } finally { results . close ( ) ; } return count ;


signature:
public class FeatureTiles { /** * Query for feature results in the x , y , and zoom level by querying features in the tile location
 * @ param x x coordinate
 * @ param y y coordinate
 * @ param zoom zoom level
 * @ return feature index results
 * @ since 3.2.0 */
public FeatureIndexResults queryIndexedFeatures ( int x , int y , int zoom ) { } }

implementation:
// Get the web mercator bounding box
BoundingBox webMercatorBoundingBox = TileBoundingBoxUtils . getWebMercatorBoundingBox ( x , y , zoom ) ; // Query for the geometries matching the bounds in the index
return queryIndexedFeatures ( webMercatorBoundingBox ) ;


signature:
public class FeatureTiles { /** * Query for feature results in the bounding box
 * @ param webMercatorBoundingBox web mercator bounding box
 * @ return feature index results
 * @ since 1.1.0 */
public FeatureIndexResults queryIndexedFeatures ( BoundingBox webMercatorBoundingBox ) { } }

implementation:
// Create an expanded bounding box to handle features outside the tile
// that overlap
BoundingBox expandedQueryBoundingBox = expandBoundingBox ( webMercatorBoundingBox ) ; // Query for geometries matching the bounds in the index
FeatureIndexResults results = indexManager . query ( expandedQueryBoundingBox , WEB_MERCATOR_PROJECTION ) ; return results ;


signature:
public class FeatureTiles { /** * Create an expanded bounding box to handle features outside the tile that
 * overlap
 * @ param boundingBox bounding box
 * @ param projection bounding box projection
 * @ return bounding box
 * @ since 3.2.0 */
public BoundingBox expandBoundingBox ( BoundingBox boundingBox , Projection projection ) { } }

implementation: BoundingBox expandedBoundingBox = boundingBox ; ProjectionTransform toWebMercator = projection . getTransformation ( ProjectionConstants . EPSG_WEB_MERCATOR ) ; if ( ! toWebMercator . isSameProjection ( ) ) { expandedBoundingBox = expandedBoundingBox . transform ( toWebMercator ) ; } expandedBoundingBox = expandBoundingBox ( expandedBoundingBox ) ; if ( ! toWebMercator . isSameProjection ( ) ) { ProjectionTransform fromWebMercator = toWebMercator . getInverseTransformation ( ) ; expandedBoundingBox = expandedBoundingBox . transform ( fromWebMercator ) ; } return expandedBoundingBox ;


signature:
public class FeatureTiles { /** * Create an expanded bounding box to handle features outside the tile that
 * overlap
 * @ param webMercatorBoundingBox web mercator bounding box
 * @ param tileWebMercatorBoundingBox tile web mercator bounding box
 * @ return bounding box
 * @ since 3.2.0 */
public BoundingBox expandBoundingBox ( BoundingBox webMercatorBoundingBox , BoundingBox tileWebMercatorBoundingBox ) { } }

implementation:
// Create an expanded bounding box to handle features outside the tile
// that overlap
double minLongitude = TileBoundingBoxUtils . getLongitudeFromPixel ( tileWidth , webMercatorBoundingBox , tileWebMercatorBoundingBox , 0 - widthOverlap ) ; double maxLongitude = TileBoundingBoxUtils . getLongitudeFromPixel ( tileWidth , webMercatorBoundingBox , tileWebMercatorBoundingBox , tileWidth + widthOverlap ) ; double maxLatitude = TileBoundingBoxUtils . getLatitudeFromPixel ( tileHeight , webMercatorBoundingBox , tileWebMercatorBoundingBox , 0 - heightOverlap ) ; double minLatitude = TileBoundingBoxUtils . getLatitudeFromPixel ( tileHeight , webMercatorBoundingBox , tileWebMercatorBoundingBox , tileHeight + heightOverlap ) ; // Choose the most expanded longitudes and latitudes
minLongitude = Math . min ( minLongitude , webMercatorBoundingBox . getMinLongitude ( ) ) ; maxLongitude = Math . max ( maxLongitude , webMercatorBoundingBox . getMaxLongitude ( ) ) ; minLatitude = Math . min ( minLatitude , webMercatorBoundingBox . getMinLatitude ( ) ) ; maxLatitude = Math . max ( maxLatitude , webMercatorBoundingBox . getMaxLatitude ( ) ) ; // Bound with the web mercator limits
minLongitude = Math . max ( minLongitude , - 1 * ProjectionConstants . WEB_MERCATOR_HALF_WORLD_WIDTH ) ; maxLongitude = Math . min ( maxLongitude , ProjectionConstants . WEB_MERCATOR_HALF_WORLD_WIDTH ) ; minLatitude = Math . max ( minLatitude , - 1 * ProjectionConstants . WEB_MERCATOR_HALF_WORLD_WIDTH ) ; maxLatitude = Math . min ( maxLatitude , ProjectionConstants . WEB_MERCATOR_HALF_WORLD_WIDTH ) ; BoundingBox expandedBoundingBox = new BoundingBox ( minLongitude , minLatitude , maxLongitude , maxLatitude ) ; return expandedBoundingBox ;


signature:
public class FeatureTiles { /** * Draw a tile bitmap from the x , y , and zoom level by querying all features . This could
 * be very slow if there are a lot of features
 * @ param x x coordinate
 * @ param y y coordinate
 * @ param zoom zoom level
 * @ return drawn bitmap , or null */
public Bitmap drawTileQueryAll ( int x , int y , int zoom ) { } }

implementation:
BoundingBox boundingBox = TileBoundingBoxUtils . getWebMercatorBoundingBox ( x , y , zoom ) ; Bitmap bitmap = null ; // Query for all features
FeatureCursor cursor = featureDao . queryForAll ( ) ; try { int totalCount = cursor . getCount ( ) ; // Draw if at least one geometry exists
if ( totalCount > 0 ) { if ( maxFeaturesPerTile == null || totalCount <= maxFeaturesPerTile ) { // Draw the tile bitmap
bitmap = drawTile ( zoom , boundingBox , cursor ) ; } else if ( maxFeaturesTileDraw != null ) { // Draw the unindexed max features tile
bitmap = maxFeaturesTileDraw . drawUnindexedTile ( tileWidth , tileHeight , totalCount , cursor ) ; } } } finally { cursor . close ( ) ; } return bitmap ;


signature:
public class FeatureTiles { /** * When the simplify tolerance is set , simplify the points to a similar
 * curve with fewer points .
 * @ param simplifyTolerance simplify tolerance in meters
 * @ param points ordered points
 * @ return simplified points
 * @ since 2.0.0 */
protected List < Point > simplifyPoints ( double simplifyTolerance , List < Point > points ) { } }

implementation:
List < Point > simplifiedPoints = null ; if ( simplifyGeometries ) { // Reproject to web mercator if not in meters
if ( projection != null && ! projection . isUnit ( Units . METRES ) ) { ProjectionTransform toWebMercator = projection . getTransformation ( WEB_MERCATOR_PROJECTION ) ; points = toWebMercator . transform ( points ) ; } // Simplify the points
simplifiedPoints = GeometryUtils . simplifyPoints ( points , simplifyTolerance ) ; // Reproject back to the original projection
if ( projection != null && ! projection . isUnit ( Units . METRES ) ) { ProjectionTransform fromWebMercator = WEB_MERCATOR_PROJECTION . getTransformation ( projection ) ; simplifiedPoints = fromWebMercator . transform ( simplifiedPoints ) ; } } else { simplifiedPoints = points ; } return simplifiedPoints ;


signature:
public class FeatureTiles { /** * Get the feature style for the feature row and geometry type
 * @ param featureRow feature row
 * @ return feature style */
protected FeatureStyle getFeatureStyle ( FeatureRow featureRow ) { } }

implementation: FeatureStyle featureStyle = null ; if ( featureTableStyles != null ) { featureStyle = featureTableStyles . getFeatureStyle ( featureRow ) ; } return featureStyle ;


signature:
public class FeatureTiles { /** * Get the feature style for the feature row and geometry type
 * @ param featureRow feature row
 * @ param geometryType geometry type
 * @ return feature style */
protected FeatureStyle getFeatureStyle ( FeatureRow featureRow , GeometryType geometryType ) { } }

implementation: FeatureStyle featureStyle = null ; if ( featureTableStyles != null ) { featureStyle = featureTableStyles . getFeatureStyle ( featureRow , geometryType ) ; } return featureStyle ;


signature:
public class FeatureTiles { /** * Get the point paint for the feature style , or return the default paint
 * @ param featureStyle feature style
 * @ return paint */
protected Paint getPointPaint ( FeatureStyle featureStyle ) { } }

implementation: Paint paint = getFeatureStylePaint ( featureStyle , FeatureDrawType . CIRCLE ) ; if ( paint == null ) { paint = pointPaint ; } return paint ;


signature:
public class FeatureTiles { /** * Get the line paint for the feature style , or return the default paint
 * @ param featureStyle feature style
 * @ return paint */
protected Paint getLinePaint ( FeatureStyle featureStyle ) { } }

implementation: Paint paint = getFeatureStylePaint ( featureStyle , FeatureDrawType . STROKE ) ; if ( paint == null ) { paint = linePaint ; } return paint ;


signature:
public class FeatureTiles { /** * Get the polygon paint for the feature style , or return the default paint
 * @ param featureStyle feature style
 * @ return paint */
protected Paint getPolygonPaint ( FeatureStyle featureStyle ) { } }

implementation: Paint paint = getFeatureStylePaint ( featureStyle , FeatureDrawType . STROKE ) ; if ( paint == null ) { paint = polygonPaint ; } return paint ;


signature:
public class FeatureTiles { /** * Get the polygon fill paint for the feature style , or return the default paint
 * @ param featureStyle feature style
 * @ return paint */
protected Paint getPolygonFillPaint ( FeatureStyle featureStyle ) { } }

implementation: Paint paint = null ; boolean hasStyleColor = false ; if ( featureStyle != null ) { StyleRow style = featureStyle . getStyle ( ) ; if ( style != null ) { if ( style . hasFillColor ( ) ) { paint = getStylePaint ( style , FeatureDrawType . FILL ) ; } else { hasStyleColor = style . hasColor ( ) ; } } } if ( paint == null && ! hasStyleColor && fillPolygon ) { paint = polygonFillPaint ; } return paint ;


signature:
public class FeatureTiles { /** * Get the feature style paint from cache , or create and cache it
 * @ param featureStyle feature style
 * @ param drawType draw type
 * @ return feature style paint */
private Paint getFeatureStylePaint ( FeatureStyle featureStyle , FeatureDrawType drawType ) { } }

implementation: Paint paint = null ; if ( featureStyle != null ) { StyleRow style = featureStyle . getStyle ( ) ; if ( style != null && style . hasColor ( ) ) { paint = getStylePaint ( style , drawType ) ; } } return paint ;


signature:
public class FeatureTiles { /** * Get the style paint from cache , or create and cache it
 * @ param style style row
 * @ param drawType draw type
 * @ return paint */
private Paint getStylePaint ( StyleRow style , FeatureDrawType drawType ) { } }

implementation: Paint paint = featurePaintCache . getPaint ( style , drawType ) ; if ( paint == null ) { Color color = null ; Style paintStyle = null ; Float strokeWidth = null ; switch ( drawType ) { case CIRCLE : color = style . getColorOrDefault ( ) ; paintStyle = Style . FILL ; break ; case STROKE : color = style . getColorOrDefault ( ) ; paintStyle = Style . STROKE ; strokeWidth = this . density * ( float ) style . getWidthOrDefault ( ) ; break ; case FILL : color = style . getFillColor ( ) ; paintStyle = Style . FILL ; strokeWidth = this . density * ( float ) style . getWidthOrDefault ( ) ; break ; default : throw new GeoPackageException ( "Unsupported Draw Type: " + drawType ) ; } Paint stylePaint = new Paint ( ) ; stylePaint . setAntiAlias ( true ) ; stylePaint . setStyle ( paintStyle ) ; stylePaint . setColor ( color . getColorWithAlpha ( ) ) ; if ( strokeWidth != null ) { stylePaint . setStrokeWidth ( strokeWidth ) ; } synchronized ( featurePaintCache ) { paint = featurePaintCache . getPaint ( style , drawType ) ; if ( paint == null ) { featurePaintCache . setPaint ( style , drawType , stylePaint ) ; paint = stylePaint ; } } } return paint ;


signature:
public class FeatureTiles { /** * Check if the bitmap was drawn upon ( non null and not transparent ) . Return the same bitmap if drawn , else recycle non null bitmaps and return null
 * @ param bitmap bitmap
 * @ return drawn bitmap or null */
protected Bitmap checkIfDrawn ( Bitmap bitmap ) { } }

implementation: if ( isTransparent ( bitmap ) ) { bitmap . recycle ( ) ; bitmap = null ; } return bitmap ;


signature:
public class FeaturePaintCache { /** * Get the paint for the style row and draw type
 * @ param styleRow style row
 * @ param type feature draw type
 * @ return paint */
public Paint getPaint ( StyleRow styleRow , FeatureDrawType type ) { } }

implementation: return getPaint ( styleRow . getId ( ) , type ) ;


signature:
public class FeaturePaintCache { /** * Get the paint for the style row id and draw type
 * @ param styleId style row id
 * @ param type feature draw type
 * @ return paint */
public Paint getPaint ( long styleId , FeatureDrawType type ) { } }

implementation: Paint paint = null ; FeaturePaint featurePaint = getFeaturePaint ( styleId ) ; if ( featurePaint != null ) { paint = featurePaint . getPaint ( type ) ; } return paint ;


signature:
public class FeaturePaintCache { /** * Set the paint for the style id and draw type
 * @ param styleRow style row
 * @ param type feature draw type
 * @ param paint paint */
public void setPaint ( StyleRow styleRow , FeatureDrawType type , Paint paint ) { } }

implementation: setPaint ( styleRow . getId ( ) , type , paint ) ;


signature:
public class FeaturePaintCache { /** * Set the paint for the style id and draw type
 * @ param styleId style row id
 * @ param type feature draw type
 * @ param paint paint */
public void setPaint ( long styleId , FeatureDrawType type , Paint paint ) { } }

implementation: FeaturePaint featurePaint = getFeaturePaint ( styleId ) ; if ( featurePaint == null ) { featurePaint = new FeaturePaint ( ) ; paintCache . put ( styleId , featurePaint ) ; } featurePaint . setPaint ( type , paint ) ;


signature:
public class IconCache { /** * Cache the icon bitmap for the icon row
 * @ param iconRow icon row
 * @ param bitmap icon bitmap
 * @ return previous cached icon bitmap or null */
public Bitmap put ( IconRow iconRow , Bitmap bitmap ) { } }

implementation: return put ( iconRow . getId ( ) , bitmap ) ;