Beispiel #1
0
QVector<QgsDataItem *> QgsWmsDataItemProvider::createDataItems( const QString &path, QgsDataItem *parentItem )
{
  QVector<QgsDataItem *> items;
  if ( path.startsWith( QLatin1String( "geonode:/" ) ) )
  {
    QString connectionName = path.split( '/' ).last();
    if ( QgsGeoNodeConnectionUtils::connectionList().contains( connectionName ) )
    {
      QgsGeoNodeConnection connection( connectionName );

      QString url = connection.uri().param( QStringLiteral( "url" ) );
      QgsGeoNodeRequest geonodeRequest( url, true );

      const QStringList encodedUris( geonodeRequest.fetchServiceUrlsBlocking( QStringLiteral( "WMS" ) ) );

      if ( !encodedUris.isEmpty() )
      {
        for ( const QString &encodedUri : encodedUris )
        {
          QgsDebugMsg( encodedUri );
          QgsDataSourceUri uri;
          QgsSettings settings;
          QString key( QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + "/" + connectionName );

          QString dpiMode = settings.value( key + "/wms/dpiMode", "all" ).toString();
          uri.setParam( QStringLiteral( "url" ), encodedUri );
          if ( !dpiMode.isEmpty() )
          {
            uri.setParam( QStringLiteral( "dpiMode" ), dpiMode );
          }

          QgsDebugMsg( QStringLiteral( "WMS full uri: '%1'." ).arg( QString( uri.encodedUri() ) ) );

          QgsDataItem *item = new QgsWMSConnectionItem( parentItem, QStringLiteral( "WMS" ), path, uri.encodedUri() );
          if ( item )
          {
            items.append( item );
          }
        }
      }
    }
  }

  return items;
}
Beispiel #2
0
QVector<QgsDataItem *> QgsXyzTileDataItemProvider::createDataItems( const QString &path, QgsDataItem *parentItem )
{
  QVector<QgsDataItem *> items;
  if ( path.startsWith( QLatin1String( "geonode:/" ) ) )
  {
    QString connectionName = path.split( '/' ).last();
    if ( QgsGeoNodeConnectionUtils::connectionList().contains( connectionName ) )
    {
      QgsGeoNodeConnection connection( connectionName );

      QString url = connection.uri().param( QStringLiteral( "url" ) );
      QgsGeoNodeRequest geonodeRequest( url, true );

      const QgsStringMap urlData( geonodeRequest.fetchServiceUrlDataBlocking( QStringLiteral( "XYZ" ) ) );

      if ( !urlData.isEmpty() )
      {
        auto urlDataIt = urlData.constBegin();
        for ( ; urlDataIt != urlData.constEnd(); ++urlDataIt )
        {
          const QString layerName = urlDataIt.key();
          QgsDebugMsg( urlDataIt.value() );
          QgsDataSourceUri uri;
          uri.setParam( QStringLiteral( "type" ), QStringLiteral( "xyz" ) );
          uri.setParam( QStringLiteral( "url" ), urlDataIt.value() );

          QgsDataItem *item = new QgsXyzLayerItem( parentItem, layerName, path, uri.encodedUri() );
          if ( item )
          {
            items.append( item );
          }
        }
      }
    }
  }

  return items;
}
Beispiel #3
0
void QgsWCSSourceSelect::addButtonClicked()
{
  QgsDataSourceUri uri = mUri;

  QString identifier = selectedIdentifier();
  if ( identifier.isEmpty() ) { return; }

  uri.setParam( QStringLiteral( "identifier" ), identifier );

  // Set crs only if necessary (multiple offered), so that we can decide in the
  // provider if WCS 1.0 with RESPONSE_CRS has to be used.  Not perfect, they can
  // add more CRS in future and URI will be saved in project without any.
  // TODO: consider again, currently if crs in url is used to set WCS coverage CRS,
  //       without that param user is asked for CRS
  //if ( selectedLayersCRSs().size() > 1 )
  //{
  uri.setParam( QStringLiteral( "crs" ), selectedCrs() );
  //}

  QgsDebugMsg( "selectedFormat = " +  selectedFormat() );
  if ( !selectedFormat().isEmpty() )
  {
    uri.setParam( QStringLiteral( "format" ), selectedFormat() );
  }

  QgsDebugMsg( "selectedTime = " +  selectedTime() );
  if ( !selectedTime().isEmpty() )
  {
    uri.setParam( QStringLiteral( "time" ), selectedTime() );
  }

  QString cache;
  QgsDebugMsg( QString( "selectedCacheLoadControl = %1" ).arg( selectedCacheLoadControl() ) );
  cache = QgsNetworkAccessManager::cacheLoadControlName( selectedCacheLoadControl() );
  uri.setParam( QStringLiteral( "cache" ), cache );

  emit addRasterLayer( uri.encodedUri(), identifier, QStringLiteral( "wcs" ) );
}
QgsRasterLayer* QgsRemoteOWSBuilder::wmsLayerFromUrl( const QString& url, const QString& layerName, QList<QgsMapLayer*>& layersToRemove, bool allowCaching ) const
{
  QgsDebugMsg( "Entering" );
  QgsRasterLayer* result = nullptr;
  QString baseUrl, format, crs;
  QStringList layerList, styleList;

  if ( allowCaching )
  {
    result = qobject_cast<QgsRasterLayer*>( QgsMSLayerCache::instance()->searchLayer( url, layerName ) );
  }

  if ( result )
  {
    return result;
  }

  QStringList urlList = url.split( QStringLiteral( "?" ) );
  if ( urlList.size() < 2 )
  {
    return nullptr;
  }
  baseUrl = urlList.at( 0 );
  QStringList paramList = urlList.at( 1 ).split( QStringLiteral( "&" ) );

  QStringList::const_iterator paramIt;
  for ( paramIt = paramList.constBegin(); paramIt != paramList.constEnd(); ++paramIt )
  {
    if ( paramIt->startsWith( QLatin1String( "http" ), Qt::CaseInsensitive ) )
    {
      baseUrl = paramIt->split( QStringLiteral( "=" ) ).at( 1 );
    }
    else if ( paramIt->startsWith( QLatin1String( "FORMAT" ), Qt::CaseInsensitive ) )
    {
      format = paramIt->split( QStringLiteral( "=" ) ).at( 1 );
    }
    else if ( paramIt->startsWith( QLatin1String( "CRS" ), Qt::CaseInsensitive ) )
    {
      crs = paramIt->split( QStringLiteral( "=" ) ).at( 1 );
    }
    else if ( paramIt->startsWith( QLatin1String( "LAYERS" ), Qt::CaseInsensitive ) )
    {
      layerList = paramIt->split( QStringLiteral( "=" ) ).at( 1 ).split( QStringLiteral( "," ) );
    }
    else if ( paramIt->startsWith( QLatin1String( "STYLES" ), Qt::CaseInsensitive ) )
    {
      styleList = paramIt->split( QStringLiteral( "=" ) ).at( 1 ).split( QStringLiteral( "," ) );
    }
  }

  QgsDebugMsg( "baseUrl: " + baseUrl );
  QgsDebugMsg( "format: " + format );
  QgsDebugMsg( "crs: " + crs );
  QgsDebugMsg( "layerList first item: " + layerList.at( 0 ) );
  QgsDebugMsg( "styleList first item: " + styleList.at( 0 ) );

  QgsDataSourceUri uri;
  uri.setParam( QStringLiteral( "url" ), baseUrl );
  uri.setParam( QStringLiteral( "format" ), format );
  uri.setParam( QStringLiteral( "crs" ), crs );
  uri.setParam( QStringLiteral( "layers" ), layerList );
  uri.setParam( QStringLiteral( "styles" ), styleList );
  result = new QgsRasterLayer( uri.encodedUri(), QLatin1String( "" ), QStringLiteral( "wms" ) );
  if ( !result->isValid() )
  {
    return nullptr;
  }

  //insert into cache
  if ( allowCaching )
  {
    QgsMSLayerCache::instance()->insertLayer( url, layerName, result );
  }
  else
  {
    layersToRemove.push_back( result );
  }
  return result;
}