6

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

5

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);
}
2

If you look at this and this, they say that both GDALOpenEx() and GDAL_OF_VECTORS were (will be?) introduced in GDAL 2.0.

GDAL 2.0 seems to be still under development. In case that you are able to compile it, you can find the source code here.

In older versions you would use OGROpen to read a Shapefile.

  • Thank you very much! I didn't find any information if GDAL 2.0 is stable, so I stick with 1.11. Although it is quite confusing, that the main website refers to GDAL 2.0. Did I miss something? – Peter A. Kolski Feb 17 '15 at 16:33
  • I agree, it's confusing. Don't know why they don't point to older versions easily, I wasn't able to find the link you put in your answer. – Germán Carrillo Feb 17 '15 at 16:38
  • There is a reference to the 1.11.x API on the home page. The main page is a product of the development version. See: gdal.org/1.11/index.html for the 1.11 API – user10353 Feb 18 '15 at 16:52
  • @kyle You're right, I couldn't see it yesterday. Thanks! – Germán Carrillo Feb 18 '15 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.