Skip to content

Commit

Permalink
correctly handle NULL values
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Sep 6, 2019
1 parent af591a8 commit bbe6821
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions wincan2qgep/core/vsacode.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
#---------------------------------------------------------------------

from qgis.core import QgsProject, QgsFeature, QgsFeatureRequest
from qgis.core import QgsProject, QgsFeature, QgsFeatureRequest, QgsApplication, NULL

from wincan2qgep.core.my_settings import MySettings

Expand Down Expand Up @@ -91,18 +91,20 @@ def structure_condition_2_damage_level(code):
"""
return damage code to renovation necessity pkey
"""
feature = QgsFeature()

layer_id = MySettings().value("vl_wastewater_structure_structure_condition")
layer = QgsProject.instance().mapLayer(layer_id)
if layer is not None:
request_text = '"code" = \'{}\''.format(code)
request = QgsFeatureRequest().setFilterExpression(request_text)
feature = next(layer.getFeatures(request), QgsFeature())
# print request_text, feature.isValid()

print(code, QgsApplication.nullRepresentation(), code == QgsApplication.nullRepresentation())

if layer is None or code == NULL or code is None:
return None

request_text = '"code" = \'{}\''.format(code)
request = QgsFeatureRequest().setFilterExpression(request_text)
feature = next(layer.getFeatures(request), QgsFeature())
# print(request_text, feature.isValid())

if feature.isValid():
return feature['value_en']

else:
return None
return None

0 comments on commit bbe6821

Please sign in to comment.