Open BartStikkers opened 2 years ago
Alter SQL code of vector layer to include a WHERE clause (RMB on layer in panel, "Update SQL layer...")
@BartStikkers I don't think that a filtering a layer with "update SQL layer" is something supported in Processing. For sure is supported the filter that you can add with right click > filter.
I don't think that a filtering a layer with "update SQL layer" is something supported in Processing.
@gioman I'm not sure what you mean by that. It goes wrong because it enters the whole SQL statement if you change the query in any way beyond "SELECT * FROM [table]", not just if you add a WHERE statement. GDAL supports this just fine, the QGIS dialog just doesn't generate the console call properly. Since it does try to, I'm assuming it's intended to work.
Since it does try to, I'm assuming it's intended to work.
yes maybe.
Also:
For sure is supported the filter that you can add with right click > filter.
This is not the case. When I try it, the filter is ignored and the entire vector layer is used as a mask. I can't use the "Selected features only" option either, it remains grayed out.
This is not the case. When I try it, the filter is ignored and the entire vector layer is used as a mask.
@BartStikkers can't confirm.
I can't use the "Selected features only" option either, it remains grayed out.
to use this option the selection must be done on map (manually, or selecting by value/expression/etc.).
What is the bug or the crash?
When I use the "clip raster by mask layer" function, the generated GDAL command line code looks like this:
gdalwarp -overwrite -of GTiff -cutline "[connection string]'" -cl "(SELECT * FROM countries WHERE admin = 'Spain')" -crop_to_cutline C:/INPUT.tif C:/OUTPUT.tif
But this produces an error:
ERROR 1: Failed to identify source layer from datasource. Process returned error code 1
Testing it in the command line, this does work:
gdalwarp -overwrite -of GTiff -cutline "[connection string]'" -csql "(SELECT * FROM countries WHERE admin = 'Spain')" -crop_to_cutline C:/INPUT.tif C:/OUTPUT.tif
So when the mask layer is a postGIS layer the flag should be -csql instead of -cl.
In addition, the code that's responsible for pasting in the SQL statement isn't working properly. It works fine when I change the statement to be like what you see above, but when I write perfectly functional SQL like this:
the resulting statement in the GDAL command looks like this:
gdalwarp -overwrite -of GTiff -cutline "[connection string]" -cl "(SELECT * FROM \\" -crop_to_cutline [etc]
So something about the way escaped characters are parsed isn't going right.
Steps to reproduce the issue
Versions
QGIS version | 3.20.3-Odense | QGIS code revision | 495fbaec -- | -- | -- | -- Qt version | 5.15.2 Python version | 3.9.5 GDAL/OGR version | 3.3.1 PROJ version | 8.1.1 EPSG Registry database version | v10.028 (2021-07-07) GEOS version | 3.9.1-CAPI-1.14.2 SQLite version | 3.35.2 PDAL version | 2.3.0 PostgreSQL client version | 13.0 SpatiaLite version | 5.0.1 QWT version | 6.1.3 QScintilla2 version | 2.11.5 OS version | Windows 10 Version 2009 | | | Active Python plugins | ClipMultipleLayersee_pluginLDMPquick_map_servicesdb_managerMetaSearchprocessing QGIS version 3.20.3-Odense QGIS code revision [495fbaec](https://github.com/qgis/QGIS/commit/495fbaec) Qt version 5.15.2 Python version 3.9.5 GDAL/OGR version 3.3.1 PROJ version 8.1.1 EPSG Registry database version v10.028 (2021-07-07) GEOS version 3.9.1-CAPI-1.14.2 SQLite version 3.35.2 PDAL version 2.3.0 PostgreSQL client version 13.0 SpatiaLite version 5.0.1 QWT version 6.1.3 QScintilla2 version 2.11.5 OS version Windows 10 Version 2009 Active Python plugins ClipMultipleLayers ee_plugin LDMP quick_map_services db_manager MetaSearch processing ### Supported QGIS version - [X] I'm running a supported QGIS version according to the roadmap. ### New profile - [X] I tried with a new QGIS profile ### Additional context _No response_