Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for postgresraster based rasters in Raster Calculator #43440

Merged
merged 3 commits into from May 30, 2021

Conversation

jgrocha
Copy link
Member

@jgrocha jgrocha commented May 29, 2021

Description

This PR makes both gdal and postgresraster based rasters available in the Raster Calculator.

Fix #43439

postgresraster

I've tested two or three raster operations and it worked fine with theses rasters (as expected).

The Raster Calculator, opened from processing tool also include these rasters now.

@github-actions github-actions bot added this to the 3.20.0 milestone May 29, 2021
@@ -735,7 +735,7 @@ QVector<QgsRasterCalculatorEntry> QgsRasterCalculatorEntry::rasterEntries()
for ( ; layerIt != layers.constEnd(); ++layerIt )
{
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( layerIt.value() );
if ( rlayer && rlayer->dataProvider() && rlayer->providerType() == QLatin1String( "gdal" ) )
if ( rlayer && rlayer->dataProvider() && ( rlayer->providerType() == QLatin1String( "gdal" ) || rlayer->providerType() == QLatin1String( "postgresraster" ) ) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason to test the providerType() at all ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so @rouault, at least for now.

If not, wms layers, for example, would also be listed in the raster calculator. Are we able to handle wms layers properly in the raster calculator?

I've done a quick test. I was not able to use the raster calculator with a WMS layer. Raster Calculator is not able to estimate the row and columns numbers from the source (using the Selected Layer Extent button), for example, as we do for a gdal or postgresqraster raster. Writing down the size of the output raster was not enough. I've got many src/core/raster/qgsrasterblock.h:818 : (valueAndNoData) [0ms] Data block not allocated errors while reading the data blocks.

In my opinion, we would need to review all descendant classes of QgsRasterLayer before allowing them to be listed in the raster calculator.

What do you think? Should we list all QgsRasterLayer descendant classes here and fix the failing issues?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps testing for (capabilities() & QgsRasterDataProvider::Size) != 0 which is true for the GDAL provider and PostgisRaster one, but not the WMS one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've improved the condition. It doesn't use provider literal names anymore. Thanks @rouault for the tip.

I've also removed the condition from the dialog itself. The list is provided by rasterEntries() where the condition makes sense. It was unnecessary duplicated on the dialog side.

@rouault rouault merged commit bbb74b8 into qgis:master May 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raster calculator does not include rasters from postgresraster provider
2 participants