Returning a new vector layer with additional setup from a processing algorithm in QGIS 3 The...

Can this note be analyzed as a non-chord tone?

In the "Harry Potter and the Order of the Phoenix" video game, what potion is used to sabotage Umbridge's speakers?

How to use ReplaceAll on an expression that contains a rule

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Which one is the true statement?

Calculate the Mean mean of two numbers

Do scriptures give a method to recognize a truly self-realized person/jivanmukta?

0-rank tensor vs vector in 1D

TikZ: How to fill area with a special pattern?

Players Circumventing the limitations of Wish

Is it correct to say moon starry nights?

Can you teleport closer to a creature you are Frightened of?

Pulling the principal components out of a DimensionReducerFunction?

(How) Could a medieval fantasy world survive a magic-induced "nuclear winter"?

Yu-Gi-Oh cards in Python 3

What was Carter Burke's job for "the company" in Aliens?

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

Is there a reasonable and studied concept of reduction between regular languages?

Touchpad not working on Debian 9

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Expectation in a stochastic differential equation

IC has pull-down resistors on SMBus lines?

What connection does MS Office have to Netscape Navigator?

Aggressive Under-Indexing and no data for missing index



Returning a new vector layer with additional setup from a processing algorithm in QGIS 3



The Next CEO of Stack OverflowUsing in-memory vector layer with QGIS processing / SEXTANTEProcessing algorithm fails from Python scriptQGIS Processing Input CRS from Input LayerQGIS Modeler: Where is output from algorithm 'Set style for vector layer'?QGIS batch processing does not allow the output from an algorithm as the input to a subsequent algorithmGetting the output layer using any processing.run*(…) method?Piping custom processing algorithm output into another in QGIS?Let QGIS 3.0 Processing algorithm output a VectorLayer loaded via the delimited text providerOutput layer from PyQGIS 3 processing script is emptyUnable to load output layer from Python algorithm in QGIS 3












0















First, allow me to apologize for the excessively long title on this post. I'll (attempt to) clarify what I'm asking about - it'll be a bit complex, so bear with me.



In general, I am asking about the usage of processing parameters in Python with QGIS 3.



I am working on a processing script in QGIS 3, which does the following:




  • Take a few inputs

  • Run a native algorithm on these inputs, saving the resulting new layer in memory

  • Set up the symbology for the layer (specifically, setting the renderer via layer.setRenderer(renderer_instance))

  • Return the layer, retaining its symbology, as the primary algorithm output


The key here is that I want to return a layer after setting up its symbology. This is problematic because I'd like to use the common input parameter QgsProcessingParameterFeatureSink, since this lets the user choose how to output the results (memory layer, temporary file, saved in a format of their choice, etc).



However, as far as I can tell, the ...ParameterFeatureSink parameter is primarily used with QgsProcessingAlgorithm's parameterAsFeatureSink method, which returns an interface to a new layer, which does not allow setting up symbology. Also, it appears that this layer is what the algorithm expects to be returned at the end, and that returning another layer (like the one described in the list above) in its place causes an error.



My question is this: how do I utilize the strengths of QgsProcessingParameterFeatureSink, while still being able to return a layer with its symbology set up as described?



The ideal solution here would be to use another of the parameterAs methods to get a place or name for the layer I'll eventually return. I could feed that name to the internal algorithm as its OUTPUT parameter, making it return a layer that my algorithm could subsequently return without generating an error.



I realize that my description here may well be inadequate or insufficient. If so, please comment, and I'll do my best to clarify.









