Hi all,
I'm trying to get the file path for an input layer (which is a csv) in a
script in QGIS 3. I can see from the algorithm history that it is there in
the parameters (see below). However, it seems that when I use
`parameterAsFile`, it always returns an empty string. Is this a bug, or am
I using it incorrectly?
What I am looking for is a way to programatically access "
C:/GIS/Projects/LizeSuitableHabitatModel/dummySpecies.txt".
Thanks,
Rudi
*Algorithm history:*
processing.run("script:suitablehabitatmodel",
{'SPECIES_LIST':'file:///C:/GIS/Projects/LizeSuitableHabitatModel/dummySpecies.txt?type=csv&geomType=none&subsetIndex=no&watchFile=no','SPECIES_POINTS':'file:///C:/GIS/Projects/LizeSuitableHabitatModel/dummyPoints.txt?type=csv&xField=DDE&yField=DDS&crs=EPSG:4326&spatialIndex=yes&subsetIndex=no&watchFile=no','MODEL_CRS':'USER:100000','SPECIES_REPROJECT':'C:/Users/rudi_000/AppData/Local/Temp/processing_41d6b6ec7dd342f1bfd813b4b1c79dba/e89a5f992eb94e2291281d57f796e1b0/SPECIES_REPROJECT.shp'})
*Summarised script:*
def initAlgorithm(self, config=None):
self.addParameter(
QgsProcessingParameterFeatureSource(
self.SPECIES_POINTS,
self.tr('Species points'),
[QgsProcessing.TypeVectorPoint]
)
)
def processAlgorithm(self, parameters, context, feedback):
speciesPointsFile = self.parameterAsFile(parameters,
self.SPECIES_POINTS, context) # always returns an empty string
genspec = '1031-125' # this would be set in a loop
# trying to apply a filter to the input file by changing the subset
parameter
uri =
f"file:///{speciesPointsFile}?type=csv&xField=DDE&yField=DDS&crs=EPSG:4326&spatialIndex=yes&subsetIndex=no&watchFile=no&subset=%22Genspec%22%20%3D%20\'{genspec}\'"
filteredLayer = QgsVectorLayer(uri, 'FILTERED_POINTS',
'delimitedtext')
pointsReprojected = processing.run("native:reprojectlayer", {
'INPUT': filteredLayer,
'TARGET_CRS': modelCrs.authid(),
'OUTPUT' : speciesReprojectOutput
}, context=context, feedback=feedback)['OUTPUT']
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user