Skip to content

Commit

Permalink
abstract user dao by table, set user custom dao contents
Browse files Browse the repository at this point in the history
  • Loading branch information
bosborn committed Feb 16, 2024
1 parent c06fd07 commit 7c246c2
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Adheres to [Semantic Versioning](http://semver.org/).
* DAO column range support (including geometry envelopes & bounding boxes) to build where clauses & args for queries
* User Column integrated Data Columns Schema support
* ogc-api-features-json-ios version 4.2.5
* Get abstract User DAO by table name
* Set User Custom DAO contents
* Get Tile Overlays and Bounded Overlays by tile table, feature table, or user DAO

## [8.0.4](https://github.com/ngageoint/geopackage-ios/releases/tag/8.0.4) (11-15-2023)

Expand Down
8 changes: 8 additions & 0 deletions geopackage-ios/GPKGGeoPackage.h
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,14 @@
*/
-(GPKGUserCustomDao *) userCustomDaoWithTable: (GPKGUserCustomTable *) table;

/**
* Get a User DAO from a table
*
* @param tableName table name
* @return user dao
*/
-(GPKGUserDao *) userDaoWithTableName: (NSString *) tableName;

/**
* Execute the sql on the GeoPackage database
*
Expand Down
36 changes: 36 additions & 0 deletions geopackage-ios/GPKGGeoPackage.m
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,45 @@ -(GPKGUserCustomDao *) userCustomDaoWithTableName: (NSString *) tableName{
}

-(GPKGUserCustomDao *) userCustomDaoWithTable: (GPKGUserCustomTable *) table{

if(table.contents == nil){
GPKGContentsDao *dao = [self contentsDao];
GPKGContents *contents = (GPKGContents *)[dao queryForIdObject:[table tableName]];
[table setContents:contents];
}
return [[GPKGUserCustomDao alloc] initWithDatabase:self.database andTable:table];
}

-(GPKGUserDao *) userDaoWithTableName: (NSString *) tableName{

GPKGUserDao *dao = nil;

if(![self isContentsTable:tableName]){
[NSException raise:@"No Contents" format:@"No contents for user table: %@", tableName];
}
enum GPKGContentsDataType dataType = [self dataTypeOfTable:tableName];
if(dataType != -1){
switch(dataType){
case GPKG_CDT_ATTRIBUTES:
dao = [self attributesDaoWithTableName:tableName];
break;
case GPKG_CDT_FEATURES:
dao = [self featureDaoWithTableName:tableName];
break;
case GPKG_CDT_TILES:
dao = [self tileDaoWithTableName:tableName];
break;
default:
[NSException raise:@"Unsupported" format:@"Unsupported data type: %@, table: %@", [GPKGContentsDataTypes name:dataType], tableName];
break;
}
}else{
dao = [self userCustomDaoWithTableName:tableName];
}

return dao;
}

-(void) execSQL: (NSString *) sql{
[self.database exec:sql];
}
Expand Down
8 changes: 8 additions & 0 deletions geopackage-ios/tiles/overlay/GPKGGeoPackageOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "GPKGTileDao.h"
#import "GPKGBoundedOverlay.h"
#import "GPKGTileScaling.h"
#import "GPKGTileRetriever.h"

/**
* GeoPackage Tile Overlay
Expand Down Expand Up @@ -76,4 +77,11 @@
*/
-(instancetype) initWithTileDao: (GPKGTileDao *) tileDao andWidth: (int) width andHeight: (int) height andScaling: (GPKGTileScaling *) scaling;

/**
* Get the tile retriever
*
* @return retriever
*/
-(NSObject<GPKGTileRetriever> *) retriever;

@end
10 changes: 7 additions & 3 deletions geopackage-ios/tiles/overlay/GPKGGeoPackageOverlay.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ -(instancetype) initWithTileDao: (GPKGTileDao *) tileDao andWidth: (int) width a
}

