[QGIS-Developer] QGIS/OGR: FeatureIds reassigned on write to data provider?

Matthias Kuhn matthias at opengis.ch
Tue Jul 4 09:33:34 PDT 2017


Hi Sandro,

The commit that introduced this behavior was done around 2 years back.
The reason for this was mainly interoperability with other applications
as Even mentioned.

https://github.com/qgis/QGIS/commit/7d7cdcd376c0d3fa60af1403a91e1e611b210174

Most relevant discussion around the issue can be found here, where this
behavior with changing feature ids is also pointed out (sorry, the
thread is really long).

https://issues.qgis.org/issues/11007

To alleviate the impact, the signal `QgsVectorLayer::dataChanged()` was
introduced. As soon as this signal is emitted, any cached feature id
should be discarded. It might help to let the geometry checker reload
the data when feature ids are bogus.

I don't know if it would be possible for OGR - in case of a repack() -
to create an internal map of new ids to original ids (or if it would be
possible for people to stop using shp :P). But I really don't know the
internals of ogr (or people) good enough to comment on the feasibility
of such a mechanism.

Regards
Matthias

On 7/4/17 5:51 PM, Sandro Mani wrote:
>
> Hi Even
>
> Thanks for the reply. Yes I am indeed testing with shapefiles.
>
> Not sure why I never observed this behaviour previously, but indeed I
> have up to now never observed this myself, nor have received bug
> reports concerned with this kind breakage - and this is a pretty hard
> to miss issue since the plugin will essentially behave randomly.
>
> In any event, so I suppose other than manually introducing a UUID
> attribute to the features and identifying them by a attribute filter
> expression, there is no way to reliably identify a feature over the
> lifetime of the layer being loaded in QGIS?
>
> I'm kinda inclined to think that I'm not the only one relying on
> feature ids to identify features?
>
> Sandro
>
> On 04.07.2017 17:36, Even Rouault wrote:
>>
>> Sandro,
>>
>>  
>>
>> I guess this might depend on the actual OGR driver used. Somehow I
>> assume you use shapefiles here ?
>>
>>  
>>
>> This is probably linked to shapefiles being repacked after the end of
>> various operations
>>
>> such as addFeatures(), changeGeometryValues(), deleteFeatures(), so
>> as to avoid issues
>>
>> with other software that don't like holes in SHP and DBF files.
>>
>>  
>>
>> There have been changes in that area to rebustify shapefile
>> recompaction that used
>>
>> to work not so well on Windows (although most of them were in OGR
>> itself),
>>
>> but my understanding of
>>
>> https://github.com/qgis/QGIS/blob/release-2_12/src/providers/ogr/qgsogrprovider.cpp
>>
>> is that even in 2.12, feature deletion should cause a repack of the
>> shapefile, so
>>
>> I'm not sure why the issue would be new
>>
>>  
>>
>> Even
>>
>>  
>>
>> > Hi
>>
>> >
>>
>> > I'm doing work on the geometry checker in QGIS master and noticed that,
>>
>> > when deleting features from an ogr vector layer, FeatureIds appear
>> to be
>>
>> > reassigned to fill up the gap in the ids. This is a pretty serious
>>
>> > blocker for the geometry checker since geometry checker errors are
>>
>> > identified by the feature id (and other parameters). So if the
>>
>> > FeatureIds change, the geometry checker errors may suddenly reference
>>
>> > the wrong feature, causing general mayhem.
>>
>> >
>>
>> > Can anyone confirm that indeed FeatureIds are being purposefully
>>
>> > reassigned, and whether there is a rationale behind this change (I
>> never
>>
>> > observed this before in QGIS 2.x)? And if so, what other options exist
>>
>> > to reliably reference a feature over the entire lifetime of the layer
>>
>> > being loaded in QGIS?
>>
>> >
>>
>> > Note that in the geometry checker, I don't use the edit buffer, but
>>
>> > write each change directly to the data provider. This to avoid that
>>
>> > situations where, after fixing multiple errors, the final result cannot
>>
>> > be committed due to a particular geometry still being invalid and the
>>
>> > provider refusing to accept the change.
>>
>> >
>>
>> > Thanks
>>
>> > Sandro
>>
>> >
>>
>> > _______________________________________________
>>
>> > QGIS-Developer mailing list
>>
>> > QGIS-Developer at lists.osgeo.org
>>
>> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>>  
>>
>>  
>>
>> -- 
>>
>> Spatialys - Geospatial professional services
>>
>> http://www.spatialys.com
>>
>
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170704/c2211f43/attachment.html>


More information about the QGIS-Developer mailing list