share



























    0















    First, allow me to apologize for the excessively long title on this post. I'll (attempt to) clarify what I'm asking about - it'll be a bit complex, so bear with me.



    In general, I am asking about the usage of processing parameters in Python with QGIS 3.



    I am working on a processing script in QGIS 3, which does the following:




    • Take a few inputs

    • Run a native algorithm on these inputs, saving the resulting new layer in memory

    • Set up the symbology for the layer (specifically, setting the renderer via layer.setRenderer(renderer_instance))

    • Return the layer, retaining its symbology, as the primary algorithm output


    The key here is that I want to return a layer after setting up its symbology. This is problematic because I'd like to use the common input parameter QgsProcessingParameterFeatureSink, since this lets the user choose how to output the results (memory layer, temporary file, saved in a format of their choice, etc).



    However, as far as I can tell, the ...ParameterFeatureSink parameter is primarily used with QgsProcessingAlgorithm's parameterAsFeatureSink method, which returns an interface to a new layer, which does not allow setting up symbology. Also, it appears that this layer is what the algorithm expects to be returned at the end, and that returning another layer (like the one described in the list above) in its place causes an error.



    My question is this: how do I utilize the strengths of QgsProcessingParameterFeatureSink, while still being able to return a layer with its symbology set up as described?



    The ideal solution here would be to use another of the parameterAs methods to get a place or name for the layer I'll eventually return. I could feed that name to the internal algorithm as its OUTPUT parameter, making it return a layer that my algorithm could subsequently return without generating an error.



    I realize that my description here may well be inadequate or insufficient. If so, please comment, and I'll do my best to clarify.









    share

























      0












      0








      0








      First, allow me to apologize for the excessively long title on this post. I'll (attempt to) clarify what I'm asking about - it'll be a bit complex, so bear with me.



      In general, I am asking about the usage of processing parameters in Python with QGIS 3.



      I am working on a processing script in QGIS 3, which does the following:




      • Take a few inputs

      • Run a native algorithm on these inputs, saving the resulting new layer in memory

      • Set up the symbology for the layer (specifically, setting the renderer via layer.setRenderer(renderer_instance))

      • Return the layer, retaining its symbology, as the primary algorithm output


      The key here is that I want to return a layer after setting up its symbology. This is problematic because I'd like to use the common input parameter QgsProcessingParameterFeatureSink, since this lets the user choose how to output the results (memory layer, temporary file, saved in a format of their choice, etc).



      However, as far as I can tell, the ...ParameterFeatureSink parameter is primarily used with QgsProcessingAlgorithm's parameterAsFeatureSink method, which returns an interface to a new layer, which does not allow setting up symbology. Also, it appears that this layer is what the algorithm expects to be returned at the end, and that returning another layer (like the one described in the list above) in its place causes an error.



      My question is this: how do I utilize the strengths of QgsProcessingParameterFeatureSink, while still being able to return a layer with its symbology set up as described?



      The ideal solution here would be to use another of the parameterAs methods to get a place or name for the layer I'll eventually return. I could feed that name to the internal algorithm as its OUTPUT parameter, making it return a layer that my algorithm could subsequently return without generating an error.



      I realize that my description here may well be inadequate or insufficient. If so, please comment, and I'll do my best to clarify.









      share














      First, allow me to apologize for the excessively long title on this post. I'll (attempt to) clarify what I'm asking about - it'll be a bit complex, so bear with me.



      In general, I am asking about the usage of processing parameters in Python with QGIS 3.



      I am working on a processing script in QGIS 3, which does the following:




      • Take a few inputs

      • Run a native algorithm on these inputs, saving the resulting new layer in memory

      • Set up the symbology for the layer (specifically, setting the renderer via layer.setRenderer(renderer_instance))

      • Return the layer, retaining its symbology, as the primary algorithm output


      The key here is that I want to return a layer after setting up its symbology. This is problematic because I'd like to use the common input parameter QgsProcessingParameterFeatureSink, since this lets the user choose how to output the results (memory layer, temporary file, saved in a format of their choice, etc).



      However, as far as I can tell, the ...ParameterFeatureSink parameter is primarily used with QgsProcessingAlgorithm's parameterAsFeatureSink method, which returns an interface to a new layer, which does not allow setting up symbology. Also, it appears that this layer is what the algorithm expects to be returned at the end, and that returning another layer (like the one described in the list above) in its place causes an error.



      My question is this: how do I utilize the strengths of QgsProcessingParameterFeatureSink, while still being able to return a layer with its symbology set up as described?



      The ideal solution here would be to use another of the parameterAs methods to get a place or name for the layer I'll eventually return. I could feed that name to the internal algorithm as its OUTPUT parameter, making it return a layer that my algorithm could subsequently return without generating an error.



      I realize that my description here may well be inadequate or insufficient. If so, please comment, and I'll do my best to clarify.







      qgis python qgis-3 qgis-processing pyqgis-3





      share












      share










      share



      share










      asked 2 mins ago









      Luke RLuke R

      214




      214






















          0






          active

          oldest

          votes












          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%2f317294%2freturning-a-new-vector-layer-with-additional-setup-from-a-processing-algorithm-i%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f317294%2freturning-a-new-vector-layer-with-additional-setup-from-a-processing-algorithm-i%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

          Щит и меч (фильм) Содержание Названия серий | Сюжет |...

          Венесуэла на летних Олимпийских играх 2000 Содержание Состав...

          Meter-Bus Содержание Параметры шины | Стандартизация |...