[Qgis-developer] Strange behaviour in feature ids when editing PostGIS layer

Victor Olaya volayaf at gmail.com
Fri Feb 6 02:39:56 PST 2015


Hi all,

I am seeing a behaviour that surprised me when editing a PostGIS
layer. HEre's a detailed explanation

Let's say I have a layer with 3 features with ids 1,2 and 3. In a
layer such as a shapefile, if you move the feature with the id 1, the
geometryChanged signal is fired, with the feature id and the new
geometry as parameters. When the editingStopped signal is emitted
after editing is finished, you can query the layer to get the feature
with that id 1, and it will be there, with the modified geometry.

In the case of a PostGIS layer, when the editingStopped signal is
emitted, the query will return no features. The feature with id 1 is
no longer there, and instead there will be a feature with id equal to
4. So basically it seems that a modification of a feature is really a
removal and then an addition, and the added feature has a different id
than the removed one,

I am sure there must be an explanation for that, based on how PostGIS
works, or how the corresponding provider handles the transactions and
the id, but this seems to me rather confusing.

In this situation (and in case this is not a bug that can't be fixed),
how would you implement a mechanism for, whenever a layer is modified,
do something later with the modified features?. Storing the ids of the
modified features and then using them on the method that is connected
to edittingStopped() won't work in this case.

Thanks in advance.


More information about the Qgis-developer mailing list