QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren() { QgsDebugMsg( "Entered" ); QVector<QgsDataItem*> children; QgsDataSourceURI uri; uri.setEncodedUri( mUri ); QgsDebugMsg( "mUri = " + mUri ); QgsWmsSettings wmsSettings; if ( !wmsSettings.parseUri( mUri ) ) { children.append( new QgsErrorItem( this, tr( "Failed to parse WMS URI" ), mPath + "/error" ) ); return children; } QgsWmsCapabilitiesDownload capDownload( wmsSettings.baseUrl(), wmsSettings.authorization() ); bool res = capDownload.downloadCapabilities(); if ( !res ) { children.append( new QgsErrorItem( this, tr( "Failed to download capabilities" ), mPath + "/error" ) ); return children; } QgsWmsCapabilities caps; if ( !caps.parseResponse( capDownload.response(), wmsSettings.parserSettings() ) ) { children.append( new QgsErrorItem( this, tr( "Failed to parse capabilities" ), mPath + "/error" ) ); return children; } // Attention: supportedLayers() gives tree leafs, not top level QVector<QgsWmsLayerProperty> layerProperties = caps.supportedLayers(); if ( layerProperties.count() ) { QgsWmsCapabilitiesProperty capabilitiesProperty = caps.capabilitiesProperty(); const QgsWmsCapabilityProperty& capabilityProperty = capabilitiesProperty.capability; // Top level layer is present max once // <element name="Capability"> // <element ref="wms:Layer" minOccurs="0"/> - default maxOccurs=1 const QgsWmsLayerProperty &topLayerProperty = capabilityProperty.layer; foreach ( const QgsWmsLayerProperty &layerProperty, topLayerProperty.layer ) { // Attention, the name may be empty QgsDebugMsg( QString::number( layerProperty.orderId ) + " " + layerProperty.name + " " + layerProperty.title ); QString pathName = layerProperty.name.isEmpty() ? QString::number( layerProperty.orderId ) : layerProperty.name; QgsWMSLayerItem *layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + "/" + pathName, capabilitiesProperty, uri, layerProperty ); children << layer; } }
QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren() { QVector<QgsDataItem*> children; QgsDataSourceURI uri; uri.setEncodedUri( mUri ); QgsDebugMsg( "mUri = " + mUri ); QgsWmsSettings wmsSettings; if ( !wmsSettings.parseUri( mUri ) ) { children.append( new QgsErrorItem( this, tr( "Failed to parse WMS URI" ), mPath + "/error" ) ); return children; } bool res = mCapabilitiesDownload->downloadCapabilities( wmsSettings.baseUrl(), wmsSettings.authorization() ); if ( !res ) { children.append( new QgsErrorItem( this, tr( "Failed to download capabilities" ), mPath + "/error" ) ); return children; } QgsWmsCapabilities caps; if ( !caps.parseResponse( mCapabilitiesDownload->response(), wmsSettings.parserSettings() ) ) { children.append( new QgsErrorItem( this, tr( "Failed to parse capabilities" ), mPath + "/error" ) ); return children; } // Attention: supportedLayers() gives tree leafs, not top level QVector<QgsWmsLayerProperty> layerProperties = caps.supportedLayers(); if ( !layerProperties.isEmpty() ) { QgsWmsCapabilitiesProperty capabilitiesProperty = caps.capabilitiesProperty(); const QgsWmsCapabilityProperty& capabilityProperty = capabilitiesProperty.capability; // If we have several top-level layers, or if we just have one single top-level layer, // then use those top-level layers directly if ( capabilityProperty.layers.size() > 1 || ( capabilityProperty.layers.size() == 1 && capabilityProperty.layers[0].layer.size() == 0 ) ) { Q_FOREACH ( const QgsWmsLayerProperty& layerProperty, capabilityProperty.layers ) { // Attention, the name may be empty QgsDebugMsg( QString::number( layerProperty.orderId ) + ' ' + layerProperty.name + ' ' + layerProperty.title ); QString pathName = layerProperty.name.isEmpty() ? QString::number( layerProperty.orderId ) : layerProperty.name; QgsWMSLayerItem *layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + '/' + pathName, capabilitiesProperty, uri, layerProperty ); children << layer; } }
QgsGrassGisLib::Raster QgsGrassGisLib::raster( QString name ) { QgsDebugMsg( "name = " + name ); foreach ( Raster raster, mRasters ) { if ( raster.name == name ) return raster; } QString providerKey; QString dataSource; int band = 1; if ( name.contains( "provider=" ) ) // encoded uri { QgsDataSourceURI uri; uri.setEncodedUri( name.toLocal8Bit() ); if ( uri.hasParam( "band" ) ) { band = uri.param( "band" ).toInt(); } providerKey = uri.param( "provider" ); if ( providerKey == "gdal" ) { dataSource = uri.param( "path" ); } else { uri.removeParam( "band" ); uri.removeParam( "provider" ); dataSource = uri.encodedUri(); } } else // simple GDAL path { providerKey = "gdal"; dataSource = name; band = 1; } QgsDebugMsg( "providerKey = " + providerKey ); QgsDebugMsg( "dataSource = " + dataSource ); QgsDebugMsg( QString( "band = %1" ).arg( band ) ); Raster raster; raster.name = name; raster.band = band; raster.provider = ( QgsRasterDataProvider* )QgsProviderRegistry::instance()->provider( providerKey, dataSource ); if ( !raster.provider || !raster.provider->isValid() ) { // No fatal, it may be used to test file existence //fatal( "Cannot load raster provider with data source: " + dataSource ); } else { raster.input = raster.provider; if ( band < 1 || band > raster.provider->bandCount() ) { fatal( "Band out of range" ); } QgsDebugMsg( QString( "mCrs valid = %1 = %2" ).arg( mCrs.isValid() ).arg( mCrs.toProj4() ) ); QgsDebugMsg( QString( "crs valid = %1 = %2" ).arg( raster.provider->crs().isValid() ).arg( raster.provider->crs().toProj4() ) ); if ( mCrs.isValid() ) { // GDAL provider loads data without CRS as EPSG:4326!!! Verify, it should give // invalid CRS instead. if ( !raster.provider->crs().isValid() ) { fatal( "Output CRS specified but input CRS is unknown" ); } if ( mCrs != raster.provider->crs() ) { raster.projector = new QgsRasterProjector(); raster.projector->setCRS( raster.provider->crs(), mCrs ); raster.projector->setInput( raster.provider ); raster.input = raster.projector; } } } raster.fd = mRasters.size(); mRasters.insert( raster.fd, raster ); return raster; }