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

native:savefeatures unable to specify output layer #56517

Closed
2 tasks done
Malvineous opened this issue Feb 25, 2024 · 4 comments
Closed
2 tasks done

native:savefeatures unable to specify output layer #56517

Malvineous opened this issue Feb 25, 2024 · 4 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Feedback Waiting on the submitter for answers Processing Relating to QGIS Processing framework or individual Processing algorithms

Comments

@Malvineous
Copy link

What is the bug or the crash?

There is no way to specify the output layer, so the output is always empty.

Steps to reproduce the issue

When using the Processing Toolbox, the UI does not provide a way to select an output layer. The qgis_process command this generates looks like so:

qgis_process --no-python run native:savefeatures --distance_units=meters --area_units=m2 --ellipsoid=NONE \
  --INPUT=input.gpkg --OUTPUT=output.gpkg --LAYER_NAME=photos --DATASOURCE_OPTIONS= \
  --LAYER_OPTIONS= --ACTION_ON_EXISTING_FILE=2

(If you run this command, output.gpkg must already exist with a photos layer for the above command to append to due to the value of ACTION_ON_EXISTING_FILE.)

Observe in the output, the LAYER_NAME is empty, so the output file is not modified:

----------------
Results
----------------

FILE_PATH:      output.gpkg
LAYER_NAME:
OUTPUT: output.gpkg

According to the source code, you can specify an output layer like this: --OUTPUT=output.gpkg|layername=photos however this fails with the error Could not create layer output.gpkg|layername=photos: OGR driver for '' not found (OGR error: ).

Versions

<style type="text/css"> p, li { white-space: pre-wrap; } </style>
QGIS version 3.34.1-Prizren QGIS code branch Release 3.34
Qt version 5.15.11
Python version 3.11.6
Compiled against GDAL/OGR 3.8.0 Running against GDAL/OGR 3.8.2
Compiled against PROJ 9.3.0 Running against PROJ 9.3.1
EPSG Registry database version v10.098 (2023-11-24)
GEOS version 3.12.0-CAPI-1.18.0
SQLite version 3.44.2
Compiled against PDAL 2.6.1 Running against PDAL 2.6.2
PostgreSQL client version 16.1
SpatiaLite version 5.1.0
QWT version 6.2.0
QScintilla2 version 2.14.1
OS version Arch Linux
       
Active Python plugins
MetaSearch 0.3.6
grassprovider 2.12.99
db_manager 0.1.20
processing 2.12.99
QGIS version 3.34.1-Prizren QGIS code branch [Release 3.34](https://github.com/qgis/QGIS/tree/release-3_34) Qt version 5.15.11 Python version 3.11.6 Compiled against GDAL/OGR 3.8.0 Running against GDAL/OGR 3.8.2 Compiled against PROJ 9.3.0 Running against PROJ 9.3.1 EPSG Registry database version v10.098 (2023-11-24) GEOS version 3.12.0-CAPI-1.18.0 SQLite version 3.44.2 Compiled against PDAL 2.6.1 Running against PDAL 2.6.2 PostgreSQL client version 16.1 SpatiaLite version 5.1.0 QWT version 6.2.0 QScintilla2 version 2.14.1 OS version Arch Linux

Active Python plugins
MetaSearch
0.3.6
grassprovider
2.12.99
db_manager
0.1.20
processing
2.12.99

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

I notice that qgsalgorithmsavefeatures.cpp:120 is passing the full destination string (including the |layername= part) to QgsVectorFileWriter::create(), which is the function that seems to fail when the output string contains a layer name.

Yet it's not until line 164 that the layer name is split off the base filename, so I'm wondering whether this is happening in the wrong order?

I'm not really sure though as it seems to specify the inputs and outputs quite differently to some of the other algorithms.

My use case is that I am writing a shell script to import geotagged photos into a layer, run some SQL on them to make some changes, and finally take that data and append it to an existing layer of geotagged photos. This final step of appending the data onto the existing layer is what's failing here.

@Malvineous Malvineous added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Feb 25, 2024
@agiudiceandrea agiudiceandrea added the Processing Relating to QGIS Processing framework or individual Processing algorithms label Feb 25, 2024
@alexbruy
Copy link
Contributor

Could not reproduce on master.

Observe in the output, the LAYER_NAME is empty, so the output file is not modified:

Have you actually checked output file? It is modified. The LAYER_NAME output is set only when "Create or overwrite file" and "Create or overwrite layer" modes are used, in the append mode layer name is not supposed to change.

When using the Processing Toolbox, the UI does not provide a way to select an output layer.

That's not true, layer name parameter is an advanced one. You need to expand Advanced parameter group to see it. By default (if layer name is not set explicitly) algorithm will derive layer name from the input filename.

@alexbruy alexbruy added the Feedback Waiting on the submitter for answers label Jan 22, 2025
@Malvineous
Copy link
Author

Yes, the output file was unchanged. At the time of reporting the bug there was no layer name option in the UI, but going in now, I see it has since been added.

It's been almost a year since I looked at this so I'm fuzzy on the details, but it looks like I was able to get it to work by using an extra file, as it seems the input and output layer names had to be the same. So instead of copying between layers I copied between different files with the same layer names.

I'm not sure if this is the case now, as generating a qgis_process command in the UI seems to allow the input field to have a layer specified, which I couldn't get working before. And I can now specify a LAYER_NAME too which I couldn't before.

I'm going to close this bug as it looks like it may have been fixed at some point in the last year.

@alexbruy
Copy link
Contributor

At the time of reporting the bug there was no layer name option in the UI, but going in now, I see it has since been added.

That's not true, this option was here since algorithm addition in 2020 and it was always marked as advanced.

@Malvineous
Copy link
Author

Well one way or another the value wasn't being used when I ran it. It's been almost a year now with no comment so unfortunately I've long forgotten the details, but I wouldn't have logged the bug report if it was as simple as filling out a text field.

Thinking hard about it now, I vaguely recall the problem was LAYER_NAME on the advanced tab was being used as the layer name for both the input and output files, so I couldn't set a layer name on the output file that was different to the input.

So what I felt was missing at the time, was an option to set the output layer name differently to the input layer name, so both of them didn't have to be the same.

When you say it works for you, have you tried exporting from a layer called "A", and appending that to layer called "B"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Feedback Waiting on the submitter for answers Processing Relating to QGIS Processing framework or individual Processing algorithms
Projects
None yet
Development

No branches or pull requests

3 participants