gpt4 book ai didi

ios - 使用 iOS 和 GDAL 的地理引用 PDF

转载 作者:行者123 更新时间:2023-11-29 12:26:01 35 4
gpt4 key购买 nike

我已经为 iOS 编译了 GDAL 1.11.0。我可以列出所有驱动程序,但如果我打开一个已知的地理引用 PDF,我会收到错误 4 ... 未被识别为受支持的文件格式。我正在尝试使用 geoPDF 文件开发 map 应用程序。这是我的代码;

-(void)gdalTests
{
NSLog(@"GDAL Testing");

GDALAllRegister();

int a = GDALGetDriverCount();

for (int b=1; b<a; b++) {

NSLog(@"GDAL Driver (%d) %s",b,GDALGetDriverLongName(GDALGetDriver(b)));
if (b==95) {
GDALDriverH drv = GDALGetDriver(b);
GDALRegisterDriver(drv);
NSLog(@"PDF DRIVER REGISTERED");
}
}

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"9030-4N KURRAJONG" ofType:@"pdf"];
GDALDatasetH dataset = GDALOpen ([filePath cStringUsingEncoding:[NSString defaultCStringEncoding]], GA_ReadOnly);

}

这是错误的输出部分。

2015-03-17 16:52:05.800 pdfTest[46322:4110504] GDAL Driver (94) HF2/HFZ heightfield raster
2015-03-17 16:52:05.800 pdfTest[46322:4110504] GDAL Driver (95) Geospatial PDF
2015-03-17 16:52:05.800 pdfTest[46322:4110504] PDF DRIVER REGISTERED
2015-03-17 16:52:05.800 pdfTest[46322:4110504] GDAL Driver (96) OziExplorer Image File
2015-03-17 16:52:05.800 pdfTest[46322:4110504] GDAL Driver (97) USGS LULC Composite Theme Grid
2015-03-17 16:52:05.801 pdfTest[46322:4110504] GDAL Driver (98) Arc/Info Export E00 GRID
2015-03-17 16:52:05.801 pdfTest[46322:4110504] GDAL Driver (99) ZMap Plus Grid
2015-03-17 16:52:05.801 pdfTest[46322:4110504] GDAL Driver (100) NOAA NGS Geoid Height Grids
2015-03-17 16:52:05.801 pdfTest[46322:4110504] GDAL Driver (101) MBTiles
2015-03-17 16:52:05.801 pdfTest[46322:4110504] GDAL Driver (102) IRIS data (.PPI, .CAPPi etc)
ERROR 4: `/Users/michealcumming/Library/Developer/CoreSimulator/Devices/83827FA6-0626-4A6F-8A43-516AD495430B/data/Containers/Bundle/Application/4249E572-0813-4C79-87BF-B1406E139552/pdfTest.app/9030-4N KURRAJONG.pdf' not recognised as a supported file format.

最佳答案

我使用 https://github.com/yllan/YLPDFKit 解决了这个问题下面是用于访问文档数据的代码。希望对您有所帮助。

NSString *documentName = @"9030-4N KURRAJONG";
NSString *filePath = [[NSBundle mainBundle]pathForResource:documentName ofType:@"pdf"];
NSURL *documentUrl = [NSURL fileURLWithPath:filePath];

CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef)documentUrl);

CGPDFStringRef string;
CGPDFDictionaryRef infoDict;

infoDict = CGPDFDocumentGetInfo(document);
NSDictionary *d = YLGetDictionaryFromCGPDFDictionary(infoDict);
NSLog(@"DOCUMENT INFO %@",d);

CGPDFPageRef page = CGPDFDocumentGetPage(document, 1);
NSLog(@"#rekt: %@",NSStringFromCGRect(CGPDFPageGetBoxRect(page, kCGPDFMediaBox)));

CGPDFDictionaryRef firstPage = CGPDFPageGetDictionary(page);

d = YLGetDictionaryFromCGPDFDictionary(firstPage);

NSArray *viewPortArray = [d objectForKey:@"VP"];
for (NSDictionary *d in viewPortArray) {

NSString *name = [d objectForKey:@"Name"];
NSLog(@"---- %@",name);
NSLog(@"%@",d);
}

for (int x = 0; x<5; x++) {

CGRect box = CGPDFPageGetBoxRect(page, x);
NSLog(@"PDF BOX %d = %0.4f %0.4f %0.4f %0.4f",x,box.origin.x,box.origin.y,box.size.width,box.size.height);
}

关于ios - 使用 iOS 和 GDAL 的地理引用 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29092538/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com