def build_vector_layer_import_command(self, variable_name, layer, context, feedback): """ Returns an import command for the specified vector layer, storing it in a variable """ if layer is None: return self.r_templates.set_variable_null(variable_name) is_ogr_disk_based_layer = layer is not None and layer.dataProvider( ).name() == 'ogr' if is_ogr_disk_based_layer: # we only support direct reading of disk based ogr layers -- not ogr postgres layers, etc source_parts = QgsProviderRegistry.instance().decodeUri( 'ogr', layer.source()) if not source_parts.get('path'): is_ogr_disk_based_layer = False elif source_parts.get('layerId'): # no support for directly reading layers by id in R is_ogr_disk_based_layer = False if not is_ogr_disk_based_layer: # parameter is not a vector layer or not an OGR layer - try to convert to a source compatible with # R OGR inputs and extract selection if required path = QgsProcessingUtils.convertToCompatibleFormat( layer, False, variable_name, compatibleFormats=QgsVectorFileWriter. supportedFormatExtensions(), preferredFormat='gpkg', context=context, feedback=feedback) ogr_layer = QgsVectorLayer(path, '', 'ogr') return self.load_vector_layer_command(variable_name, ogr_layer, None) # already an ogr disk based layer source return self.load_vector_layer_command(variable_name, layer, None)