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

Negative feature IDs, no updates possible #28218

Open
qgib opened this issue Nov 7, 2018 · 11 comments
Open

Negative feature IDs, no updates possible #28218

qgib opened this issue Nov 7, 2018 · 11 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Editing

Comments

@qgib
Copy link
Contributor

qgib commented Nov 7, 2018

Author Name: Jeffrey Bostoen (Jeffrey Bostoen)
Original Redmine Issue: 20398
Affected QGIS version: 3.4.1
Redmine category:editing


I'm using data retrieved from a MySQL data source, using an x86 driver.
BIGINTs seem to internally be converted in some cases to negative values for ogc_fid.
Features get rendered, but it seems I'm unable to update any of the features with a negative ogc_fid

@qgib
Copy link
Contributor Author

qgib commented Nov 7, 2018

Author Name: Jeffrey Bostoen (Jeffrey Bostoen)


Actually tried a workaround with a GeoJSON file, but each time I edit it, it just creates another .tmp file and leaves the original file untouched ...

@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Editing labels May 25, 2019
@debaser75
Copy link

This seems to be happening with geopackages on 3.4.2 as well. I imported OSM data to a geopackage. Some of the features were given a negative FID value. These negative values tend to be 'big' as well (e.g., -1984514722) even though there are only 319 features in this point layer. I can update an attribute value for any feature with a positive FID, but the edits don't persist when I edit a field on a feature that has a negative value.

It appears that negative FIDs are also causing this problem with PostGIS layers served via WFS, as documented here. So it seems like this may be an issue with QGIS and not the data sources.

@vesnikos
Copy link

vesnikos commented Jun 9, 2020

yep, this seems to be the case for QGIS 3.12.2

@dingausmwald
Copy link

$id gives negative ids too. Qgis 3.14.15, geopackage, windows 10. Have to execute the $id command a second time after closing attribute table to get positive ids.

@andreasneumann
Copy link
Member

As far as I know, the negative IDs are "normal" as long as you haven't saved your features to file or DB. Then they are changed to DB generated IDs. Unless you are in transaction mode, where you get the DB generated ids immediately. But transaction mode is only available for selected DBs, like PostgreSQL, Oracle and perhaps (not sure) SQL-Server.

@dingausmwald
Copy link

Yes, this was the case in earlier versions, at least ive seen this behaviour before. But now, with geopackage and 3.14.15, the negative ids stay even after save, after closing and opening the att table.

Whole steps where:
Create geopackage
create id field
copying some line features from one table to another (different table structure)
execute $id on all id fields (in att table)
save

  • ids still -50 to -60 or something like that

@gioman
Copy link
Contributor

gioman commented Sep 8, 2020

Whole steps where:
Create geopackage
create id field
copying some line features from one table to another (different table structure)
execute $id on all id fields (in att table)
save

* ids still -50 to -60 or something like that

@dingausmwald can you attach sample data? thanks!

@gioman gioman added the Feedback Waiting on the submitter for answers label Sep 8, 2020
@gioman gioman removed the Feedback Waiting on the submitter for answers label Dec 22, 2020
@gioman gioman changed the title Negative feature IDs = no updates possible? Negative feature IDs, no updates possible Dec 22, 2020
@Skipper-is
Copy link

Skipper-is commented Oct 19, 2022

I am having the same issue with version 3.22.10
I have attached the geopackage with the faulty layer. It isn't everything as it has sensitive data, but this is an example of what happens.
faultygeopackage.zip
I digitised a new feature, using snapping, around an existing feature, and initially it looked good. Pressed save, geometry is now null, FID is negative, and I now am unable to remove that feature from the layer to redigitise, or even see the feature (as geom is now null).
Has happened with a few features, and I've had to go in and do SQL "DELETE FROM" to get rid of them. Seems to mainly happen when snapping is used for me, like it is creating some invalid goemetry, but instead of telling me, it just corrupts everything. I'm using snapping to vertex, segment and area, with enable topological editing, snapping on intersection, and tracing on

@bpf800
Copy link

bpf800 commented Apr 30, 2023

I have the same problem in QGIS 3.28.5. The layer is pure manual digitization except that at one point I transformed the project for QFieldCloud. Now one feature suddenly has fid '-62' and I cannot edit or delete it. Edits disappear as soon as I have typed them when I leave the field. Delete attempts give an error message, but not helpful:
grafik
Here a look at the attributes of this and similar features:
grafik

I think the main bug is that once a negative fid occurs, it should be possible to at least delete the feature. I am relatively new to QGIS and don't immediately know how to apply an SQL command like the previous commentor.

I have restarted QGIS and the laptop, and made and saved other changes to this layer after noticing the problem with one feature.

I don't know how this fid got there, but will provide some info:

  • Even if I inadvertently typed into that autogenerate field, it would not have been a negative number as all my data are positive.

  • Info about the layer:
    grafik

  • Form for the fid field -- I think it was the default:
    grafik
    grafik

The preview of '-62' as the default is strange. I have edited and added other features after looking at the wrong feature and this remains.

Any ideas? I can provide more info; the project is small and not secret.

@bpf800
Copy link

bpf800 commented Apr 30, 2023

I tried to figure out @Skipper-is 's solution inside QGIS, found DB Manager, could enter select * from Kaesten where fid < 0 and see that I have 5 rows with this problem. However, delete from Kaesten where fid < 0 gives an error as it is interpreted as CREATE TEMP VIEW _tview AS delete from Kaesten where fid < 0: 1, because "kaesten" is shown as a virtual layer.

Am I missing a trick to edit the actual table from inside QGIS, or do I have to try to edit "kaesten.gpkg" with an external SQLite editor?

@bpf800
Copy link

bpf800 commented May 1, 2023

(I did remove those rows with DB Browser for SQLite.)

I have found ways to reproduce the error, i.e., produce rows with negative fids that then become unmodifiable and undeletable:

  • Add a feature (in my case a point). Do not save the layer yet.
  • Open the attribute table and modify an attribute of this feature. Here I changed Column 'Details' for features with 'Nummer' 17 and 18:

grafik

  • While other features added since last saving look like this:

grafik

The same happens if I click with the 'Move Feature' Tool on a feature that I added but did not save yet.

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! Editing
Projects
None yet
Development

No branches or pull requests

8 participants