Some of you might be familiar with geoserver for serving spatial data as consumable WMS/WFS layers. The issue is that as far as I know, you have to manually manage assets upload and specifying styles manually. Also the tool is a bit dated.
One modern alternative is QGIS server, you can find pre-made docker image online, and it also syncs with the Desktop version. The good thing about QGIS server is that you can create a QGIS project via the desktop application, then upload it wholesale to Postgres instance as QGIS server backend.
Assuming we’re starting with raw spatial data as hardfiles, and you want to use Postgres as data store backend, and that you don’t want to expose the database to public:
- Import data to QGIS desktop.
Fix geometries> save to Postgres.
Collect geometries> save to Postgres. (This is for some cases where the raw data contain both
MultiPolygonin the same file, Postgres backend doesn’t allow mixed geometry type).
Import Layer/File, and set desired
CRS+ spatial index here.
- Import uploaded layers into current QGIS project.
- Import geoserver styles (in SLD format) in QGIS via python console, then attach to layers.
layer = iface.activeLayer() layer.loadSldStyle("style.sld")
- Save current project as
*.qgz, manually replace
private ip address.
- Re-zip the assets into
*.qgz. Important: have to use command-line on MacOS.
- Turn on airplane mode, then open the modified QGIS project. (This is so that it won’t keep reaching Postgres via private ip.)
- Disable airplane mode, then write the project to Postgres. (Need to whitelist your home ip so that you can reach prod db behind vpc.)
- Voila 🎉
- To be sure, restart the server every time you update the project.
- Need to use private ip for database hostname.
- On M1, need to use QGIS installed via mamba. (Otherwise you’ll have missing requirements for