Opened 7 years ago

Closed 7 years ago

#5699 closed defect (wontfix)

Docs: not clear that tutorials on default pages are GDAL 2.0 only

Reported by: nadams Owned by: warmerdam
Priority: normal Milestone:
Component: Docs Version: 1.11.1
Severity: normal Keywords:
Cc:

Description (last modified by Kyle Shannon)

After building from source on Windows 7 with MS Visual Studio 2008, no drivers are found by GDAL.

In the following application, all of the cerr statements get hit:

#include <iostream>
#include "gdal.h"
#include "gdal_priv.h"
#include "ogr_api.h"

int main(int argc, char *argv[])
{
    GDALAllRegister();

    GDALDriverManager dm;
    dm.AutoLoadDrivers();
    int count = dm.GetDriverCount();
    if( count == 0 )
        std::cerr << "Exactly " << count << " drivers found by GDALDriverManager.\n" << std::endl;

    GDALDriver *poDriver = (GDALDriver*) GDALGetDriverByName("ESRI Shapefile");
    if( poDriver == NULL )
        std::cerr << "ESRI Shapefile driver not available.\n" << std::endl;

    GDALDataset* poDS = (GDALDataset*) GDALOpen( "Political_VotingPrecincts.shp", GA_ReadOnly );
    if( poDS == NULL )
        std::cerr << "Open failed.\n" << std::endl;

    return 0;
}

Attachments (1)

nmake.opt (23.4 KB) - added by nadams 7 years ago.

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by nadams

Attachment: nmake.opt added

comment:1 Changed 7 years ago by Kyle Shannon

Description: modified (diff)

nadams,

You don't need to instantiate a driver manager. Also you are using the 2.0 unified driver model for GDAL and OGR, but you stated verson 1.11.1 in the ticket.

See the docs here for 1.x:

http://gdal.org/1.11/index.html

If you are using the trunk (2.0dev), then this should work:

#include "gdal.h"
#include "gdal_priv.h"

int main(int argc, char *argv[])
{
    GDALAllRegister();

    GDALDriver *poDriver = (GDALDriver*) GDALGetDriverByName("ESRI Shapefile");
    if( poDriver == NULL )
        std::cerr << "ESRI Shapefile driver not available.\n" << std::endl;

    GDALDataset* poDS = (GDALDataset*) GDALOpen( "Political_VotingPrecincts.shp", GA_ReadOnly );
    if( poDS == NULL )
        std::cerr << "Open failed.\n" << std::endl;

    return 0;
}

If you are using 1.x, you need to use the OGR API for vector datasources (cut from the ogr tutorial):

#include "ogr_api.h"
int main()
{
    OGRRegisterAll();
    OGRDataSourceH hDS;

    hDS = OGROpen( "point.shp", FALSE, NULL );
    if( hDS == NULL )
    {
        printf( "Open failed.\n" );
        exit( 1 );
    }
    /* ... */
    return 0;
}

comment:2 Changed 7 years ago by Even Rouault

Resolution: invalid
Status: newclosed
Version: 1.11.1unspecified

Kyle is right.

To be more precise, actually with GDAL 2.0, you would need to use GDALOpenEx() and specify GDAL_OF_VECTOR as open flag (or use OGROpen() )

comment:3 Changed 7 years ago by nadams

Version: unspecified1.11.1

Thank you for the feedback.

But to clarify, I am indeed using version 1.11.1.

I downloaded it via the "Building GDAL from Source" page linked from the homepage: http://trac.osgeo.org/gdal/wiki/BuildHints

That page links to here for the actual download: http://trac.osgeo.org/gdal/wiki/DownloadSource

And I initially tried used the tutorial that is also linked from the homepage: http://www.gdal.org/ogr_apitut.html

That tutorial differentiates between "C++" and "C" examples, not particular versions of GDAL.

But the GDALOpenEx() method did not exist in 1.11.1, so I switched to the GDALOpen() method.

Failing that I went looking for a way to have the API tell me things like how many drivers were being loaded and whether the shapefile in particular was being loaded. That is what led to the GDALDriverManager and GDALGetDriverByName() code snippets.

Perhaps the tutorials linked from the homepage could use some clarifying text with regard to the particular versions of GDAL at play, especially since the homepage leads to version 1.11.1 for developers wanting to build from source.

comment:4 Changed 7 years ago by nadams

Component: defaultDocs
Resolution: invalid
Status: closedreopened

comment:5 Changed 7 years ago by Even Rouault

The home page at gdal.org mentions "Traditionnaly GDAL used to design the raster part of the library, and OGR the vector part for Simple Features. Starting with GDAL 2.0, both sides have been more tightly integrated. You can still refer to the documentation of GDAL 1.X if needed." and that points to http://gdal.org/1.11/index.html

comment:6 Changed 7 years ago by Even Rouault

Summary: No drivers foundDocs: not clear that tutorials on default pages are GDAL 2.0 only

comment:7 Changed 7 years ago by Even Rouault

Resolution: wontfix
Status: reopenedclosed

I don't think any further action is needed. Closing

Note: See TracTickets for help on using tickets.