简体   繁体   English

如何在C ++中使用gdal打开postGIS表?

[英]How do I open postGIS table with gdal in C++?

I'm completely new in gdal with C++, and want to open postgreSQL table(with geometry) with gdal API. 我对使用C ++的gdal完全陌生,并希望使用gdal API打开postgreSQL表(带有几何图形)。 I cannot find how to do that in tutorial of gdal.org. 我在gdal.org的教程中找不到该怎么做。 Below is what i was trying now. 以下是我现在正在尝试的方法。 How can I do open table with GDALOpenEx for postgreSQL? 如何使用GDALOpenEx为postgreSQL打开表?

GDALAllRegister();

GDALDataset* poDS;


std::string source = "PG:host=111.111.111.111 port=5432 dbname=db user=user password=password";
poDS = (GDALDataset*) GDALOpenEx(source.c_str(), GDAL_OF_VERBOSE_ERROR | GDAL_OF_VECTOR, NULL, NULL, NULL);

ERROR 4 : PG:host=host port=5432 dbname=db user=user password=XXXX No such file or directory 错误4 :PG:主机=主机端口= 5432 dbname = db用户=用户密码= XXXX没有这样的文件或目录

I was also puzzled with this question for serveral hours. 数小时的时间我也对此问题感到困惑。 I have used the same kind of connection string. 我使用了相同类型的连接字符串。 This is enough to connect the postgresql.If this is not useful,Please Check something else. 这足以连接postgresql。如果这没有用,请检查其他事项。 Enable the postgresql when you compile the gdal(in the nmake.opt file open PostGIS Libraries colume,set you libpq.lib file and include directory). 编译gdal时启用postgresql(在nmake.opt文件中,打开PostGIS库名称,设置libpq.lib文件并包含目录)。 code: 码:

    GDALAllRegister();
    const char* path ="PG:dbname=db host=localhost port=5432 user=postgres 
    password=password";
    GDALDataset *pDos =nullptr;
    pDos = (GDALDataset *)GDALOpenEx(path,GDAL_OF_VECTOR,nullptr,nullptr,nullptr);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM