5

Is possible in Processing Modeler use "Export" - "Save features as"?

Model schema:

enter image description here

Generated code:

from qgis.core import QgsProcessing
from qgis.core import QgsProcessingAlgorithm
from qgis.core import QgsProcessingMultiStepFeedback
from qgis.core import QgsProcessingParameterVectorLayer
from qgis.core import QgsProcessingParameterFeatureSink
import processing


class MyExampleModel(QgsProcessingAlgorithm):

    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterVectorLayer('inputlayer', 'input layer', types=[QgsProcessing.TypeVectorPoint], defaultValue=None))
        self.addParameter(QgsProcessingParameterFeatureSink('ResultCsvLayer', 'result CSV layer', type=QgsProcessing.TypeVectorAnyGeometry, createByDefault=True, defaultValue=None))

    def processAlgorithm(self, parameters, context, model_feedback):
        # Use a multi-step feedback, so that individual child algorithm progress reports are adjusted for the
        # overall progress through the model
        feedback = QgsProcessingMultiStepFeedback(1, model_feedback)
        results = {}
        outputs = {}

        # Add field to attributes table
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'example_field',
            'FIELD_PRECISION': 0,
            'FIELD_TYPE': 0,
            'INPUT': parameters['inputlayer'],
            'OUTPUT': parameters['ResultCsvLayer']
        }
        outputs['AddFieldToAttributesTable'] = processing.run('qgis:addfieldtoattributestable', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
        results['ResultCsvLayer'] = outputs['AddFieldToAttributesTable']['OUTPUT']
        return results

    def name(self):
        return 'my example model'

    def displayName(self):
        return 'my example model'

    def group(self):
        return 'example group'

    def groupId(self):
        return ''

    def createInstance(self):
        return MyExampleModel()

Model exported format:

<!DOCTYPE model>
<Option type="Map">
  <Option type="Map" name="children">
    <Option type="Map" name="qgis:addfieldtoattributestable_1">
      <Option type="bool" value="true" name="active"/>
      <Option name="alg_config"/>
      <Option type="QString" value="qgis:addfieldtoattributestable" name="alg_id"/>
      <Option type="QString" value="Add field to attributes table" name="component_description"/>
      <Option type="double" value="443" name="component_pos_x"/>
      <Option type="double" value="506" name="component_pos_y"/>
      <Option name="dependencies"/>
      <Option type="QString" value="qgis:addfieldtoattributestable_1" name="id"/>
      <Option type="Map" name="outputs">
        <Option type="Map" name="result CSV layer">
          <Option type="QString" value="qgis:addfieldtoattributestable_1" name="child_id"/>
          <Option type="QString" value="result CSV layer" name="component_description"/>
          <Option type="double" value="448" name="component_pos_x"/>
          <Option type="double" value="585" name="component_pos_y"/>
          <Option type="invalid" name="default_value"/>
          <Option type="bool" value="false" name="mandatory"/>
          <Option type="QString" value="result CSV layer" name="name"/>
          <Option type="QString" value="OUTPUT" name="output_name"/>
        </Option>
      </Option>
      <Option type="bool" value="true" name="outputs_collapsed"/>
      <Option type="bool" value="true" name="parameters_collapsed"/>
      <Option type="Map" name="params">
        <Option type="List" name="FIELD_LENGTH">
          <Option type="Map">
            <Option type="int" value="2" name="source"/>
            <Option type="int" value="10" name="static_value"/>
          </Option>
        </Option>
        <Option type="List" name="FIELD_NAME">
          <Option type="Map">
            <Option type="int" value="2" name="source"/>
            <Option type="QString" value="example_field" name="static_value"/>
          </Option>
        </Option>
        <Option type="List" name="FIELD_PRECISION">
          <Option type="Map">
            <Option type="int" value="2" name="source"/>
            <Option type="int" value="0" name="static_value"/>
          </Option>
        </Option>
        <Option type="List" name="FIELD_TYPE">
          <Option type="Map">
            <Option type="int" value="2" name="source"/>
            <Option type="int" value="0" name="static_value"/>
          </Option>
        </Option>
        <Option type="List" name="INPUT">
          <Option type="Map">
            <Option type="QString" value="inputlayer" name="parameter_name"/>
            <Option type="int" value="0" name="source"/>
          </Option>
        </Option>
      </Option>
    </Option>
  </Option>
  <Option name="help"/>
  <Option name="modelVariables"/>
  <Option type="QString" value="example group" name="model_group"/>
  <Option type="QString" value="my example model" name="model_name"/>
  <Option type="Map" name="parameterDefinitions">
    <Option type="Map" name="inputlayer">
      <Option type="List" name="data_types">
        <Option type="int" value="0"/>
      </Option>
      <Option type="invalid" name="default"/>
      <Option type="QString" value="input layer" name="description"/>
      <Option type="int" value="0" name="flags"/>
      <Option name="metadata"/>
      <Option type="QString" value="inputlayer" name="name"/>
      <Option type="QString" value="vector" name="parameter_type"/>
    </Option>
    <Option type="Map" name="qgis:addfieldtoattributestable_1:result CSV layer">
      <Option type="bool" value="true" name="create_by_default"/>
      <Option type="int" value="-1" name="data_type"/>
      <Option type="invalid" name="default"/>
      <Option type="QString" value="result CSV layer" name="description"/>
      <Option type="int" value="0" name="flags"/>
      <Option name="metadata"/>
      <Option type="QString" value="qgis:addfieldtoattributestable_1:result CSV layer" name="name"/>
      <Option type="QString" value="sink" name="parameter_type"/>
      <Option type="bool" value="true" name="supports_non_file_outputs"/>
    </Option>
  </Option>
  <Option type="Map" name="parameters">
    <Option type="Map" name="inputlayer">
      <Option type="QString" value="inputlayer" name="component_description"/>
      <Option type="double" value="443" name="component_pos_x"/>
      <Option type="double" value="418" name="component_pos_y"/>
      <Option type="QString" value="inputlayer" name="name"/>
    </Option>
  </Option>
</Option>

Info about QGIS:

enter image description here Summary:

I want to specify result CSV layer as CSV file with semicolon delimiter in model without user typing settings in file export system menu.

5
  • Everything you set as a final outcome will ask you for a location to be saved at once you run the model. Does this answer your question?
    – Erik
    Sep 21, 2020 at 10:53
  • I want save CSV file with specific "layerOptions" without typing export setting
    – Wenceslauw
    Sep 21, 2020 at 11:07
  • 1
    Then please edit your question accordingly and add, what you tried so far.
    – Erik
    Sep 21, 2020 at 11:16
  • I am added some details about this questions, is sufficient?
    – Wenceslauw
    Sep 22, 2020 at 5:46
  • 1
    Maybe this helps: gis.stackexchange.com/questions/337693/…
    – MrXsquared
    Sep 22, 2020 at 18:30

0

Your Answer

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

Browse other questions tagged or ask your own question.