I have a Web app where you can create geodata with OpenLayers. (Polygons and points). It's saved on a PostGIS database along with other non-geographic data. You can export the geographic data as shapefiles and open them in QGIS. And then import the shapefiles back to the server after modifications in QGIS.

I would like the QGIS user to be able to work on the features without going through this procedure of export and import. I want him to have direct access through a REST API. Is there a way in QGIS or a plugin that is able to get and then push the modifications to my server when saving his work?


Solution 1 is to:

  • open the port on your PostGIS database
  • declare the connection in the Data Source Manager of QGIS
  • directly consume the PostGIS table within QGIS where you can edit

No need to go through any import/export or something like a REST API.

Main drawback is while you do local edit on QGIS, you may get edit also on Web app. It can be a "deal breaker" because you may have editing conflicts.

Solution 2:

You may want to expose your PostGIS table(s) by using OGC standard WFS-T (WFS with transaction e.g editing capabilities) as QGIS can directly do editing in this case (built-in)

Solution 3:

If you really want to make call to a particular REST API, you will need to customize PyQGIS code. Instead of print statements, you would need to replace code to make your http calls to your API. This partial answer supposes you know some Python and you already first made a call to your REST API to get features and then load them using a recipe like https://anitagraser.com/pyqgis-101-introduction-to-qgis-python-programming-for-non-programmers/pyqgis101-creating-editing-a-new-vector-layer/

layer = iface.activeLayer()
def afterCommitChanges():

# Simple version but you surely will need to use other signals listed at
# https://qgis.org/api/classQgsVectorLayer.html starting with keyword
# "committed" like `committedFeaturesAdded` (second sample)

def committedFeaturesAdded(layerId, addedFeatures):
    print(layerId, addedFeatures)

# To stop listening to signal event when editing. Do not do it when testing but only at the end, to clean event management

  • Thanks! Ok Solution 1 might not be suitable because I can't give access to the full table to the user, but only the rows that concern his account. The DB gathers data from multiple users... Solution 3 might not be suitable either because I can't ask my clients to do modifications to their QGIS software. Solution 2 WFS-T seems the way to go. But I have to see if it's possible to filter the results on the server to serve only the data the user has right on. And do also some processing to add specific attributes to features. What do you think? – Philiz May 9 at 13:55
  • For solution 1, look at "Row Security Policies" to manage users rights per row on the same table postgresql.org/docs/13/ddl-rowsecurity.html For solution 2 rights management, you may look at github.com/geoserver/geofence (but then you will be tied to GeoServer to serve WFS-T) – ThomasG77 May 9 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.