2

I'm updating a plugin for QGIS and struggling to see how to set the default file type when using the QgsProcessingParameterVectorDestination parameter. See code below.

    self.addParameter(
        QgsProcessingParameterVectorDestination(
            "OUTPUT_POND_OUTLINES",
            "Output Pond Outlines Vector",                
            optional=False,                
        )
    )

Based on the docs i can not see how to pass *.shp as the default format like you do with a QgsProcessingParameterFileDestination

    self.addParameter(
        QgsProcessingParameterFileDestination(
            "OUTPUT_POND_OUTLINES",
            "Output Pond Outlines Vector",                
            optional=False,
            fileFilter="ESRI Shapefile (*.shp)"                              
        )
    )

P.S. I prefer using QgsProcessingParameterVectorDestination as it handles the temporary output and adding to the current project by default. Where as QgsProcessingParameterFileDestination doesn't seem to have this capability.

2
  • 1
    you should really migrate away from shapefiles, they are a bad way to store and transfer data Commented Sep 15 at 15:59
  • as mentioned below, issues with write times been slow on large datasets. GDAL/GRASS etc. does not always behave nicely with GPKG's.. Commented Sep 26 at 1:50

1 Answer 1

2

As a workaround I can suggest the following approach:

Firstly initiate a "new" class e.g. QgsProcessingParameterVectorDestinationSHP with createFileFilter method in the processing script:

class QgsProcessingParameterVectorDestinationSHP(QgsProcessingParameterVectorDestination):
    def createFileFilter(self):
        return "ESRI Shapefile (*.shp)"

And then wrap the desired parameter into QgsProcessingParameterVectorDestinationSHP inside the def initAlgorithm(self, config=None):

self.addParameter(
    QgsProcessingParameterVectorDestinationSHP(
        name="OUTPUT_POND_OUTLINES",
        description="Output Pond Outlines Vector",                
        optional=False,
    )
)

After that it should work as intended:

result

And as was suggested by @IanTurton it is better switching to something more up-to-date i.e. GeoPackage.

2
  • good work around, i have found write times to GPKG incredibly slow compared to SHP though, im not sure how to get around this limitation. When interacting with other tools like GDAL and GRASS reading/writing GPKG's often throws me errors.. Commented Sep 26 at 1:48
  • 1
    You are welcome, please, do not forget about "What should I do when someone answers my question?". Interesting case with slow write times of the GPKG, maybe it can be a nice topic to be asked on the GIS SE, or directly contact the OGC Consortium. Commented Sep 26 at 5:31

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.