[Qgis-user] Question
Richard Duivenvoorde
rdmailings at duif.net
Tue Jul 21 04:32:50 PDT 2020
Hi,
FYI These kind of developers/c++ questions are problably better asked/answered on the QGIS-dev list
I think you also should add some more context, for example:
- what exactly are you trying to do? Add a rasterlayer to... what?
- which development/Operating system environment are you using for this?
- is this a standalone dir applicatio?
- is this code somewhere on github so others can have a look?
Otherwise this is too open I think, for others to take the time to try to understand and answer.
Regards,
Richard Duivenvoorde
On 7/21/20 1:18 PM, Alireza Ghalavand wrote:
> Hello,
>
>
> Qgis Error “Raster layer Cannot instantiate the 'gdal' data provider” in qt c++ <https://stackoverflow.com/questions/63010283/qgis-error-raster-layer-cannot-instantiate-the-gdal-data-provider-in-qt-c>
>
> When I am trying to add a raster layer, I get this error from QgsRasterLayer::IsValid()!!! Can anybody tell me why this happens!? I am beginner in qgis, so could you please explain in detail. the first func "onAddLayer" used for Add button clicked and second func is defined for adding a raster layer.
>
> *my code:*
> void MainWindow::onAddLayer()
> {
> const auto path = QFileDialog::getOpenFileName(this, "SELECT GIS MAP LAYER", QDir(
> _lastMapDir).path());
>
> if (path.isEmpty() || path.isNull())
> {
> return;
> }
>
> addRasterLayer(path);
> _lastMapDir = QDir(path).canonicalPath();
> }
>
> void MainWindow::addRasterLayer(const QFileInfo &info)
> {
> LOG(QString("adding map layer %1").arg(info.filePath()));
> QString errMsg;
>
> // if (!QgsRasterLayer::isValidRasterFileName(info.filePath(), errMsg))
> // {
> // LOG(errMsg);
>
> // return;
> // }
>
> QScopedPointer<QgsRasterLayer> layer(new QgsRasterLayer(info.filePath(), info.baseName()));
> //layer->setDataProvider("gdal"); // Added by ArGhalavand
>
> if (!layer->isValid())
> {
> LOG(QString("failed to add layer (%1)").arg(layer->error().message(
> QgsErrorMessage::Format::Text)));
>
> return;
> }
>
> save("last_layer_path", info.filePath(), "gis");
> _rasterProvider = layer->dataProvider();
> _mapCanvas->freeze(true);
> auto item = QgsMapCanvasLayer(layer.take(), true);
> _mapCanvas->setExtent(item.layer()->extent());
> QgsMapLayerRegistry::instance()->addMapLayer(item.layer(), true);
> _mapCanvas->setLayerSet(QList<QgsMapCanvasLayer>() << item);
> _mapCanvas->freeze(false);
> _mapCanvas->setVisible(true);
> _mapCanvas->refresh();
> statusBar()->showMessage(QString("%1 LOADED").arg(info.fileName()), 3000);
> }
>
> *With Best Regards,*
> Alireza Ghalavand
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
More information about the Qgis-user
mailing list