-(void) initHelperWithRetriever: (GPKGGeoPackageTileRetriever *) retriever{
self.retriever = retriever;
_retriever = retriever;
SFPGeometryTransform *transform = [SFPGeometryTransform transformFromEpsg:PROJ_EPSG_WEB_MERCATOR andToEpsg:PROJ_EPSG_WORLD_GEODETIC_SYSTEM];
GPKGBoundingBox *boundingBox = [[retriever webMercatorBoundingBox] transform:transform];
[transform destroy];
Expand All @@ -59,15 +59,19 @@ -(void) initHelperWithRetriever: (GPKGGeoPackageTileRetriever *) retriever{
//[self setMaximumZ:tileDao.maxZoom];
}

-(NSObject<GPKGTileRetriever> *) retriever{
return _retriever;
}

-(BOOL) hasTileToRetrieveWithX: (NSInteger) x andY: (NSInteger) y andZoom: (NSInteger) zoom{
return [self.retriever hasTileWithX:x andY:y andZoom:zoom];
return [_retriever hasTileWithX:x andY:y andZoom:zoom];
}

-(NSData *) retrieveTileWithX: (NSInteger) x andY: (NSInteger) y andZoom: (NSInteger) zoom{

NSData *tileData = nil;

GPKGGeoPackageTile *geoPackageTile = [self.retriever tileWithX:x andY:y andZoom:zoom];
GPKGGeoPackageTile *geoPackageTile = [_retriever tileWithX:x andY:y andZoom:zoom];
if(geoPackageTile != nil){
tileData = geoPackageTile.data;
}
Expand Down
40 changes: 40 additions & 0 deletions geopackage-ios/tiles/overlay/GPKGOverlayFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,44 @@
*/
+(GPKGBoundedOverlay *) linkedFeatureOverlayWithOverlay: (GPKGFeatureOverlay *) featureOverlay andGeoPackage: (GPKGGeoPackage *) geoPackage;

/**
* Get a Tile Overlay for the tile or feature table
*
* @param geoPackage GeoPackage
* @param table tile or feature table
*
* @return tile overlay
*/
+(MKTileOverlay *) tileOverlayWithGeoPackage: (GPKGGeoPackage *) geoPackage andTableName: (NSString *) table;

/**
* Get a Bounded Overlay Tile Provider for the tile or feature table
*
* @param geoPackage GeoPackage
* @param table tile or feature table
*
* @return tile overlay
*/
+(GPKGBoundedOverlay *) boundedOverlayWithGeoPackage: (GPKGGeoPackage *) geoPackage andTableName: (NSString *) table;

/**
* Get a Tile Overlay for the tile or feature DAO
*
* @param geoPackage GeoPackage
* @param userDao user DAO
*
* @return tile overlay
*/
+(MKTileOverlay *) tileOverlayWithGeoPackage: (GPKGGeoPackage *) geoPackage andUserDao: (GPKGUserDao *) userDao;

/**
* Get a Bounded Overlay Tile Provider for the tile or feature DAO
*
* @param geoPackage GeoPackage
* @param userDao user DAO
*
* @return tile overlay
*/
+(GPKGBoundedOverlay *) boundedOverlayWithGeoPackage: (GPKGGeoPackage *) geoPackage andUserDao: (GPKGUserDao *) userDao;

@end
42 changes: 42 additions & 0 deletions geopackage-ios/tiles/overlay/GPKGOverlayFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,46 @@ +(GPKGBoundedOverlay *) linkedFeatureOverlayWithOverlay: (GPKGFeatureOverlay *)
return overlay;
}

+(MKTileOverlay *) tileOverlayWithGeoPackage: (GPKGGeoPackage *) geoPackage andTableName: (NSString *) table{
return [self boundedOverlayWithGeoPackage:geoPackage andTableName:table];
}

+(GPKGBoundedOverlay *) boundedOverlayWithGeoPackage: (GPKGGeoPackage *) geoPackage andTableName: (NSString *) table{

GPKGBoundedOverlay *overlay = nil;

if([geoPackage isTileTable:table]){
GPKGTileDao *tileDao = [geoPackage tileDaoWithTableName:table];
overlay = [self boundedOverlay:tileDao];
}else if([geoPackage isFeatureTable:table]){
GPKGFeatureDao *featureDao = [geoPackage featureDaoWithTableName:table];
GPKGFeatureTiles *featureTiles = [[GPKGFeatureTiles alloc] initWithGeoPackage:geoPackage andFeatureDao:featureDao];
overlay = [[GPKGFeatureOverlay alloc] initWithFeatureTiles:featureTiles];
}else{
[NSException raise:@"Table Type" format:@"Table is not a tile or feature type: %@", table];
}

return overlay;
}

+(MKTileOverlay *) tileOverlayWithGeoPackage: (GPKGGeoPackage *) geoPackage andUserDao: (GPKGUserDao *) userDao{
return [self boundedOverlayWithGeoPackage:geoPackage andUserDao:userDao];
}

+(GPKGBoundedOverlay *) boundedOverlayWithGeoPackage: (GPKGGeoPackage *) geoPackage andUserDao: (GPKGUserDao *) userDao{

GPKGBoundedOverlay *overlay = nil;

if([userDao isKindOfClass:[GPKGTileDao class]]){
overlay = [self boundedOverlay:(GPKGTileDao *) userDao];
}else if([userDao isKindOfClass:[GPKGFeatureDao class]]){
GPKGFeatureTiles *featureTiles = [[GPKGFeatureTiles alloc] initWithGeoPackage:geoPackage andFeatureDao:(GPKGFeatureDao *) userDao];
overlay = [[GPKGFeatureOverlay alloc] initWithFeatureTiles:featureTiles];
}else{
[NSException raise:@"DAO Type" format:@"User DAO is not a tile or feature type: %@", userDao.tableName];
}

return overlay;
}

@end
8 changes: 8 additions & 0 deletions geopackage-ios/tiles/overlay/GPKGXYZOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "GPKGTileDao.h"
#import "GPKGBoundedOverlay.h"
#import "GPKGTileRetriever.h"

/**
* XYZ Overlay, assumes XYZ tiles
Expand All @@ -23,4 +24,11 @@
*/
-(instancetype) initWithTileDao: (GPKGTileDao *) tileDao;

/**
* Get the tile retriever
*
* @return retriever
*/
-(NSObject<GPKGTileRetriever> *) retriever;

@end
10 changes: 7 additions & 3 deletions geopackage-ios/tiles/overlay/GPKGXYZOverlay.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ @implementation GPKGXYZOverlay
-(instancetype) initWithTileDao: (GPKGTileDao *) tileDao{
self = [super init];
if(self != nil){
self.retriever = [[GPKGXYZTileRetriever alloc] initWithTileDao:tileDao];
_retriever = [[GPKGXYZTileRetriever alloc] initWithTileDao:tileDao];

[self setMinimumZ:tileDao.minZoom];
[self setMaximumZ:tileDao.maxZoom];
Expand All @@ -44,15 +44,19 @@ -(instancetype) initWithTileDao: (GPKGTileDao *) tileDao{
return self;
}

-(NSObject<GPKGTileRetriever> *) retriever{
return _retriever;
}

-(BOOL) hasTileToRetrieveWithX: (NSInteger) x andY: (NSInteger) y andZoom: (NSInteger) zoom{
return [self.retriever hasTileWithX:x andY:y andZoom:zoom];
return [_retriever hasTileWithX:x andY:y andZoom:zoom];
}

-(NSData *) retrieveTileWithX: (NSInteger) x andY: (NSInteger) y andZoom: (NSInteger) zoom{

NSData *tileData = nil;

GPKGGeoPackageTile *geoPackageTile = [self.retriever tileWithX:x andY:y andZoom:zoom];
GPKGGeoPackageTile *geoPackageTile = [_retriever tileWithX:x andY:y andZoom:zoom];
if(geoPackageTile != nil){
tileData = geoPackageTile.data;
}
Expand Down
6 changes: 6 additions & 0 deletions geopackage-iosTests/GPKGCreateTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ - (void) testTableTypes {

}

- (void) testUserDao {

[GPKGGeoPackageTestUtils testUserDao:self.geoPackage];

}

@end
2 changes: 2 additions & 0 deletions geopackage-iosTests/GPKGGeoPackageTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@

+(void) testTableTypes: (GPKGGeoPackage *) geoPackage;

+(void) testUserDao: (GPKGGeoPackage *) geoPackage;

@end
38 changes: 38 additions & 0 deletions geopackage-iosTests/GPKGGeoPackageTestUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "GPKGFeatureIndexManager.h"
#import "GPKGGeoPackageFactory.h"
#import "GPKGCoverageData.h"
#import "GPKGTableInfo.h"

@implementation GPKGGeoPackageTestUtils

Expand Down Expand Up @@ -520,4 +521,41 @@ +(void) testTableTypes: (GPKGGeoPackage *) geoPackage{

}

+(void) testUserDao: (GPKGGeoPackage *) geoPackage{

NSArray<NSString *> *tables = [geoPackage tables];
for(NSString *table in tables){
GPKGUserDao *dao = [geoPackage userDaoWithTableName:table];
[GPKGTestUtils assertNotNil:dao];
enum GPKGContentsDataType dataType = [geoPackage dataTypeOfTable:table];
GPKGTableInfo *tableInfo = [GPKGTableInfo infoWithConnection:geoPackage.database andTable:table];
[GPKGTestUtils assertEqualIntWithValue:[tableInfo numColumns] andValue2:[dao columnCount]];
GPKGContents *contents = [dao contents];
[GPKGTestUtils assertNotNil:contents];
if(dataType == -1){
[GPKGTestUtils assertTrue:[dao isKindOfClass:[GPKGUserCustomDao class]]];
[GPKGTestUtils assertNotNil:contents.dataType];
}else{
switch(dataType){
case GPKG_CDT_ATTRIBUTES:
[GPKGTestUtils assertTrue:[dao isKindOfClass:[GPKGAttributesDao class]]];
[GPKGTestUtils assertEqualIntWithValue:GPKG_CDT_ATTRIBUTES andValue2:[contents contentsDataType]];
break;
case GPKG_CDT_FEATURES:
[GPKGTestUtils assertTrue:[dao isKindOfClass:[GPKGFeatureDao class]]];
[GPKGTestUtils assertEqualIntWithValue:GPKG_CDT_FEATURES andValue2:[contents contentsDataType]];
break;
case GPKG_CDT_TILES:
[GPKGTestUtils assertTrue:[dao isKindOfClass:[GPKGTileDao class]]];
[GPKGTestUtils assertEqualIntWithValue:GPKG_CDT_TILES andValue2:[contents contentsDataType]];
break;
default:
[GPKGTestUtils fail:[NSString stringWithFormat:@"Unsupported data type: %@", [GPKGContentsDataTypes name:dataType]]];
break;
}
}
}

}

@end
6 changes: 6 additions & 0 deletions geopackage-iosTests/GPKGImportTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ - (void) testTableTypes {

}

- (void) testUserDao {

[GPKGGeoPackageTestUtils testUserDao:self.geoPackage];

}

@end

0 comments on commit 7c246c2

Please sign in to comment.