[QGIS-Developer] On the fly on MapCanvas
bachgist at gmail.com
bachgist at gmail.com
Mon Mar 16 19:54:17 PDT 2020
Dear QGIS-Developer,
I am writing a simple program to display raster data using qgis api C++.
When I open raster data that has different coordinate systems, the
on-the-fly feature does not work on my mapCanvas.
Can someone help me?
This is my code:
OpenGisData::OpenGisData(QWidget *parent)
: QMainWindow(parent)
{
setupUi(this);
QWidget* centralWidget = OpenGisDataClass::centralWidget;
mMapCanvas = new QgsMapCanvas(centralWidget);
QGridLayout* gridLayout = new QGridLayout;
gridLayout->addWidget(mMapCanvas);
centralWidget->setLayout(gridLayout);
connect(actionOpen, &QAction::triggered, this, &OpenGisData::open);
}
void OpenGisData::open()
{
QString fileName = QFileDialog::getOpenFileName(this, "Open data",
"D:\\Test");
if (!fileName.isEmpty())
{
QgsRasterLayer* rasterLayer = new QgsRasterLayer(fileName);
if (rasterLayer && rasterLayer->isValid())
{
QList<QgsMapLayer*> layers = mMapCanvas->layers();
layers.append(rasterLayer);
mMapCanvas->setLayers(layers);
mMapCanvas->zoomToFullExtent();
}
}
}
Thank You
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200317/2e756532/attachment.html>
More information about the QGIS-Developer
mailing list