[QGIS-Developer] ProcessingAlgorithm: get filename of the INPUT param

Richard Duivenvoorde rdmailings at duif.net
Wed Jun 19 06:42:30 PDT 2019


Nope,

SOURCE = <qgis._core.QgsProcessingFeatureSource object at 0x7fff684dcee8>

which (I think) does not bring you any further:

https://qgis.org/api/classQgsProcessingFeatureSource.html

unless you 'materialize' it to a layer:

https://qgis.org/api/classQgsFeatureSource.html

which is what I actually do below

Regards,

Richard



On 19/06/2019 15.26, info wrote:
> Hi,
> 
> l.source() perhaps?
> 
> Cheers,
> Benoit
> 
> 
> On 2019-06-19 14:20, Richard Duivenvoorde wrote:
>> Hi,
>>
>> got a question from somebody who needed to find the filename of an input
>> param in a ProcessingAlgorithm
>> (because he is going to read that file again or something like that).
>>
>> He adds the INPUT via the initAlgorithm function:
>>
>>         self.addParameter(
>>             QgsProcessingParameterFeatureSource(
>>                 self.INPUT,
>>                 self.tr('Input layer (.geojson)'),
>>                 [QgsProcessing.TypeVectorLine]
>>             )
>>         )
>>
>> And then tried to get the filename in the
>> processAlgorithm-implementation from the source via
>> self.parameterAsSource, but then could not find an uri/filename.
>>
>> Via:
>> https://gis.stackexchange.com/questions/280667/using-a-selected-layer-with-processing-in-qgis-3
>>
>> I gave him:
>> l = self.parameterAsVectorLayer(parameters, 'INPUT', context)
>> feedback.pushInfo('l = {}'.format(l))
>> feedback.pushInfo('l.dataProvider() = {}'.format(l.dataProvider()))
>> feedback.pushInfo('l.dataProvider().uri() =
>> {}'.format(l.dataProvider().uri()))
>> feedback.pushInfo('l.dataProvider().uri().uri() =
>> {}'.format(l.dataProvider().uri().uri()))
>>
>> which at least gives him the dataprovider uri WITH the filename.
>>
>> Question:
>> 1) isn't there an easier way, or is this the preferred way?
>> 2) if the filename contains a space, then the uri().uri() only shows the
>> part AFTER the space (as if it was a relative path, but then the wrong
>> path...). Using a filename from a dir WITHOUT a space the uri().uri()
>> shows you the full file path.
>>
>> TIA & Regards,
>>
>> Richard Duivenvoorde
>> _______________________________________________
>> QGIS-Developer mailing list
>> QGIS-Developer at lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer



More information about the QGIS-Developer mailing list