[QGIS-Developer] set and export FID with OGR provider

Even Rouault even.rouault at spatialys.com
Mon Oct 9 09:48:39 PDT 2017


On lundi 9 octobre 2017 18:13:42 CEST G. Allegri wrote:
> HI all,
> GeoJSON RFC7946 states that "If a Feature has a commonly used identifier,
> that identifier SHOULD be included as a member of the Feature object with
> the name "id", and the value of this member is either a JSON string or
> number". For example OpenLayers tries to parse the id field to uniquely
> identify the features inside a GeoJSON feature collection.
> I've digged how OGR GeoJSON driver treats FIDs during serialization and it
> seems that it will write it if the OGrFeature has the FID field set [2],
> but AFAICS QIGS OGR provider doesn't set it unless "the first attribute is
> the FID and the user has set it". Well, this condition depends on [4], and
> now I odn't understand how this applies to a QGIS layer being exported to
> GeoJSON.
> 
> Questions:
>  - is there a way to force the OGR provider setting the FID?

None that I can think ok

>  - could the OGR provider have an option to force it from the export
> window, like Mapserver does with the USE_FEATUREID option for its output
> format

Possibly, but are sure your use case involve the OGR provider at all ? "Save a layer as"
normally involves the QgsVectorFileWriter class. But the issue will be the same. By the way when looking at it, I saw
https://github.com/qgis/QGIS/blob/master/src/core/qgsvectorfilewriter.cpp#L1987 whose
logic is completely broken: OGR_F_SetFID() would only be called for QGIS feature ids > INT_MAX.
This weird stuff comes from https://github.com/qgis/QGIS/commit/891e66523fdf21283ca15533684a57dd8c27f955
I guess only the debug message makes sense in this test.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20171009/52ff9fc7/attachment-0001.html>


More information about the QGIS-Developer mailing list