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

G. Allegri giohappy at gmail.com
Tue Oct 10 03:02:00 PDT 2017


Hi Even,
I thought file writing path went through the OGR provider, while it simply
uses QgsFileWriter.
Is there any reason not having OGR_F_SetFID be used? If there isn't any
side effect could we use it by default?

giovanni

2017-10-09 18:48 GMT+02:00 Even Rouault <even.rouault at spatialys.com>:

> 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/20171010/96d21fe7/attachment.html>


More information about the QGIS-Developer mailing list