Gokul Gopan Contact
← Back to Projects

PLAN4BETTER · PYQGIS

From a database layer to a finished map.

A connected QGIS workflow I developed: add a shared basemap and layout, apply the correct database style to the project layer, then export the finished map with its note embedded as PNG metadata.

01 / LAYOUT TOOLS

Add the shared basemap into the QGIS project.

The project already contains the database layer amenity_mainburg. I use Layout Tools to add BasemapDE Vektor – Straßenfokus from the shared project template. The full QGIS layer panel is visible: the new basemap appears below the database layer.

QGIS Layout Tools with amenity_mainburg in the Layers panel and BasemapDE Vektor – Straßenfokus added
The layout/basemap plugin selects the shared template and adds the vector basemap to the current QGIS project.

02 / P4B STYLING

Apply the correct database style and rename the layer.

With the layer and basemap in place, P4B Styling reads the active vector layer and lists only compatible styles from PostgreSQL. Here the input is amenity_mainburg and the selected point style is Apotheke. Applying it changes the map symbols and sets the display name to Apotheke.

P4B Styling plugin selecting amenity_mainburg and Apotheke style
Select the database layer and the matching stored style.
QGIS map after P4B Styling applies the Apotheke style and renames the layer
The same layer is renamed Apotheke and receives pharmacy symbols. The layer panel and basemap remain visible.
What the code does

It loads QML definitions from PostgreSQL, filters the style list by QGIS geometry type, writes the selected QML to a temporary file, calls loadNamedStyle(), refreshes the canvas and renames the layer. The underlying features and attributes are unchanged.

03 / LAYOUT TOOLS

Open the imported print layout.

The layout selected from the shared template is registered in QGIS and becomes available through Project → Layouts. Opening Bevölkerungsdichte brings the template into the Layout Manager, including its map frame, title, legend, logos, scale bar, north arrow and metadata fields.

QGIS Project menu showing imported Bevölkerungsdichte layout
The imported layout is available from the QGIS Project menu.
QGIS Layout Manager showing the imported Bevölkerung print layout
The shared print layout opens with map, legend, scale bar, north arrow and description fields ready for project-specific content.

04 / EXPORT WITH METADATA

Export the map and keep its note attached.

The export tool selects one or more QGIS print layouts, renders each one at 300 dpi and saves it as a PNG. It reads the layout item named Description, cleans its line breaks and stores that note in the PNG metadata together with an author field.

This prepares the output for a later workflow: the map image and its note can be extracted together and given to an LLM as context. The plugin itself does not call an LLM.

QGIS print layoutMap + Description item
300 dpi PNGQgsLayoutExporter
Map note metadataComment + Author for downstream LLM context

RESULT

A repeatable map-production workflow inside QGIS.

Layout Tools brings standardised basemaps and layouts into the project. P4B Styling makes the project layer readable and consistently named. The exporter preserves the map note with the final image. My employer reference confirms internal use of the styling and layout plugins and faster, more consistent map production.

Python · PyQGIS · Qt · PostgreSQL · QML · XML · Pillow