code: def _remove_features(layer):
      layer_purpose = layer.keywords['layer_purpose']
      layer_subcategory = layer.keywords.get(layer_purpose)
      compulsory_field = get_compulsory_fields(layer_purpose, layer_subcategory)
      inasafe_fields = layer.keywords['inasafe_fields']
      field_names = inasafe_fields.get(compulsory_field['key'])
      if not isinstance(field_names, list):
          field_names = [field_names]
      for field_name in field_names:
          if not field_name:
              message = 'Keyword %s is missing from %s' % (
                  compulsory_field['key'], layer_purpose)
              raise InvalidKeywordsForProcessingAlgorithm(message)
          index = layer.fields().lookupField(field_name)
          request = QgsFeatureRequest()
          request.setSubsetOfAttributes([field_name], layer.fields())
          layer.startEditing()
          i = 0
          for feature in layer.getFeatures(request):
              feat_attr = feature.attributes()[index]
              if (feat_attr is None
                      or (hasattr(feat_attr, 'isNull')
                          and feat_attr.isNull())):
                  if layer_purpose == 'hazard':
                      layer.deleteFeature(feature.id())
                      i += 1
                  elif layer_purpose == 'aggregation':
                      layer.changeAttributeValue(
                          feature.id(), index, str(feature.id()))
                  elif layer_purpose == 'exposure':
                      layer.changeAttributeValue(
                          feature.id(), index, '')
              geometry = feature.geometry()
              if not geometry:
                  layer.deleteFeature(feature.id())
                  i += 1
                  continue
              if geometry.isEmpty():
                  layer.deleteFeature(feature.id())
                  i += 1
                  continue
              if not geometry.isGeosValid():
                  pass
          layer.commitChanges()
          if i:
              LOGGER.critical(
                  'Features which have been removed from %s : %s'
                  % (layer.keywords['layer_purpose'], i))
          else:
              LOGGER.info(
                  'No feature has been removed from %s during the vector layer '
                  'preparation' % layer.keywords['layer_purpose'])