2

I'm using a WFS that is openly available as a demo from the MapServer web site.

http://demo.mapserver.org/cgi-bin/wfs?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetCapabilities

And now I want to make a client application that can consume this service in C++ (QT) using the GDAL libraries.

I have compiled GDAL with Xerces and curl as the docs say but apart from that they are not very clear about how to use it for a WFS, I'm sure the functionality is there because it says it supports it but I can't find any WFS specific documentation, so far I have just tried to open a connection and get this error:

GDALAllRegister();
const char *pszFilename = NULL;
pszFilename = "http://demo.mapserver.org/cgi-bin/wfs?";
m_dataset = (GDALDataset*) GDALOpen(pszFilename, GA_ReadOnly);

if( m_dataset == NULL )
{
    std::cout << "Dataset is empty" << std::endl;
    exit( 1 );
}

Error:

ERROR 4: `/vsimem/http_1/file.dat' not recognised as a supported file format.

Dataset is empty
ERROR 4: Failed to create temporary file:/tmp/file.dat

I have also tried instead of the URL, an XML document that contains the URL like the docs say this should work.

<OGRWFSDataSource>
    <URL>http://path/to/WFS/service[?OPTIONAL_PARAMETER1=VALUE[&amp;OPTIONNAL_PARAMETER2=VALUE]]</URL>
</OGRWFSDataSource> 

But this just says the file isn't a compatible type, any help would be appreciated here.

1 Answer 1

4

GDAL 1.x

GDAL versions < 2.0 have separate raster (gdal) and vector (ogr) libraries. Don't try to open the WFS vector data with GDAL, use OGR instead. GDAL supports raster data, OGR supports vector.

GDAL 2+

The raster and vector drivers are integrated into the gdal library and you use GDALOpenEx to open both raster and vector datasets. The ogr library/namespace is still available for backwards compatibility.

Here's a link to the WFS Driver documentation and the OGR API tutorial.

5
  • thanks, iv tried this, i downloaded PS and GCS files (although i dont know what they are/what they are for but it said i needed them and linked GDAL_DATA path to the location they are saved) but now when i run using the OGR functions i get this error and have no idea what it means (same error happens if i run ogrinfo in console) ERROR 6: EPSG PCS/GCS code 4326 not found in EPSG support files. Is this a valid EPSG coordinate system?
    – AngryDuck
    Commented Jul 31, 2013 at 10:33
  • but it does print out all of the data from my wfs though
    – AngryDuck
    Commented Jul 31, 2013 at 10:37
  • @AngryDuck Either set a GDAL_DATA environment variable before running your program or call CPLSetConfigOption. You don't need to download gdal data files, they're included in the source you built from. There's more files than the ones you downloaded.
    – user2856
    Commented Jul 31, 2013 at 11:01
  • Hmmm that sucks my data dir for my GDAL source contains just a licence text file?? where are these files meant to be?
    – AngryDuck
    Commented Jul 31, 2013 at 11:14
  • ok got the files from the original download they must have got lost when i compiled all something, all working now no errors thanks!!
    – AngryDuck
    Commented Jul 31, 2013 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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