Read-only mirror of https://github.com/sogis/qgis-json-tests — Kanton Solothurn. Issues & pull requests at the source.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2019-07-09 16:57:03 +02:00
postgresql-serviceconf adding docker-compose file for test environment 2019-06-27 14:57:12 +02:00
qgis adding docker-compose file for test environment 2019-06-27 14:57:12 +02:00
screenshots more screenshots of identify results of json structures 2019-06-27 15:19:54 +02:00
sql adding docker-compose file for test environment 2019-06-27 14:57:12 +02:00
.gitignore update .gitignore 2019-06-27 15:19:01 +02:00
docker-compose.yml adding docker-compose file for test environment 2019-06-27 14:57:12 +02:00
LICENSE Create LICENSE 2019-07-09 16:57:03 +02:00
README.md Update README.md 2019-06-28 14:08:24 +02:00

qgis-json-tests

Testing Display of JSON data in QGIS Desktop and QGIS server

Goals

  • Test JSON Display in QGIS widgets

Relevant PRs/commits

Unit tests from OpenGIS

Remarks

  • jsonb is the binary version
  • jsonb can be created by casting a json text string to jsonb, e.g. "'{"a":1,"b":2}'::jsonb
  • Minimum PG versions: 9.2 for json and 9.4 for jsonb

Advantages / Disadvantages of json vs jsonb

jsonb advantages jsonb disadvantages
faster queries (SELECT) may change original formatting slighly when compared to exact copy in json
supports indexing slightly slower input (INSERT and UPDATE)
faster than hstore data type may take more disk space than plain json
certain queries (e.g. aggregates) may be slower due to lack of statistics

see also Faster Operations with the JSONB Data Type in PostgreSQL

Display of JSON Data in QGIS Desktop

see also OPENGIS blog post "Visualize Postgres JSON data in QML widgets"

Useful json-compatible widgets in QGIS

  • List
  • Key/Value
  • Text Edit (preferably with Multiline Option)
  • QML Widget

Attention: by default, QGIS assigns the Key/Value widget to json/jsonb data types. If the JSON structure isn't compatible one will see an empty widget, even if JSON data exists.

Text Edit widget

Sample Structure: any valid JSON structure can be used.

Configuration hints: For longer structures be sure to check the "Multiline" checkbox in the "Text edit" widget configuration.

Screenshot configuration of text edit widget

This is how it looks like in a text edit widget in form mode, regardless if the source data type is json or jsonb:

Screenshot display of text edit widget in form mode

List widget

Valid json structure for list widget:

[
 "Apples",
 "Cherries",
 "Bananas",
 "Strawberries"
]

Screenshot configuration of list widget

This is how it looks like in a list widget in form mode, regardless if the source data type is json or jsonb:

Screenshot display of list widget in form mode

Key/Value widget

Valid json structure for list widget:

{
 "Apples": 20,
 "Cherries": 13,
 "Bananas": 23,
 "Strawberries": 7
}

Screenshot configuration of key-value widget

This is how it looks like in a list widget in form mode, regardless if the source data type is json or jsonb:

Screenshot display of list widget in form mode

Attribute Table View

This is how the attribute table looks like for the different widget types: list and key/value entries are separated by kommas combined with a blank as separater, keys are separated from the values with a colon and a blank:

Screenshot of json data in table mode

Note that the height of the rows are not auto-sized and often need to be made a bit higher manually.

Display of JSON Data in the combo QGIS Server and Desktop

To test whether raw json/jsonb data is supported there is a Postgis/QGIS Server test environment that you can start with:

docker-compose up

in the root of this repository.

GetFeatureInfo results with format "text/plain"

GetFeatureInfo results with format text/plain

Remarks: displays as expected

GetFeatureInfo results with format "text/html"

GetFeatureInfo results with format text/html

Remarks: Works ok, but room for improvements.

Proposal for improvements:

  • for text widgets: use <pre></pre> tag to preserver line breaks and display with a monospace-font
  • for list widget: use <ul><li></li></ul> structure
  • for key value widget: use <table/> structure

GetFeatureInfo results with format "application/json"

GetFeatureInfo results with format application/json

Remarks: doesn't display at all. Fixes pending