QGIS – Transfer Layer Styles Table

Marketing
Marketing
  • Updated

by David Crowther

QGIS Lay Sty 1.pngQuestion:

How can you transfer the Layer Styles table from one Database to another Database?

Answer:

The simplest way to copy the Layer Styles table from one database to another is to use QGIS. Follow the steps below and you can transfer your table too!

In the example below we will transfer an existing Layer Styles table from a Postgres database to a new SQL database.

1 – In QGIS connect to the current database that contains the current Layer Styles table.

Use QGIS and connect to your current database but ensure that in the connection settings you tick the option for Also list tables with no geometry.

QGIS Lay Sty 2.jpg

When you connect via the DB Manager tool, you can now see the Layer Styles table in the list.

QGIS Lay Sty 3.jpg

Note – if you don’t see the Layer Styles table ensure that you have saved at least one style into your current database, as this will then auto create the Layer Styles table.

Once you have dragged it into QGIS and the table is open it will be listed in your Layer Panel.

QGIS Lay Sty 4.jpg

2– Drag and drop the Layer Styles table into your new Database.

In QGIS select the Layer Styles table and drag it into your new Database. In this example we are going to import it into a SQL Database.

QGIS Lay Sty 5.jpg

When tyring to import the Layer Styles table into a SQL database, you may get an error message saying the useAsdefault field cannot be imported.

So, by saving the Postgres Table as a temporary GIS file e.g. a GeoPackage file, you can drop the useAsdefault column.

QGIS Lay Sty 6.jpg

This time if you drag and drop the GIS file version of the table, it will successfully be imported into your SQL database.

QGIS Lay Sty 7.jpg

Once it has been uploaded into the database, we can select the table to view the records.

QGIS Lay Sty 8.jpg

3– Update the Layer Styles table.

Now that the Layer Styles table has been imported into your new database, you will need to edit some of the values to reference the new database. For example:

  • f_table_catalog – change to the new database name
  • f_table_schema – change to dbo for a SQL database

QGIS Lay Sty 9.jpg

Finally, we will need to update the Design of the table now that it is in the new SQL database:

  • to add back in the UseAsdefault field
  • and also remove the Type field as SQL does not need this

QGIS Lay Sty 10.jpg

4 – Open a Table from the new Database and use the Saved Style.

Now if you open a table from the new (SQL) database, and it has a valid reference in the Layer Styles table, when it opens it will be auto styled!

QGIS Lay Sty 11.jpg

By transferring the Layer Styles table to your new Database, this means that you won’t need to recreate and save the individual Styles for each of your tables…. Hopefully saving you lots of time and effort!

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.