Esempio n. 1
0
QgsWmsProvider * QgsWMSConnection::provider( )
{
  // TODO: Create and bind to data provider

  // load the server data provider plugin
  QgsProviderRegistry * pReg = QgsProviderRegistry::instance();

  QgsWmsProvider *wmsProvider =
    ( QgsWmsProvider* ) pReg->provider( "wms", mUri.encodedUri() );

  return wmsProvider;
}
// this is static
QString QgsNewVectorLayerDialog::runAndCreateLayer( QWidget* parent, QString* pEnc )
{
  QgsNewVectorLayerDialog geomDialog( parent );
  if ( geomDialog.exec() == QDialog::Rejected )
  {
    return QLatin1String( "" );
  }

  QgsWkbTypes::Type geometrytype = geomDialog.selectedType();
  QString fileformat = geomDialog.selectedFileFormat();
  QString enc = geomDialog.selectedFileEncoding();
  int crsId = geomDialog.selectedCrsId();
  QgsDebugMsg( QString( "New file format will be: %1" ).arg( fileformat ) );

  QList< QPair<QString, QString> > attributes;
  geomDialog.attributes( attributes );

  QSettings settings;
  QString lastUsedDir = settings.value( QStringLiteral( "/UI/lastVectorFileFilterDir" ), QDir::homePath() ).toString();
  QString filterString = QgsVectorFileWriter::filterForDriver( fileformat );
  QString fileName = QFileDialog::getSaveFileName( nullptr, tr( "Save layer as..." ), lastUsedDir, filterString );
  if ( fileName.isNull() )
  {
    return QLatin1String( "" );
  }

  if ( fileformat == QLatin1String( "ESRI Shapefile" ) && !fileName.endsWith( QLatin1String( ".shp" ), Qt::CaseInsensitive ) )
    fileName += QLatin1String( ".shp" );

  settings.setValue( QStringLiteral( "/UI/lastVectorFileFilterDir" ), QFileInfo( fileName ).absolutePath() );
  settings.setValue( QStringLiteral( "/UI/encoding" ), enc );

  //try to create the new layer with OGRProvider instead of QgsVectorFileWriter
  QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
  QString ogrlib = pReg->library( QStringLiteral( "ogr" ) );
  // load the data provider
  QLibrary* myLib = new QLibrary( ogrlib );
  bool loaded = myLib->load();
  if ( loaded )
  {
    QgsDebugMsg( "ogr provider loaded" );

    typedef bool ( *createEmptyDataSourceProc )( const QString&, const QString&, const QString&, QgsWkbTypes::Type,
        const QList< QPair<QString, QString> >&, const QgsCoordinateReferenceSystem & );
    createEmptyDataSourceProc createEmptyDataSource = ( createEmptyDataSourceProc ) cast_to_fptr( myLib->resolve( "createEmptyDataSource" ) );
    if ( createEmptyDataSource )
    {
      if ( geometrytype != QgsWkbTypes::Unknown )
      {
        QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromSrsId( crsId );
        if ( !createEmptyDataSource( fileName, fileformat, enc, geometrytype, attributes, srs ) )
        {
          return QString::null;
        }
      }
      else
      {
        QgsDebugMsg( "geometry type not recognised" );
        return QString::null;
      }
    }
    else
    {
      QgsDebugMsg( "Resolving newEmptyDataSource(...) failed" );
      return QString::null;
    }
  }

  if ( pEnc )
    *pEnc = enc;

  return fileName;
}
Esempio n. 3
0
QgsVectorLayerImport::QgsVectorLayerImport( const QString &uri,
    const QString &providerKey,
    const QgsFields& fields,
    QGis::WkbType geometryType,
    const QgsCoordinateReferenceSystem* crs,
    bool overwrite,
    const QMap<QString, QVariant> *options,
    QProgressDialog *progress )
    : mErrorCount( 0 )
    , mAttributeCount( -1 )
    , mProgress( progress )

