Getting the layer styles out of a *.QGS without having the layers itselves












1















Is it possible, to restore the layer-styles from a *.QGS project file?



I have unhandled layers in my project. As I'm starting the project, QGIS is asking me for the source of the layers but I don't have them anymore. So I ignore it and the project will be - of course - loaded without any layers and without their styles. But I just need the styles - how do I get to them as style file?










share|improve this question



























    1















    Is it possible, to restore the layer-styles from a *.QGS project file?



    I have unhandled layers in my project. As I'm starting the project, QGIS is asking me for the source of the layers but I don't have them anymore. So I ignore it and the project will be - of course - loaded without any layers and without their styles. But I just need the styles - how do I get to them as style file?










    share|improve this question

























      1












      1








      1








      Is it possible, to restore the layer-styles from a *.QGS project file?



      I have unhandled layers in my project. As I'm starting the project, QGIS is asking me for the source of the layers but I don't have them anymore. So I ignore it and the project will be - of course - loaded without any layers and without their styles. But I just need the styles - how do I get to them as style file?










      share|improve this question














      Is it possible, to restore the layer-styles from a *.QGS project file?



      I have unhandled layers in my project. As I'm starting the project, QGIS is asking me for the source of the layers but I don't have them anymore. So I ignore it and the project will be - of course - loaded without any layers and without their styles. But I just need the styles - how do I get to them as style file?







      qgis layers style qgs






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 30 '18 at 8:31









      MAPMAP

      2,43523568




      2,43523568






















          3 Answers
          3






          active

          oldest

          votes


















          5














          If you open a .QGS with a text editor you will see some XML code. Your project layers are inside <projectlayers> ... </projectlayers> tags and each layer is in <maplayer>...</maplayer> tags. Search through the maplayer tags until you find the broken one that has a missing source. You can search for the layername tag to help you.



          Once you find that, search for the next <renderer-v2> tag. This is the style definition for that layer. Copy all the text including the open <renderer-v2> and closing </renderer-v2> tag. All that text is a valid QGIS style definition which we can put into a QML file.



          Put that text into a new file with a header with a DOCTYPE and <qgis ... tag so the start looks like this:




          <!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
          <qgis simplifyDrawingHints="1" simplifyLocal="1" maxScale="0" simplifyMaxScale="1" styleCategories="AllStyleCategories" version="3.4.2-Madeira" simplifyDrawingTol="1" labelsEnabled="0" minScale="1e+8" readOnly="0" hasScaleBasedVisibilityFlag="0" simplifyAlgorithm="0">
          <renderer-v2 type="singleSymbol" enableorderby="0" symbollevels="0" forceraster="0">
          <symbols>
          <symbol name="0" type="marker" alpha="1" clip_to_extent="1">
          [etc]



          and it ends with </renderer-v2>. Save this file as rescue.qml.



          Then in QGIS from the properties dialog of an existing layer you can load this QML file and use it to style it. Note it has to be compatible - you'll struggle to apply a polygon style to a point layer, for example.



          I'm working with QGIS 3.4, and it saves .qgz files, which are zipped .qgs files. You can run your standard unzipping program on a .qgz to get a .qgs which you can edit to get the style info in the renderer-v2 tag.



          If you have a lot of these to do then a short Python program could be written to extract all the renderer info from a QGS and save it in separate QML files - it would not surprise me if something like this didn't already exist or was part of a QGIS plugin...






          share|improve this answer































            2














            I don't know how to extract styles but one thing you could try is "fixing" the links with the wrong data. The data just needs to match the original layers' geometry. Then save the styles as a QML file to import into new QGIS projects.



            Also I found that setting up shortcuts to copy and paste styles is so hand, I have mine set to ctrl+shift+c and crtl+shift+v.






            share|improve this answer































              0














              .qgs files are formatted in XML so you can open them in a text editor and copy them in another .qgs file.



              Look for <map-layer-style name=""> markup.






              share|improve this answer























                Your Answer








                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "79"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f304499%2fgetting-the-layer-styles-out-of-a-qgs-without-having-the-layers-itselves%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                5














                If you open a .QGS with a text editor you will see some XML code. Your project layers are inside <projectlayers> ... </projectlayers> tags and each layer is in <maplayer>...</maplayer> tags. Search through the maplayer tags until you find the broken one that has a missing source. You can search for the layername tag to help you.



                Once you find that, search for the next <renderer-v2> tag. This is the style definition for that layer. Copy all the text including the open <renderer-v2> and closing </renderer-v2> tag. All that text is a valid QGIS style definition which we can put into a QML file.



                Put that text into a new file with a header with a DOCTYPE and <qgis ... tag so the start looks like this:




                <!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
                <qgis simplifyDrawingHints="1" simplifyLocal="1" maxScale="0" simplifyMaxScale="1" styleCategories="AllStyleCategories" version="3.4.2-Madeira" simplifyDrawingTol="1" labelsEnabled="0" minScale="1e+8" readOnly="0" hasScaleBasedVisibilityFlag="0" simplifyAlgorithm="0">
                <renderer-v2 type="singleSymbol" enableorderby="0" symbollevels="0" forceraster="0">
                <symbols>
                <symbol name="0" type="marker" alpha="1" clip_to_extent="1">
                [etc]



                and it ends with </renderer-v2>. Save this file as rescue.qml.



                Then in QGIS from the properties dialog of an existing layer you can load this QML file and use it to style it. Note it has to be compatible - you'll struggle to apply a polygon style to a point layer, for example.



                I'm working with QGIS 3.4, and it saves .qgz files, which are zipped .qgs files. You can run your standard unzipping program on a .qgz to get a .qgs which you can edit to get the style info in the renderer-v2 tag.



                If you have a lot of these to do then a short Python program could be written to extract all the renderer info from a QGS and save it in separate QML files - it would not surprise me if something like this didn't already exist or was part of a QGIS plugin...






                share|improve this answer




























                  5














                  If you open a .QGS with a text editor you will see some XML code. Your project layers are inside <projectlayers> ... </projectlayers> tags and each layer is in <maplayer>...</maplayer> tags. Search through the maplayer tags until you find the broken one that has a missing source. You can search for the layername tag to help you.



                  Once you find that, search for the next <renderer-v2> tag. This is the style definition for that layer. Copy all the text including the open <renderer-v2> and closing </renderer-v2> tag. All that text is a valid QGIS style definition which we can put into a QML file.



                  Put that text into a new file with a header with a DOCTYPE and <qgis ... tag so the start looks like this:




                  <!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
                  <qgis simplifyDrawingHints="1" simplifyLocal="1" maxScale="0" simplifyMaxScale="1" styleCategories="AllStyleCategories" version="3.4.2-Madeira" simplifyDrawingTol="1" labelsEnabled="0" minScale="1e+8" readOnly="0" hasScaleBasedVisibilityFlag="0" simplifyAlgorithm="0">
                  <renderer-v2 type="singleSymbol" enableorderby="0" symbollevels="0" forceraster="0">
                  <symbols>
                  <symbol name="0" type="marker" alpha="1" clip_to_extent="1">
                  [etc]



                  and it ends with </renderer-v2>. Save this file as rescue.qml.



                  Then in QGIS from the properties dialog of an existing layer you can load this QML file and use it to style it. Note it has to be compatible - you'll struggle to apply a polygon style to a point layer, for example.



                  I'm working with QGIS 3.4, and it saves .qgz files, which are zipped .qgs files. You can run your standard unzipping program on a .qgz to get a .qgs which you can edit to get the style info in the renderer-v2 tag.



                  If you have a lot of these to do then a short Python program could be written to extract all the renderer info from a QGS and save it in separate QML files - it would not surprise me if something like this didn't already exist or was part of a QGIS plugin...






                  share|improve this answer


























                    5












                    5








                    5







                    If you open a .QGS with a text editor you will see some XML code. Your project layers are inside <projectlayers> ... </projectlayers> tags and each layer is in <maplayer>...</maplayer> tags. Search through the maplayer tags until you find the broken one that has a missing source. You can search for the layername tag to help you.



                    Once you find that, search for the next <renderer-v2> tag. This is the style definition for that layer. Copy all the text including the open <renderer-v2> and closing </renderer-v2> tag. All that text is a valid QGIS style definition which we can put into a QML file.



                    Put that text into a new file with a header with a DOCTYPE and <qgis ... tag so the start looks like this:




                    <!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
                    <qgis simplifyDrawingHints="1" simplifyLocal="1" maxScale="0" simplifyMaxScale="1" styleCategories="AllStyleCategories" version="3.4.2-Madeira" simplifyDrawingTol="1" labelsEnabled="0" minScale="1e+8" readOnly="0" hasScaleBasedVisibilityFlag="0" simplifyAlgorithm="0">
                    <renderer-v2 type="singleSymbol" enableorderby="0" symbollevels="0" forceraster="0">
                    <symbols>
                    <symbol name="0" type="marker" alpha="1" clip_to_extent="1">
                    [etc]



                    and it ends with </renderer-v2>. Save this file as rescue.qml.



                    Then in QGIS from the properties dialog of an existing layer you can load this QML file and use it to style it. Note it has to be compatible - you'll struggle to apply a polygon style to a point layer, for example.



                    I'm working with QGIS 3.4, and it saves .qgz files, which are zipped .qgs files. You can run your standard unzipping program on a .qgz to get a .qgs which you can edit to get the style info in the renderer-v2 tag.



                    If you have a lot of these to do then a short Python program could be written to extract all the renderer info from a QGS and save it in separate QML files - it would not surprise me if something like this didn't already exist or was part of a QGIS plugin...






                    share|improve this answer













                    If you open a .QGS with a text editor you will see some XML code. Your project layers are inside <projectlayers> ... </projectlayers> tags and each layer is in <maplayer>...</maplayer> tags. Search through the maplayer tags until you find the broken one that has a missing source. You can search for the layername tag to help you.



                    Once you find that, search for the next <renderer-v2> tag. This is the style definition for that layer. Copy all the text including the open <renderer-v2> and closing </renderer-v2> tag. All that text is a valid QGIS style definition which we can put into a QML file.



                    Put that text into a new file with a header with a DOCTYPE and <qgis ... tag so the start looks like this:




                    <!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
                    <qgis simplifyDrawingHints="1" simplifyLocal="1" maxScale="0" simplifyMaxScale="1" styleCategories="AllStyleCategories" version="3.4.2-Madeira" simplifyDrawingTol="1" labelsEnabled="0" minScale="1e+8" readOnly="0" hasScaleBasedVisibilityFlag="0" simplifyAlgorithm="0">
                    <renderer-v2 type="singleSymbol" enableorderby="0" symbollevels="0" forceraster="0">
                    <symbols>
                    <symbol name="0" type="marker" alpha="1" clip_to_extent="1">
                    [etc]



                    and it ends with </renderer-v2>. Save this file as rescue.qml.



                    Then in QGIS from the properties dialog of an existing layer you can load this QML file and use it to style it. Note it has to be compatible - you'll struggle to apply a polygon style to a point layer, for example.



                    I'm working with QGIS 3.4, and it saves .qgz files, which are zipped .qgs files. You can run your standard unzipping program on a .qgz to get a .qgs which you can edit to get the style info in the renderer-v2 tag.



                    If you have a lot of these to do then a short Python program could be written to extract all the renderer info from a QGS and save it in separate QML files - it would not surprise me if something like this didn't already exist or was part of a QGIS plugin...







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 30 '18 at 9:18









                    SpacedmanSpacedman

                    22.9k23449




                    22.9k23449

























                        2














                        I don't know how to extract styles but one thing you could try is "fixing" the links with the wrong data. The data just needs to match the original layers' geometry. Then save the styles as a QML file to import into new QGIS projects.



                        Also I found that setting up shortcuts to copy and paste styles is so hand, I have mine set to ctrl+shift+c and crtl+shift+v.






                        share|improve this answer




























                          2














                          I don't know how to extract styles but one thing you could try is "fixing" the links with the wrong data. The data just needs to match the original layers' geometry. Then save the styles as a QML file to import into new QGIS projects.



                          Also I found that setting up shortcuts to copy and paste styles is so hand, I have mine set to ctrl+shift+c and crtl+shift+v.






                          share|improve this answer


























                            2












                            2








                            2







                            I don't know how to extract styles but one thing you could try is "fixing" the links with the wrong data. The data just needs to match the original layers' geometry. Then save the styles as a QML file to import into new QGIS projects.



                            Also I found that setting up shortcuts to copy and paste styles is so hand, I have mine set to ctrl+shift+c and crtl+shift+v.






                            share|improve this answer













                            I don't know how to extract styles but one thing you could try is "fixing" the links with the wrong data. The data just needs to match the original layers' geometry. Then save the styles as a QML file to import into new QGIS projects.



                            Also I found that setting up shortcuts to copy and paste styles is so hand, I have mine set to ctrl+shift+c and crtl+shift+v.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 30 '18 at 8:54









                            TeddyTedTedTeddyTedTed

                            56319




                            56319























                                0














                                .qgs files are formatted in XML so you can open them in a text editor and copy them in another .qgs file.



                                Look for <map-layer-style name=""> markup.






                                share|improve this answer




























                                  0














                                  .qgs files are formatted in XML so you can open them in a text editor and copy them in another .qgs file.



                                  Look for <map-layer-style name=""> markup.






                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    .qgs files are formatted in XML so you can open them in a text editor and copy them in another .qgs file.



                                    Look for <map-layer-style name=""> markup.






                                    share|improve this answer













                                    .qgs files are formatted in XML so you can open them in a text editor and copy them in another .qgs file.



                                    Look for <map-layer-style name=""> markup.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 30 '18 at 9:00









                                    Nicolas BoisteaultNicolas Boisteault

                                    752524




                                    752524






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f304499%2fgetting-the-layer-styles-out-of-a-qgs-without-having-the-layers-itselves%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Plaza Victoria

                                        Puebla de Zaragoza

                                        Musa