Skip to main content
Notice removed Draw attention by CommunityBot
Bounty Ended with ThomasG77's answer chosen by CommunityBot
Tweeted twitter.com/StackGIS/status/1288444179731943425
added 360 characters in body
Source Link
DGIS
  • 2.7k
  • 22
  • 42

In my standalone script I want to use the SAGA tool "merge vector layers". According to the docs I need the following.

Thus, I wrote the following code to implement the tool:

def merge(self):
    Parcel_channel2 = self.Parcel_Channel2()
    intersection = self.intersection()
    param = {'INPUT': [Parcel_channel2, intersection],
             'MERGED': 'TEMPORARY_OUTPUT',
             'SRCINFO': False,
             'MATCH': True,
             }
    merge = processing.run('saga:mergevectorlayers', param)
    vlayer = merge['MERGED']
    QgsProject.instance().addMapLayer(vlayer)
    return vlayer

When I try to run the script I get the following error message:

QgsProject.addMapLayer(): argument 1 has unexpected type 'str'

With native Qgs tools, this code works fine. However, it seems that SAGA doesn't return a VectorLayer but just the string in my 'outDir' variable. How do I get the output when using SAGA?

I'm using QGIS 3.10

Edit: I figured out, that native Qgs tools retun QgsMapLayer objects and saga tools return the path and name of a .shp file

C:/Users/denni/AppData/Local/Temp/processing_c0c1104bbc4447558e00113072ccc4d8/91e580e9c006429597540594cb000407/MERGED.shp

but I need a QgsMapLayer as result... how would I do that?

In my standalone script I want to use the SAGA tool "merge vector layers". According to the docs I need the following.

Thus, I wrote the following code to implement the tool:

def merge(self):
    Parcel_channel2 = self.Parcel_Channel2()
    intersection = self.intersection()
    param = {'INPUT': [Parcel_channel2, intersection],
             'MERGED': 'TEMPORARY_OUTPUT',
             'SRCINFO': False,
             'MATCH': True,
             }
    merge = processing.run('saga:mergevectorlayers', param)
    vlayer = merge['MERGED']
    QgsProject.instance().addMapLayer(vlayer)
    return vlayer

When I try to run the script I get the following error message:

QgsProject.addMapLayer(): argument 1 has unexpected type 'str'

With native Qgs tools, this code works fine. However, it seems that SAGA doesn't return a VectorLayer but just the string in my 'outDir' variable. How do I get the output when using SAGA?

I'm using QGIS 3.10

In my standalone script I want to use the SAGA tool "merge vector layers". According to the docs I need the following.

Thus, I wrote the following code to implement the tool:

def merge(self):
    Parcel_channel2 = self.Parcel_Channel2()
    intersection = self.intersection()
    param = {'INPUT': [Parcel_channel2, intersection],
             'MERGED': 'TEMPORARY_OUTPUT',
             'SRCINFO': False,
             'MATCH': True,
             }
    merge = processing.run('saga:mergevectorlayers', param)
    vlayer = merge['MERGED']
    QgsProject.instance().addMapLayer(vlayer)
    return vlayer

When I try to run the script I get the following error message:

QgsProject.addMapLayer(): argument 1 has unexpected type 'str'

With native Qgs tools, this code works fine. However, it seems that SAGA doesn't return a VectorLayer but just the string in my 'outDir' variable. How do I get the output when using SAGA?

I'm using QGIS 3.10

Edit: I figured out, that native Qgs tools retun QgsMapLayer objects and saga tools return the path and name of a .shp file

C:/Users/denni/AppData/Local/Temp/processing_c0c1104bbc4447558e00113072ccc4d8/91e580e9c006429597540594cb000407/MERGED.shp

but I need a QgsMapLayer as result... how would I do that?

deleted 68 characters in body
Source Link
DGIS
  • 2.7k
  • 22
  • 42

In my standalone script I want to use the SAGA tool "merge vector layers". According to the docs I need the following.

Thus, I wrote the following code to implement the tool:

def merge(self):
    Parcel_channel2 = self.Parcel_Channel2()
    intersection = self.intersection()
    outDir = os.path.join(QgsProject().instance().homePath(), "merge.shp")
    param = {'INPUT': [Parcel_channel2, intersection],
             'MERGED': outDir'TEMPORARY_OUTPUT',
             'SRCINFO': False,
             'MATCH': True,
             }
    merge = processing.run('saga:mergevectorlayers', param)
    vlayer = merge['MERGED']
    QgsProject.instance().addMapLayer(vlayer)
    return vlayer

When I try to run the script I get the following error message:

QgsProject.addMapLayer(): argument 1 has unexpected type 'str'

With native Qgs tools, this code works fine. However, it seems that SAGA doesn't return a VectorLayer but just the string in my 'outDir' variable. How do I get the output when using SAGA?

I'm using QGIS 3.10

In my standalone script I want to use the SAGA tool "merge vector layers". According to the docs I need the following.

Thus, I wrote the following code to implement the tool:

def merge(self):
    Parcel_channel2 = self.Parcel_Channel2()
    intersection = self.intersection()
    outDir = os.path.join(QgsProject().instance().homePath(), "merge.shp")
    param = {'INPUT': [Parcel_channel2, intersection],
             'MERGED': outDir,
             'SRCINFO': False,
             'MATCH': True,
             }
    merge = processing.run('saga:mergevectorlayers', param)
    vlayer = merge['MERGED']
    QgsProject.instance().addMapLayer(vlayer)
    return vlayer

When I try to run the script I get the following error message:

QgsProject.addMapLayer(): argument 1 has unexpected type 'str'

With native Qgs tools, this code works fine. However, it seems that SAGA doesn't return a VectorLayer but just the string in my 'outDir' variable. How do I get the output when using SAGA?

I'm using QGIS 3.10

In my standalone script I want to use the SAGA tool "merge vector layers". According to the docs I need the following.

Thus, I wrote the following code to implement the tool:

def merge(self):
    Parcel_channel2 = self.Parcel_Channel2()
    intersection = self.intersection()
    param = {'INPUT': [Parcel_channel2, intersection],
             'MERGED': 'TEMPORARY_OUTPUT',
             'SRCINFO': False,
             'MATCH': True,
             }
    merge = processing.run('saga:mergevectorlayers', param)
    vlayer = merge['MERGED']
    QgsProject.instance().addMapLayer(vlayer)
    return vlayer

When I try to run the script I get the following error message:

QgsProject.addMapLayer(): argument 1 has unexpected type 'str'

With native Qgs tools, this code works fine. However, it seems that SAGA doesn't return a VectorLayer but just the string in my 'outDir' variable. How do I get the output when using SAGA?

I'm using QGIS 3.10

Notice added Draw attention by DGIS
Bounty Started worth 200 reputation by DGIS
naming
Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

using Using SAGA tool in PyqgsPyQGIS standalone script. Output doesn't return vector layer

Source Link
DGIS
  • 2.7k
  • 22
  • 42
Loading