<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"Trebuchet MS";
        panose-1:2 11 6 3 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Vorformatiert Zchn";
        margin:0cm;
        font-size:10.0pt;
        font-family:"Courier New";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.HTMLVorformatiertZchn
        {mso-style-name:"HTML Vorformatiert Zchn";
        mso-style-priority:99;
        mso-style-link:"HTML Vorformatiert";
        font-family:Consolas;
        mso-ligatures:none;
        mso-fareast-language:DE-CH;}
span.E-MailFormatvorlage21
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;
        mso-ligatures:standardcontextual;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1074163612;
        mso-list-template-ids:199234574;}
@list l1
        {mso-list-id:1216546938;
        mso-list-type:hybrid;
        mso-list-template-ids:-1606637138 134676495 134676505 134676507 134676495 134676505 134676507 134676495 134676505 134676507;}
@list l1:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l1:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l1:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l1:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=DE-CH link=blue vlink=purple style='word-wrap:break-word'><div class=WordSection1><p class=MsoNormal><span style='mso-fareast-language:EN-US'>Dear Etienne<o:p></o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'>The code is working! But I missed initial steps.<o:p></o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><ol style='margin-top:0cm' start=1 type=1><li class=MsoListParagraph style='margin-left:0cm;mso-list:l1 level1 lfo3'><span lang=FR-CH style='mso-fareast-language:EN-US'>You must have one or many vector layers inside QGIS.<o:p></o:p></span></li><li class=MsoListParagraph style='margin-left:0cm;mso-list:l1 level1 lfo3'><span style='mso-fareast-language:EN-US'>Upload these layers with drag and drop to the postgres DB.<o:p></o:p></span></li><li class=MsoListParagraph style='margin-left:0cm;mso-list:l1 level1 lfo3'><span style='mso-fareast-language:EN-US'>Dowload these layers from the postgres DB.<o:p></o:p></span></li><li class=MsoListParagraph style='margin-left:0cm;mso-list:l1 level1 lfo3'><span lang=FR-CH style='mso-fareast-language:EN-US'>Create styles or load styles from style files (*.qml) to the layers. For many style files there is a nice extention available « Layer Stayle Loader »<o:p></o:p></span></li><li class=MsoListParagraph style='margin-left:0cm;mso-list:l1 level1 lfo3'><span lang=FR-CH style='mso-fareast-language:EN-US'>Run the code below in the Python-Console. Take care the code still has the appopriate indents ! When you then load such a layer again from postgres DB then the style is loaded as well.<o:p></o:p></span></li></ol><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p> </o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span style='font-size:9.0pt;font-family:"Courier New";color:black'>mapGeometryType = {</span><span style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span style='font-size:9.0pt;font-family:"Courier New";color:black'>    </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#098658'>0</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>: </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"Point"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>,</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>    </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#098658'>1</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>: </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"Line"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>,</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>    </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#098658'>2</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>: </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"Polygon"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>,</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>    </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#098658'>3</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>: </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"UnknownGeometry"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>,</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>    </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#098658'>4</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>: </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"NullGeometry"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>,</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>}</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p> </o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>layers = QgsProject.instance().mapLayers()</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p> </o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#AF00DB'>for</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'> layer </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#AF00DB'>in</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'> layers.values():</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>    </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#AF00DB'>if</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'> layer.type() == QgsMapLayer.VectorLayer:</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>        </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#AF00DB'>if</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'> mapGeometryType[layer.geometryType()] != </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"NullGeometry"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>:</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>            layer.deleteStyleFromDatabase</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>            layer.saveStyleToDatabase(</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#001080'>name</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>=layer.name(),</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#001080'>description</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>=</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"Default style for </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:blue'>{}</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>.format(layer.name()), </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#001080'>useAsDefault</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>=</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:blue'>True</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>, </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#001080'>uiFileContent</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>=</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>""</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>)</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p><p class=MsoNormal><span lang=FR-CH style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span lang=FR-CH style='mso-fareast-language:EN-US'>P.S.<o:p></o:p></span></p><p class=MsoNormal><span lang=FR-CH style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='color:black;mso-fareast-language:EN-US'>I tested it with the beautiful dataset from the Swiss Topo, </span><span style='color:black'><a href="https://www.swisstopo.admin.ch/de/landeskarte-swiss-map-vector-10#Weiterf%C3%BChrende-Informationen-"><span lang=FR-CH>Swiss Map Vector 10</span></a></span><span lang=FR-CH style='color:black'>. </span><span style='color:black'>It’s free!</span><o:p></o:p></p><p class=MsoNormal style='line-height:12.0pt;background:white'><o:p> </o:p></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span style='color:black'>Many thanks to all of you!</span><o:p></o:p></p><p class=MsoNormal style='line-height:12.0pt;background:white'><o:p> </o:p></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span style='color:black'>Peter</span><span style='mso-fareast-language:EN-US'><o:p></o:p></span></p><p class=MsoNormal style='line-height:12.0pt;background:white'><span style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-US'><o:p> </o:p></span></p><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=DE>Von:</span></b><span lang=DE> Etienne Trimaille <etienne.trimaille@gmail.com> <br><b>Gesendet:</b> Dienstag, 8. April 2025 18:18<br><b>An:</b> peter.berger@bluewin.ch<br><b>Cc:</b> Jorge Gustavo Rocha <jgr@geomaster.pt>; qgis-user@lists.osgeo.org<br><b>Betreff:</b> Re: [Qgis-user] Storing and Retrieving Vector Layers with Styles to Postgres DB<o:p></o:p></span></p></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>The code from Jorge does the job for ALL layers in the current project, can you describe your issue Peter ?<o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal><span lang=FR-CH>Le mar. 8 avr. 2025 à 17:51, peter.berger--- via QGIS-User <</span><a href="mailto:qgis-user@lists.osgeo.org"><span lang=FR-CH>qgis-user@lists.osgeo.org</span></a><span lang=FR-CH>> a écrit :<o:p></o:p></span></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'><div><p class=MsoNormal><span lang=FR-CH>Hi Jorge<o:p></o:p></span></p><div><p class=MsoNormal><span lang=FR-CH><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=FR-CH>For me it is too minimal with this code alone. Would it be possible to describe how to run it when I have 65 Layers with styles and like to bring it all with styles to the postgres DB?<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=FR-CH><o:p> </o:p></span></p></div><div><p class=MsoNormal>Many thanks in advance.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Peter<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>Von meinem iPhone gesendet<o:p></o:p></p></div><div><p class=MsoNormal><br><br><o:p></o:p></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal style='margin-bottom:12.0pt'>Am 08.04.2025 um 10:59 schrieb Jorge Gustavo Rocha via QGIS-User <<a href="mailto:qgis-user@lists.osgeo.org" target="_blank">qgis-user@lists.osgeo.org</a>>:<o:p></o:p></p></blockquote></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal> <span lang=FR-CH><o:p></o:p></span></p><p><span lang=FR-CH>Hi,<o:p></o:p></span></p><p><span lang=FR-CH>This is the code I use (since some years ago...) to write styles from all layers to the database:<o:p></o:p></span></p><div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>mapGeometryType = {</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#098658'>0</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>: </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"Point"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>,</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#098658'>1</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>: </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"Line"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>,</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#098658'>2</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>: </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"Polygon"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>,</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#098658'>3</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>: </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"UnknownGeometry"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>,</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#098658'>4</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>: </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"NullGeometry"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>,</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>}</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>layers = QgsProject.instance().mapLayers()</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#AF00DB'>for</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'> layer </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#AF00DB'>in</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'> layers.values():</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#AF00DB'>if</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'> layer.type() == QgsMapLayer.VectorLayer:</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#AF00DB'>if</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'> mapGeometryType[layer.geometryType()] != </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"NullGeometry"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>:</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>layer.deleteStyleFromDatabase</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div><div><p class=MsoNormal style='line-height:12.0pt;background:white'><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>layer.saveStyleToDatabase(</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#001080'>name</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>=</span><span style='color:black'><a href="http://layer.name" target="_blank"><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New"'>layer.name</span></a></span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>(),</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#001080'>description</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>=</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"Default style for </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:blue'>{}</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>"</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>.format(</span><span style='color:black'><a href="http://layer.name" target="_blank"><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New"'>layer.name</span></a></span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>()), </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#001080'>useAsDefault</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>=</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:blue'>True</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>, </span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#001080'>uiFileContent</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>=</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#A31515'>""</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:black'>)</span><span lang=FR-CH style='font-size:9.0pt;font-family:"Courier New";color:#3B3B3B'><o:p></o:p></span></p></div></div><div><p class=MsoNormal>Since we are writing all with the flag "default style" there is no need to load them when opening the project.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span lang=FR-CH>Regards,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=FR-CH><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=FR-CH>Jorge Gustavo<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=FR-CH><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=FR-CH>On 07/04/25 19:11, Ludwig Kniprath via QGIS-User wrote:<o:p></o:p></span></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p><span lang=FR-CH>Hello Peter,<o:p></o:p></span></p><p><span lang=FR-CH>everything that users do in QGis can be done by Python scripts, including your steps listed below. <o:p></o:p></span></p><p><span lang=FR-CH>There are some difficulties for the desired "one step" solution, f. e. the name of the file-based layer must be converted in a valid and unique postgis table-name, the fields of the file-based layer must be stored with valid postgis field-types and -names and so on...<o:p></o:p></span></p><p><span lang=FR-CH>Taking into account all special features, exceptions and necessary settings, this results in a rather complex program, the implementation of which may be more complex than the manual implementation in QGis...<o:p></o:p></span></p><p>Just my two cents...<o:p></o:p></p><p>Ludwig<o:p></o:p></p><p><o:p> </o:p></p><div><p class=MsoNormal>Am 07.04.25 um 08:45 schrieb peter.berger--- via QGIS-User:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>There are serveral steps necessary to store from QGIS a vector layer with his style in a postgres DB. For a big amout of layers this is impracticaI.<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'>Therfore I would do this in one step from QGIS. <span lang=FR-CH>Is this in any way possible?<o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=FR-CH> <o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span style='font-size:8.0pt;font-family:"Trebuchet MS",sans-serif'>Peter Berger</span></b><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:8.0pt;font-family:"Trebuchet MS",sans-serif'>Brunnwiesenstrasse 62</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:8.0pt;font-family:"Trebuchet MS",sans-serif'>8049 Zürich</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:8.0pt;font-family:"Trebuchet MS",sans-serif'>Schweiz</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:8.0pt;font-family:"Trebuchet MS",sans-serif'>mobile +41 79 301 71 54</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:8.0pt;font-family:"Trebuchet MS",sans-serif'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:8.0pt;font-family:"Trebuchet MS",sans-serif'>The several step procedure:</span><o:p></o:p></p><p><span style='font-family:Symbol'>·</span>  <strong><span style='font-family:"Calibri",sans-serif'>Load the layer</span></strong>: Import the layer from a vector file into QGIS.<o:p></o:p></p><p><span style='font-family:Symbol'>·</span>  <strong><span style='font-family:"Calibri",sans-serif'>Rename (if necessary)</span></strong>: Give the layer an appropriate name.<o:p></o:p></p><p><span style='font-family:Symbol'>·</span>  <strong><span style='font-family:"Calibri",sans-serif'>Transfer the layer to Postgres</span></strong>: Drag the layer into the PostgreSQL database. You will find it there with the specific name.<o:p></o:p></p><p><span style='font-family:Symbol'>·</span>  <strong><span style='font-family:"Calibri",sans-serif'>Load the layer from Postgres</span></strong>: Import it back from the PostgreSQL database into QGIS.<o:p></o:p></p><p><span style='font-family:Symbol'>·</span>  <strong><span style='font-family:"Calibri",sans-serif'>Assign the style</span></strong>: Copy the style from the original layer and assign it to the Postgres layer loaded in QGIS.<o:p></o:p></p><p><span style='font-family:Symbol'>·</span>  <strong><span style='font-family:"Calibri",sans-serif'>Export the style</span></strong>: Export the style of the Postgres layer. You will now find an option to save the style with the exact name of the layer in the PostgreSQL database.<o:p></o:p></p><p><span style='font-family:Symbol'>·</span>  <strong><span style='font-family:"Calibri",sans-serif'>Delete old layers and reload</span></strong>: Delete all associated layers and reload the layer from the PostgreSQL database.<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:8.0pt;font-family:"Trebuchet MS",sans-serif'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p><pre>_______________________________________________<o:p></o:p></pre><pre>QGIS-User mailing list<o:p></o:p></pre><pre><a href="mailto:QGIS-User@lists.osgeo.org" target="_blank">QGIS-User@lists.osgeo.org</a><o:p></o:p></pre><pre>List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><o:p></o:p></pre><pre>Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><o:p></o:p></pre></blockquote><p class=MsoNormal><o:p> </o:p></p><pre><span lang=FR-CH>_______________________________________________<o:p></o:p></span></pre><pre><span lang=FR-CH>QGIS-User mailing list<o:p></o:p></span></pre><pre><a href="mailto:QGIS-User@lists.osgeo.org" target="_blank"><span lang=FR-CH>QGIS-User@lists.osgeo.org</span></a><span lang=FR-CH><o:p></o:p></span></pre><pre>List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><o:p></o:p></pre><pre>Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-user</a><o:p></o:p></pre></blockquote><div><p class=MsoNormal>-- <o:p></o:p></p><div><p class=MsoNormal><b><span style='font-size:18.0pt'>Geomaster, LDA</span> </b><o:p></o:p></p><div><p class=MsoNormal><b><span lang=FR-CH style='font-size:7.5pt;color:#999999'>VENHA DESCOBRIR O CAMINHO DO OPEN SOURCE CONNOSC</span></b><b><span lang=FR-CH> </span></b><span lang=FR-CH><o:p></o:p></span></p><table class=MsoNormalTable border=0 cellspacing=1 cellpadding=0 width=450 style='width:337.5pt'><tr style='height:25.0pt'><td width=150 valign=top style='width:112.5pt;padding:1.0pt 1.0pt 1.0pt 1.0pt;height:25.0pt'><p class=MsoNormal><span lang=FR-CH style='font-size:7.5pt;mso-fareast-language:EN-US'> </span><span lang=FR-CH style='font-size:10.0pt;mso-fareast-language:EN-US'><br>Rua Afonso Palmeira, 31, 7 D<br>4715-278 Braga<br>VAT/NIF 510 906 109<br>Phone   +351 253 257 173<br>Site </span><span style='mso-fareast-language:EN-US'><a href="http://geomaster.pt" target="_blank"><span lang=FR-CH style='font-size:10.0pt'>geomaster.pt</span></a></span><span lang=FR-CH style='font-size:10.0pt;mso-fareast-language:EN-US'><br>GPS 41.54627, -8.40432 </span><span lang=FR-CH style='mso-fareast-language:EN-US'><o:p></o:p></span></p><div><p class=MsoNormal><span style='mso-fareast-language:EN-US'><cropped-geomaster300x300-1.png><o:p></o:p></span></p></div></td><td width=25 valign=top style='width:18.75pt;padding:1.0pt 1.0pt 1.0pt 1.0pt;height:25.0pt'><div class=MsoNormal align=right style='text-align:right'><span style='mso-fareast-language:EN-US'><hr size=30 width=6 style='width:4.7pt' align=right></span></div></td><td width=150 nowrap valign=top style='width:112.5pt;padding:1.0pt 1.0pt 1.0pt 1.0pt;height:25.0pt'><p class=MsoNormal><span lang=FR-CH style='font-size:7.5pt;mso-fareast-language:EN-US'> </span><span lang=FR-CH style='font-size:10.0pt;mso-fareast-language:EN-US'><br>Jorge Gustavo Rocha <br></span><span lang=FR-CH style='font-size:7.5pt;color:#999999;mso-fareast-language:EN-US'>CTO<br><br></span><span lang=FR-CH style='font-size:10.0pt;mso-fareast-language:EN-US'>Mobile   +351 910 333 888<br>Email    </span><span style='mso-fareast-language:EN-US'><a href="mailto:jgr@geomaster.pt" target="_blank"><span lang=FR-CH style='font-size:10.0pt'>jgr@geomaster.pt</span></a></span><span style='mso-fareast-language:EN-US'> <span lang=FR-CH><o:p></o:p></span></span></p></td></tr></table></div></div></div><p class=MsoNormal><span lang=FR-CH>_______________________________________________<br>QGIS-User mailing list<br></span><a href="mailto:QGIS-User@lists.osgeo.org" target="_blank"><span lang=FR-CH>QGIS-User@lists.osgeo.org</span></a><span lang=FR-CH><br>List info: </span><a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank"><span lang=FR-CH>https://lists.osgeo.org/mailman/listinfo/qgis-user</span></a><span lang=FR-CH><br>Unsubscribe: </span><a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank"><span lang=FR-CH>https://lists.osgeo.org/mailman/listinfo/qgis-user</span></a><span lang=FR-CH><o:p></o:p></span></p></div></blockquote></div></div><p class=MsoNormal><span lang=FR-CH>_______________________________________________<br>QGIS-User mailing list<br></span><a href="mailto:QGIS-User@lists.osgeo.org" target="_blank"><span lang=FR-CH>QGIS-User@lists.osgeo.org</span></a><span lang=FR-CH><br>List info: </span><a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank"><span lang=FR-CH>https://lists.osgeo.org/mailman/listinfo/qgis-user</span></a><span lang=FR-CH><br>Unsubscribe: </span><a href="https://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank"><span lang=FR-CH>https://lists.osgeo.org/mailman/listinfo/qgis-user</span></a><span lang=FR-CH><o:p></o:p></span></p></blockquote></div></div></body></html>