`
刘燕宝宝鱼
  • 浏览: 25918 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

iOS 读取arcgis bundle,bundlx文件算法。

 
阅读更多

       前段时间做了arcgis bundle压缩地图数据的读取,方法如下,使用object C 

+ (NSData *)getCompressedTile:(NSString *)filepath
                                   x:(NSString *)x
                                   y:(NSString *)y
                                   z:(NSString *)z {
    filepath = [NSString stringWithFormat:@"%@%@", filepath, @"Layers/_alllayers"];
    NSString *bundlepath=filepath;
    bundlepath=[filepath stringByAppendingString:bundlepath];
    NSString *lpadding = @"00";
    NSString *lz=[NSString stringWithFormat:@"%@%@", lpadding, z];
    NSString *l = [NSString stringWithFormat:@"L%@",[lz substringFromIndex:[lz length] - 2]];
    int row = [y intValue];
    int col = [x intValue];
    int rGroup = 128 * (row / 128);
    NSString *r = [[NSString alloc] initWithFormat:@"%1x",rGroup];
    while ([r hasPrefix:@"0"]) {
        r = [r substringFromIndex:1];
    }
    int rLength = [r length];
    if (rLength < 4) {
        r = [NSString stringWithFormat:@"0000%@", r];
        
        r = [r substringFromIndex:[r length] - 4];
    }
    r = [NSString stringWithFormat:@"R%@", r];
    int cGroup = 128 * (col / 128);
    NSString *c =  [[NSString alloc] initWithFormat:@"%1x",cGroup];
    while ([c hasPrefix:@"0"]) {
        c =[c substringFromIndex:1];
    }
    int cLength = [c length];
    if (cLength < 4) {
        c = [NSString stringWithFormat:@"0000%@", c];
        c = [c substringFromIndex:[c length] - 4];
    }
    c = [NSString stringWithFormat:@"C%@", c];//@"R0a00" @"C3480"
    
    NSString *bundleBase = [NSString stringWithFormat:@"%@/%@/%@%@", filepath , l,r ,c];
    NSString *bundlxFileName = [NSString stringWithFormat:@"%@.bundlx", bundleBase];
    NSString *bundleFileName = [NSString stringWithFormat:@"%@.bundle", bundleBase];
    NSFileManager *filemanager=[NSFileManager defaultManager];
    //NSLog(@"bundle%@,bundlx%@,bundlx %@,%@,%@,%@",bundleFileName,bundlxFileName,c,l,r,bundleBase);
//    NSLog(@"bundle------:%@",bundleFileName);
//    NSLog(@"bundlx------:%@",bundlxFileName);
    if (![filemanager fileExistsAtPath:bundleFileName]||![filemanager fileExistsAtPath:bundlxFileName]) {
//        NSLog(@"地图bundle文件或bundlx文件不存在!");
        return nil;
    }
    int index = 128 * (col - cGroup) + (row - rGroup);
    
    NSFileHandle* lxfileHandle=[NSFileHandle fileHandleForReadingAtPath:bundlxFileName];
    [lxfileHandle seekToFileOffset: 16 + 5 * index];
    Byte bufferbundlx[5];
    NSData *data=[lxfileHandle readDataOfLength:5];
    [data getBytes:bufferbundlx];
    
    long offset = (long ) (bufferbundlx[0] & 0xff)
    + (long) (bufferbundlx[1] & 0xff) * 256
    + (long) (bufferbundlx[2] & 0xff) * 65536
    + (long) (bufferbundlx[3] & 0xff) * 16777216
    + (long) (bufferbundlx[4] & 0xff) * 4294967296LL;   
    
   // NSLog(@"%ld",offset);    
    NSFileHandle *lefileHandle=[NSFileHandle fileHandleForReadingAtPath:bundleFileName];
    [lefileHandle seekToFileOffset:offset];
    Byte bufferbundle[4];
    NSData *bundleIndex=[lefileHandle readDataOfLength:4];
    [bundleIndex getBytes:bufferbundle];    
    int length = (int) (bufferbundle[0]& 0xff)
    + (int) (bufferbundle[1] &  0xff) * 256
    + (int) (bufferbundle[2] &  0xff) * 65536
    + (int) (bufferbundle[3] &  0xff) * 16777216;
   // NSLog(@"dddddddddd%d",length);    
    NSData *result=[lefileHandle readDataOfLength:length];
    //关闭文件流
    [lxfileHandle closeFile];
    [lefileHandle closeFile];
    
    return result;
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics