In QGIS 3.4 I can run algorithms under the General setting "Invalid features filtering" -> "Ignore features with invalid geometries" However, when I try Processing through Python functions like the qgis:fieldcalculator it just breaks. Is there a way to make my QGIS python interpreter recognize that I do not care for invalid geometries?
Here is an example of a working code with valid geometries which breaks when invalid :
import os
import sys
import gdal
gdal.UseExceptions()
from qgis.core import QgsApplication
from qgis.analysis import QgsNativeAlgorithms
QgsApplication.setPrefixPath(os.path.join("C:", os.sep, "OSGeo4W64", "apps", "qgis"), True)
qgs = QgsApplication([], False)
qgs.initQgis()
sys.path.append(os.path.join("C:", os.sep, "OSGeo4W64", "apps", "qgis", "python", "plugins"))
import processing
from processing.core.Processing import Processing
Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
def add_area(input_vector):
out = "pathtooutput.shp"
params = {
'INPUT': input_vector,
'FIELD_NAME': 'area',
'FIELD_TYPE': 0,
'FIELD_LENGTH': 10,
'FIELD_PRECISION': 3,
'NEW_FIELD': True,
'FORMULA': ' $area ',
'OUTPUT': out
}
res = processing.run("qgis:fieldcalculator", params)
print(res)
return out
inp = "path_to_testvector_with_invalid_or_valid_geometries_for_test.shp"
add_area(inp)