Exemplo n.º 1
0
    def check_layer_is_geopackage(layer: QgsMapLayer) -> Tuple[bool, str]:

        if not layer:
            return False, 'La couche est invalide'

        testing = os.environ.get('TESTING_MERCICOR', '')
        if testing == 'True':
            return True, ''

        uri = QgsProviderRegistry.instance().decodeUri('ogr', layer.source())
        if not uri['path'].lower().endswith('.gpkg') or not uri['layerName']:
            message = (
                'La couche doit être le geopackage de la zone d\'étude et non pas {}'
                .format(layer.source()))
            return False, message

        return True, ''
Exemplo n.º 2
0
def layer_name_source(layer: QgsMapLayer) -> Tuple[str, str]:
    """
    Returns the name and the source path of the layer.

    :param layer: the layer from which to extract name and source.
    :type layer: QgsMapLayer.
    :return: the layer name and source.
    :rtype: tuple of two strings.

    Examples:
    """

    return layer.name(), layer.source()
Exemplo n.º 3
0
def getConnectionParameterFromDbLayer(layer: QgsMapLayer) -> Dict[str,str]:
    '''
    Get connection parameters
    from the layer datasource
    '''
    connectionParams = None

    if layer.providerType() == 'postgres':
        dbType = 'postgis'
    else:
        dbType = 'spatialite'

    src = layer.source()
    try:
        uri = QgsDataSourceUri(src)
    except:
        uri = QgsDataSourceURI(src)

    # TODO Use immutable namedtuple
    connectionParams = {
        'service' : uri.service(),
        'dbname' : uri.database(),
        'host' : uri.host(),
        'port': uri.port(),
        'user' : uri.username(),
        'password': uri.password(),
        'sslmode' : uri.sslMode(),
        'key': uri.keyColumn(),
        'estimatedmetadata' : str(uri.useEstimatedMetadata()),
        'checkPrimaryKeyUnicity' : '',
        'srid' : uri.srid(),
        'type': uri.wkbType(),
        'schema': uri.schema(),
        'table' : uri.table(),
        'geocol' : uri.geometryColumn(),
        'sql' : uri.sql(),
        'dbType': dbType
    }

    return connectionParams