[GIS] GDAL in C++: Reading a ShapeFile

cgdalogrosxshapefile

I am trying to use the GDAL Lib to read a ShapeFile (.shp). I followed the instructions of http://www.gdal.org/ogr_apitut.html – But it doesn't work!

#include <gdal_priv.h>
#include <ogrsf_frmts.h>

int main()
{
GDALAllRegister();

GDALDataset       *poDS;   
poDS = (GDALDataset*) GDALOpenEx( "point.shp", GDAL_OF_VECTOR, NULL, NULL, NULL );
}

The error message is that "GDALOpenEx()" is a undeclared identifier. Also "GDAL_OF_VECTOR" is not declared.

How do I access the GDALOpenEx() method?
Do I have to load some drivers? (Which I thought GDALAllRegister() would do)

I am using xCode 6 on Mac OS 10.10. GDAL 1.11 from http://www.kyngchaos.com/software:frameworks

Best Answer

That solved my problem.

Further information and a tutorial can be found here http://gdal.org/1.11/ogr/ogr_apitut.html

A C++ version for GDAL 1.11:

#include <GDAL/ogrsf_frmts.h>
int main()
{
OGRRegisterAll();
OGRDataSource   *poDS;
poDS = OGRSFDriverRegistrar::Open( "data.shp", FALSE);
}