Qt gdal错误:'Open'不是'OGRSFDriverRegistrar'的成员

问题描述 投票:0回答:2

我正在使用gdal库开发一个Qt项目。

Qt5.9.1。 Ubuntu 16.10 LTS。

我收到一个错误,我不知道出了什么问题。

#include <QCoreApplication>
#include <QFile>
#include "ogrsf_frmts.h"

int main(int argc, char *argv[])
{
    OGRRegisterAll();
    OGRDataSource *source;

    source = OGRSFDriverRegistrar::Open( <path to s57 file>, FALSE );
    if( source == NULL )
    {
        printf( "Open failed.\n" );
        exit( 1 );
    }
}

我收到以下错误:

main.cpp:11: error: 
'Open' is not a member of 'OGRSFDriverRegistrar';

source = OGRSFDriverRegistrar::Open( <path to s57 chart file>, FALSE );

任何人都可以帮我解决错误吗?

qt gdal
2个回答
1
投票

类OGRSFDriverRegistrar被标记为Legacy类,因此不推荐使用。

docs建议使用引用GDALDriverManager()

在新代码中使用GDALDriverManager!可以在以后的版本中删除此类。

您使用的是哪个版本的GDAL?可能是OGRSFDriverRegistrar已被删除。

无论如何删除,我建议您尝试使用GDALDriverManager更新代码。

编辑:添加了示例。

#include "gdal_priv.h"
#include "cpl_conv.h" // for CPLMalloc()
int main()
{
    GDALDataset  *poDataset;
    GDALAllRegister();
    poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );
    if( poDataset == NULL )
    {
        ...;
    }
}

取自GDAL API tutorial


0
投票

找到了OGR Tutorial。这里用例子解释这些功能。 @Petar给出了初步帮助。在进一步探索网站时,我找到了确切的方法。

GDALDataset *dataSet;
GDALAllRegister();
dataSet = (GDALDataset*)GDALOpenEx("ENCFILE.000",GDAL_OF_VECTOR,NULL,NULL,NULL);
if(dataSet == NULL)
{
    printf( "Open failed.\n" );
    exit( 1 );
}
else
{
    printf( "SUCCESS.\n" );
}
© www.soinside.com 2019 - 2024. All rights reserved.