0

I am trying to load a WMS into my C++ program to use it as a GDALDataset. The problem is that I am able to load the WMS but every time I am doing a GetRasterCount() I get 0; and every time I am trying to do a GetRasterBand(0) I get "Erreur de segmentation (core dumped)".

I was doing the same thing for WFS (GetLayerCount() and GetLayer(0)) and it was working fine.

Here is my code:

GDALAllRegister();
GDALDataset *poDS = static_cast<GDALDataset*>(
poDS = (GDALDataset*)GDALOpenEx("https://geowebservices.stanford.edu/geoserver/ows?SERVICE=WMS&request=GetCapabilities", GDAL_OF_RASTER,NULL,NULL,NULL ));

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

std::cout << "THE DATASET CONTAINS THIS MANY RASTER BANDS : " << poDS->GetRasterCount() << std::endl;

for (int i = 0; i < poDS->GetRasterCount(); i++){

    GDALRasterBand  *band;
    band = poDS->GetRasterBand(i);
    std::cout << band->GetXSize() << std::endl;
}
  • 1
    There are no rasters in a WMS Capabilities response, just like there are no features in a WFS Capabilities response. What happens if you use GetLayerCount() and GetLayer(0) on the WMS Capabilities? – nmtoken Nov 20 '20 at 10:07
  • I still get 0 for GetLayerCount() and GetLayer(0) doesn't give me an error but if I do a GetName() afterwards, I get a segmentation core dumped error. – The Guest Nov 20 '20 at 10:51
  • maybe the problem comes from the wms ? – The Guest Nov 20 '20 at 10:52
  • gdalinfo "geowebservices.stanford.edu/geoserver/…" works fine so I would guess the WMS is fine – Ian Turton Nov 20 '20 at 11:19

Your Answer

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

Browse other questions tagged or ask your own question.