1

I am new to QGIS (Version 3.2.2) and basically what I want to archive is to load OSM data and apply my own map style to it. However once I have defined my style I would also like to be able to load new OSM data and instantly select the same features (roads, rails, etc.) and apply my custom style.

The workflow I have come up so far is:

  • load the data according to https://gis.stackexchange.com/a/101746/120164
  • creating my style by creating layers, which I do as follows:
    • connect to the database
    • expand the database in the browser
    • double click on the type of features I want in my new layer (points, lines, polygons, etc.)
    • add a filter to the new layer, so only features with the key/tag I want are in the layer

From a software developers point of view, I would now just switch the database connection and the queries could be applied to another database and so a map of another region would be rendered without having to do much. However it seems that the layers are somehow linked to the database.

Is there an easy way to just take the style/selection of features and apply it to other mapdata?

2
  • 2
    For the style part, you can save them as qml files, and apply that style file to any new database connection. If you look into my style files at github.com/Andre-J/QGIS-OpenStreetMap-Styles. you see that I have only three, one for every geometry type.
    – AndreJ
    Commented Sep 2, 2018 at 13:28
  • Thanks this was very helpful. Especially since it showed me how rule based rendering works, which is far easier than the approach I used before. I compiled my findings in a separate answer.
    – T. Watzl
    Commented Sep 6, 2018 at 18:22

2 Answers 2

2

Yes, in QGIS you can copy and paste styles or you can save styles for later usage. The style defined for one layer can be applied to another (if layers share the same geometry and use the same fields and values for attribute based rules).

Shift-copy and shift-paste will copy and paste your style from one layer to another.

In layer properties dialog, you have a Style drop down button, that you can use to save and load styles. I would recommend to save styles to the database (either sqlite or postgresql). If you do so, a new layer_styles table will be created.

For a new layer, you just need to load the already saved style in the database. You can copy the table betwen you databases or use QGIS to read from one database and store it on another.

This is specially useful if you have multiple users and if you want to send the data and the style to another user.

2
  • So basically for changing the map content, I would use the same database, but replace the data in it. Is that correct? And if i want to create a new project with the same styles, I have to store them in my working database, open the working database from the new project and copy the styles over to a new working database?
    – T. Watzl
    Commented Sep 2, 2018 at 18:57
  • Do a few trials. It should be easy to copy styles between layers and databases. But if you find it difficult, let us know.
    – jgrocha
    Commented Sep 3, 2018 at 8:44
1

Ok. After trying out the things recommended by @jgrocha and @AndreJ I have found two possible ways to do what I wanted, which is to style map data and exchange the style between different maps.

For both ways I would recommend to not create layers directly from the map database, but create a new database through the QGIS datasource browser. Then connect to the map database and copy over the data to the working database. This way the data in the working database can later be replaced to show different map contents with the same style.

For styling there are the following possibilities:

1. Create a separate feature for each layer and style it

It is possible, although I do not recommend it, since it is very tedious. Basically for each feature create a new layer, add a filter to it, style it the way you want it to be.

To exchange the style, save it in the working database, duplicate it and replace the data in the new instance.

2. Create one layer for lines, multilinestrings, polygons, etc. and style with rules

This is very effective, also the rules can be created far quicker than the multiple layers for each feature. To change to rule rendering open the properties of a layer and change at the top to 'rule-based'.

Once styling is done the style can either be exported to the working database and copied as described before, or exported as a qml file and easily loaded into other projects.

Save and Load of styles is done at the bottom of the properties dialog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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