Skip to main content
added 1 character in body; edited title
Source Link
Jochen Schwarze
  • 14.9k
  • 8
  • 54
  • 120

Best way (performance wise) to add Attribute fields in pyQGISPyQGIS on large files

I have a question regarding adding attribute fields on an existing vector file in pyQGISPyQGIS. I’m writing a processing script for QGIS, and so far, I use the QGIS field calculator to add new attribute fields and then fill every feature with a value. The script looks something like this:

layer = QgsVectorLayer(myVectorFile,"", "ogr")
Field_1=processing.runalg('qgis:fieldcalculator',layer,'Field_1',1,1.0,1.0,True,Value_1,None)
Field_2=processing.runalg('qgis:fieldcalculator',Field_1['OUTPUT_LAYER'],'Field_2',1,1.0,1.0,True,Value_2,None)
Field_3=processing.runalg('qgis:fieldcalculator',Field_2['OUTPUT_LAYER'],'Field_3',1,1.0,1.0,True,Value_3,None)

Etc.

This works as expected, but it takes a very long time when I run the script, since it runs on very large vector files with a lot of features. I’m looking for a better/more performant way to add fields and file them with a value in pyQGISPyQGIS. I imagenimagine that maybe it would be possible to only edit the .dbf file? I’m open to suggestions.

Best way (performance wise) to add Attribute fields in pyQGIS on large files

I have a question regarding adding attribute fields on an existing vector file in pyQGIS. I’m writing a processing script for QGIS, and so far, I use the QGIS field calculator to add new attribute fields and then fill every feature with a value. The script looks something like this:

layer = QgsVectorLayer(myVectorFile,"", "ogr")
Field_1=processing.runalg('qgis:fieldcalculator',layer,'Field_1',1,1.0,1.0,True,Value_1,None)
Field_2=processing.runalg('qgis:fieldcalculator',Field_1['OUTPUT_LAYER'],'Field_2',1,1.0,1.0,True,Value_2,None)
Field_3=processing.runalg('qgis:fieldcalculator',Field_2['OUTPUT_LAYER'],'Field_3',1,1.0,1.0,True,Value_3,None)

Etc.

This works as expected, but it takes a very long time when I run the script, since it runs on very large vector files with a lot of features. I’m looking for a better/more performant way to add fields and file them with a value in pyQGIS. I imagen that maybe it would be possible to only edit the .dbf file? I’m open to suggestions.

Best way (performance wise) to add Attribute fields in PyQGIS on large files

I have a question regarding adding attribute fields on an existing vector file in PyQGIS. I’m writing a processing script for QGIS, and so far, I use the QGIS field calculator to add new attribute fields and then fill every feature with a value. The script looks something like this:

layer = QgsVectorLayer(myVectorFile,"", "ogr")
Field_1=processing.runalg('qgis:fieldcalculator',layer,'Field_1',1,1.0,1.0,True,Value_1,None)
Field_2=processing.runalg('qgis:fieldcalculator',Field_1['OUTPUT_LAYER'],'Field_2',1,1.0,1.0,True,Value_2,None)
Field_3=processing.runalg('qgis:fieldcalculator',Field_2['OUTPUT_LAYER'],'Field_3',1,1.0,1.0,True,Value_3,None)

Etc.

This works as expected, but it takes a very long time when I run the script, since it runs on very large vector files with a lot of features. I’m looking for a better/more performant way to add fields and file them with a value in PyQGIS. I imagine that maybe it would be possible to only edit the .dbf file? I’m open to suggestions.

Tweeted twitter.com/StackGIS/status/990898665446412289
edited tags
Link
Miron
  • 1.2k
  • 7
  • 20
edited body
Source Link
Miron
  • 1.2k
  • 7
  • 20

I have a question regarding adding attribute fields on an existing vector file in pyQGIS. I’m writing a processing script for QGIS, and so far, I use the QGIS field calculator to add new attribute fields and then fill every feature with a value. The script looks something like this:

layer = QgsVectorLayer(myVectorFile,"", "ogr")
Field_1=processing.runalg('qgis:fieldcalculator',layer,'Field_1',1,1.0,1.0,True,Value_1,None)
Field_2=processing.runalg('qgis:fieldcalculator',Field_1['OUTPUT_LAYER'],'Value_2''Field_2',1,1.0,1.0,True,Field_2Value_2,None)
Field_3=processing.runalg('qgis:fieldcalculator',Field_2['OUTPUT_LAYER'],'Value_3''Field_3',1,1.0,1.0,True,Field_3Value_3,None)

Etc.

This works as expected, but it takes a very long time when I run the script, since it runs on very large vector files with a lot of features. I’m looking for a better/more performant way to add fields and file them with a value in pyQGIS. I imagen that maybe it would be possible to only edit the .dbf file? I’m open to suggestions.

I have a question regarding adding attribute fields on an existing vector file in pyQGIS. I’m writing a processing script for QGIS, and so far, I use the QGIS field calculator to add new attribute fields and then fill every feature with a value. The script looks something like this:

layer = QgsVectorLayer(myVectorFile,"", "ogr")
Field_1=processing.runalg('qgis:fieldcalculator',layer,'Field_1',1,1.0,1.0,True,Value_1,None)
Field_2=processing.runalg('qgis:fieldcalculator',Field_1['OUTPUT_LAYER'],'Value_2',1,1.0,1.0,True,Field_2,None)
Field_3=processing.runalg('qgis:fieldcalculator',Field_2['OUTPUT_LAYER'],'Value_3',1,1.0,1.0,True,Field_3,None)

Etc.

This works as expected, but it takes a very long time when I run the script, since it runs on very large vector files with a lot of features. I’m looking for a better/more performant way to add fields and file them with a value in pyQGIS. I imagen that maybe it would be possible to only edit the .dbf file? I’m open to suggestions.

I have a question regarding adding attribute fields on an existing vector file in pyQGIS. I’m writing a processing script for QGIS, and so far, I use the QGIS field calculator to add new attribute fields and then fill every feature with a value. The script looks something like this:

layer = QgsVectorLayer(myVectorFile,"", "ogr")
Field_1=processing.runalg('qgis:fieldcalculator',layer,'Field_1',1,1.0,1.0,True,Value_1,None)
Field_2=processing.runalg('qgis:fieldcalculator',Field_1['OUTPUT_LAYER'],'Field_2',1,1.0,1.0,True,Value_2,None)
Field_3=processing.runalg('qgis:fieldcalculator',Field_2['OUTPUT_LAYER'],'Field_3',1,1.0,1.0,True,Value_3,None)

Etc.

This works as expected, but it takes a very long time when I run the script, since it runs on very large vector files with a lot of features. I’m looking for a better/more performant way to add fields and file them with a value in pyQGIS. I imagen that maybe it would be possible to only edit the .dbf file? I’m open to suggestions.

Source Link
Miron
  • 1.2k
  • 7
  • 20
Loading