{
  mProvider = nullptr;

  QgsProviderRegistry * pReg = QgsProviderRegistry::instance();

  QLibrary *myLib = pReg->providerLibrary( providerKey );
  if ( !myLib )
  {
    mError = ErrInvalidProvider;
    mErrorMessage = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
    return;
  }

  createEmptyLayer_t * pCreateEmpty = reinterpret_cast< createEmptyLayer_t * >( cast_to_fptr( myLib->resolve( "createEmptyLayer" ) ) );
  if ( !pCreateEmpty )
  {
    delete myLib;
    mError = ErrProviderUnsupportedFeature;
    mErrorMessage = QObject::tr( "Provider %1 has no %2 method" ).arg( providerKey, "createEmptyLayer" );
    return;
  }

  delete myLib;

  // create an empty layer
  QString errMsg;
  mError = pCreateEmpty( uri, fields, geometryType, crs, overwrite, &mOldToNewAttrIdx, &errMsg, options );
  if ( hasError() )
  {
    mErrorMessage = errMsg;
    return;
  }

  Q_FOREACH ( int idx, mOldToNewAttrIdx.values() )
  {
    if ( idx > mAttributeCount )
      mAttributeCount = idx;
  }

  mAttributeCount++;

  QgsDebugMsg( "Created empty layer" );

  QgsVectorDataProvider *vectorProvider = dynamic_cast< QgsVectorDataProvider* >( pReg->provider( providerKey, uri ) );
  if ( !vectorProvider || !vectorProvider->isValid() || ( vectorProvider->capabilities() & QgsVectorDataProvider::AddFeatures ) == 0 )
  {
    mError = ErrInvalidLayer;
    mErrorMessage = QObject::tr( "Loading of layer failed" );

    if ( vectorProvider )
      delete vectorProvider;

    return;
  }

  mProvider = vectorProvider;
  mError = NoError;
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
    int rtn;
    int rank;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    if(rank == 0){
        //QApplication::setStyle("plastique");
        //QApplication::setDesktopSettingsAware(true);
        //QApplication::setEffectEnabled(true);

        QString myPluginsDir = "/usr/lib/qgis/plugins";
        QgsProviderRegistry * preg = QgsProviderRegistry::instance(myPluginsDir);
        QString pluglist=preg->pluginList();
        //printf("plugins: %s\n",pluglist.toStdString().c_str());
        //fflush(stdout);

        QgsApplication a(argc, argv, TRUE);
        //QApplication a(argc, argv);
        Prb w;
        w.show();
        rtn = a.exec();
    }
    else{
        // wait
        int runCnt = 0;
        while (true){

            int rank;
            MPI_Comm_rank(MPI_COMM_WORLD, &rank);
            printf("************ Run count = %i for rank %i\n", ++runCnt, rank);
            fflush(stdout);

            librasterblaster::Configuration conf;
            // local variables for MPI_Recv
            MPI_Status status;
            char str[1000];
            int n;
            long m;
            //receive the partition size
            MPI_Recv(&n, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
            conf.partition_size = n;
            // receive the input file
            MPI_Recv(str, 1000, MPI_CHAR, 0, 1, MPI_COMM_WORLD, &status);
            conf.input_filename = str;
            // receive the output file
            MPI_Recv(str, 1000, MPI_CHAR, 0, 2, MPI_COMM_WORLD, &status);
            conf.output_filename = str;
            //receive the resampler;
            MPI_Recv(&(conf.resampler), sizeof(enum librasterblaster::RESAMPLER), MPI_BYTE, 0, 3, MPI_COMM_WORLD, &status);
            // receive the output srs
            MPI_Recv(str, 1000, MPI_CHAR, 0, 4, MPI_COMM_WORLD, &status);
            conf.output_srs = str;
            //receive the fillvalue
            MPI_Recv(str, 1000, MPI_CHAR, 0, 5, MPI_COMM_WORLD, &status);
            conf.fillvalue = str;


            // reporting

            printf("process %i received partition size %i\n", rank, conf.partition_size);
            printf("process %i received input file %s\n", rank, conf.input_filename.c_str());
            printf("process %i received output file file %s\n", rank, conf.output_filename.c_str());
            //printf("process %i received resampler %l\n", rank, conf.resampler);

            if(conf.resampler == librasterblaster::MIN){
                printf("process %i received resampler MIN\n", rank);
            }
            else if(conf.resampler == librasterblaster::MAX){
                printf("process %i received resampler MAX\n", rank);
            }
            else if(conf.resampler == librasterblaster::NEAREST){
                printf("process %i received resampler NEAREST\n", rank);
            }
            else  if(conf.resampler == librasterblaster::MEAN){
                printf("process %i received resampler MEAN\n", rank);
            }
            else {
                 printf("process %i received resampler NONE OF THE ABOVE\n", rank);
            }
            printf("process %i received output srs %s\n", rank, conf.output_srs.c_str());
            printf("process %i received fillvalue file %s\n", rank, conf.fillvalue.c_str());
            fflush(stdout);
            int ret =  librasterblaster::prasterblasterpio(conf, NULL);


        }






    }



    MPI_Finalize();
    return rtn;
}
Esempio n. 5
0
QgsPluginManager::QgsPluginManager( QgsPythonUtils* pythonUtils, QWidget * parent, Qt::WFlags fl )
    : QDialog( parent, fl )
{
  setupUi( this );

  mPythonUtils = pythonUtils;

  // set the default lib dir to the qgis install directory/lib (this info is
  // available from the provider registry so we use it here)
  QgsProviderRegistry *pr = QgsProviderRegistry::instance();
  /*  char **argv = qApp->argv();
     QString appDir = argv[0];
     int bin = appDir.findRev("/bin", -1, false);
     QString baseDir = appDir.left(bin);
     QString libDir = baseDir + "/lib"; */

  lblPluginDir->setText( pr->libraryDirectory().path() );
  setTable();
  getPluginDescriptions();
  getPythonPluginDescriptions();
  mModelProxy->sort( 0, Qt::AscendingOrder );
  //
  // Create the select all and clear all buttons and add them to the
  // buttonBox
  //
  QPushButton * btnSelectAll = new QPushButton( tr( "&Select All" ) );
  QPushButton * btnClearAll = new QPushButton( tr( "&Clear All" ) );
  buttonBox->addButton( btnSelectAll, QDialogButtonBox::ActionRole );
  buttonBox->addButton( btnClearAll, QDialogButtonBox::ActionRole );
  // connect the slot up to catch when a bookmark is deleted
  connect( btnSelectAll, SIGNAL( clicked() ), this, SLOT( selectAll() ) );
  // connect the slot up to catch when a bookmark is zoomed to
  connect( btnClearAll, SIGNAL( clicked() ), this, SLOT( clearAll() ) );

  leFilter->setFocus( Qt::MouseFocusReason );

  qRegisterMetaType<QgsDetailedItemData>();

  // disable plugin installer button for now until we resolve some problems [MD]
  btnPluginInstaller->hide();
#if 0
  // add installer's icon
  QString myCurThemePath = QgsApplication::activeThemePath() + "/plugins/plugin_installer.png";
  QString myDefThemePath = QgsApplication::defaultThemePath() + "/plugins/plugin_installer.png";
  if ( QFile::exists( myCurThemePath ) )
  {
    btnPluginInstaller->setIcon( QIcon( myCurThemePath ) );
  }
  else if ( QFile::exists( myDefThemePath ) )
  {
    btnPluginInstaller->setIcon( QIcon( myDefThemePath ) );
  }

  // check for plugin installer
  if ( checkForPluginInstaller() )
  {
    connect( btnPluginInstaller, SIGNAL( clicked() ), this, SLOT( showPluginInstaller() ) );
  }
  else
  {
    btnPluginInstaller->setEnabled( false );
  }
#endif
}
QgsVectorLayerExporter::QgsVectorLayerExporter( const QString &uri,
    const QString &providerKey,
    const QgsFields &fields,
    QgsWkbTypes::Type geometryType,
    const QgsCoordinateReferenceSystem &crs,
    bool overwrite,
    const QMap<QString, QVariant> &options,
    QgsFeatureSink::SinkFlags sinkFlags )
  : mErrorCount( 0 )
  , mAttributeCount( -1 )

{
  mProvider = nullptr;

  QgsProviderRegistry *pReg = QgsProviderRegistry::instance();

  std::unique_ptr< QLibrary > myLib( pReg->createProviderLibrary( providerKey ) );
  if ( !myLib )
  {
    mError = ErrInvalidProvider;
    mErrorMessage = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
    return;
  }

  createEmptyLayer_t *pCreateEmpty = reinterpret_cast< createEmptyLayer_t * >( cast_to_fptr( myLib->resolve( "createEmptyLayer" ) ) );
  if ( !pCreateEmpty )
  {
    mError = ErrProviderUnsupportedFeature;
    mErrorMessage = QObject::tr( "Provider %1 has no %2 method" ).arg( providerKey, QStringLiteral( "createEmptyLayer" ) );
    return;
  }

  // create an empty layer
  QString errMsg;
  mError = pCreateEmpty( uri, fields, geometryType, crs, overwrite, &mOldToNewAttrIdx, &errMsg, !options.isEmpty() ? &options : nullptr );
  if ( errorCode() )
  {
    mErrorMessage = errMsg;
    return;
  }

  Q_FOREACH ( int idx, mOldToNewAttrIdx )
  {
    if ( idx > mAttributeCount )
      mAttributeCount = idx;
  }

  mAttributeCount++;

  QgsDebugMsg( QStringLiteral( "Created empty layer" ) );

  QString uriUpdated( uri );
  // HACK sorry...
  if ( providerKey == QLatin1String( "ogr" ) )
  {
    QString layerName;
    if ( options.contains( QStringLiteral( "layerName" ) ) )
      layerName = options.value( QStringLiteral( "layerName" ) ).toString();
    if ( !layerName.isEmpty() )
    {
      uriUpdated += QLatin1String( "|layername=" );
      uriUpdated += layerName;
    }
  }

  QgsDataProvider::ProviderOptions providerOptions;
  QgsVectorDataProvider *vectorProvider = dynamic_cast< QgsVectorDataProvider * >( pReg->createProvider( providerKey, uriUpdated, providerOptions ) );
  if ( !vectorProvider || !vectorProvider->isValid() || ( vectorProvider->capabilities() & QgsVectorDataProvider::AddFeatures ) == 0 )
  {
    mError = ErrInvalidLayer;
    mErrorMessage = QObject::tr( "Loading of layer failed" );

    delete vectorProvider;
    return;
  }

  // If the result is a geopackage layer and there is already a field name FID requested which
  // might contain duplicates, make sure to generate a new field with a unique name instead
  // that will be filled by ogr with unique values.

  // HACK sorry
  const QString path = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "ogr" ), uri ).value( QStringLiteral( "path" ) ).toString();
  if ( sinkFlags.testFlag( QgsFeatureSink::SinkFlag::RegeneratePrimaryKey ) && path.endsWith( QLatin1String( ".gpkg" ), Qt::CaseInsensitive ) )
  {
    QString fidName = options.value( QStringLiteral( "FID" ), QStringLiteral( "FID" ) ).toString();
    int fidIdx = vectorProvider->fields().lookupField( fidName );
    if ( fidIdx != -1 )
    {
      mOldToNewAttrIdx.remove( fidIdx );
    }
  }

  mProvider = vectorProvider;
  mError = NoError;
}