[QGIS-Developer] QgsJsonUtils does not parse fields - bug or a feature?

Áron Gergely aron.gergely at rasterra.nl
Thu Jul 23 00:30:45 PDT 2020


Hi list,

I am parsing a larger (about 200k characters) GeoJSON FeatureCollection 
string via QgsJsonUtils.stringToFields().
It contains polygon features, each with many coordinate pairs.
Despite the string being valid GeoJSON, no fields are returned.

However, if I save the string to a .geojson file and open it as vector 
layer, it opens with the attribute fields.

I am working with both QGIS 3.10.8 and 3.14.1 on Ubuntu.
Here is a simplified example of the GeoJSON structure:

{
     "features": [
         {
             "geometry": {
                 "coordinates": [
                     [
                         [
                             0.0,
                             1.0
                         ],
                      .
                      .
                      .
                         [
                             0.0,
                             1.0
                         ]
                     ]
                 ],
                 "type": "Polygon"
             },
             "id": "abcd",
             "type": "Feature",
             "properties": {
                 "attrib_a": "a text",
                 "attrib_b": 1
             }
         }
     ],
"type": "FeatureCollection"
}


I found that if I do either of the below steps before calling 
QgsJsonUtils.stringToFields(), it does return the fields:

  *   significantly reduce the number of coordinate pairs
  *   Change the order of objects so that "type"  is ahead of "geometry"
    in the features.

I looked at the unit tests of QgsJsonUtils but only short geojson 
strings are tested there..

So it looks like large geometry objects in the GeoJSON feature would 
prevent reading its fields... unless "type" is parsed before them?

Is this buggy behavior? Or am I missing something?

Should I open an issue on GitHub?



Best regards,
Aron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200723/bb8719e3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: aron_gergely.vcf
Type: text/x-vcard
Size: 4 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200723/bb8719e3/attachment.vcf>


More information about the QGIS-Developer mailing list