geraldo / qgs-layer-parser

Parse QGIS project file and create JSON config file
GNU General Public License v3.0
0 stars 0 forks source link

qgs-layer-parser

Parse QGIS 3 project files and write a JSON config file with layer information.

Getting started

Start the script using python3 parseQGS.py project.qgs [mapproxy_project_name]

It creates a JSON configuration file called project.qgs.json.

A typical output for a layer could look like this:

  {
    "hidden": false,
    "indentifiable": true,
    "actions": [],
    "name": "barris",
    "type": "layer",
    "showLegend": true,
    "external": false,
    "visible": true,
    "fields": [
      {
        "name": "N_Distri"
      },
      {
        "name": "N_Barri"
      },
      {
        "name": "Coord_X"
      },
      {
        "name": "Coord_Y"
      }
    ]
  },

Error debugging

If you run the script on a server without X Server, you could get an error like:

qt.qpa.xcb: could not connect to display qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.

qgis-layer-parser uses QgsApplication, which needs QGuiApplication, but principally is a console applications to be run in a non-X environment, so try turning off X Server by:

export QT_QPA_PLATFORM=offscreen

If you still run into troubles, try to set QT_DEBUG_PLUGINS=1.

Configuration

QGIS project variables

Groups and layers can be hidden by adding their names inside an array like QGIS project variable:

Special characters

Alternativly to QGIS project variables some special characters can be used to hide layers, etc.:

More info

The project includes a test QGIS 3 project called bcn-geodata.qgs and it's geojson sources. It uses Open Data from Barceclona with information about districts and neighbourhoods.

It also includes an exmaple using ol-layerswitcher using the produced bcn-geodata.json file to configure layers. You can see the result opening layerswitcher.html.