Ejemplo n.º 1
0
def checkJoinExists(layername, fieldname, targetlayer, targetfield):
    """
    Returns True if vector layer has a join with a
    target layer using the specified field and target field
    :param layername: vector layer name
    :param fieldname: join field name
    :param targetlayer: target vector layer name
    :param targetfield: target join field name
    :return: Boolean
    """

    layer = layerFromName(layername)
    tlayer = layerFromName(targetlayer)

    # check if layers exist
    if layer is None or tlayer is None:
        return False

    # check if join fields exist
    if fieldname not in [f.name() for f in layer.pendingFields()] or \
       targetfield not in [f.name() for f in tlayer.pendingFields()]:
        return False

    join_settings = (tlayer.id(), unicode(targetfield), unicode(fieldname))

    for j in layer.vectorJoins():
        if (j.joinLayerId, j.joinFieldName,
                j.targetFieldName) == join_settings:
            return True

    return False
Ejemplo n.º 2
0
def checkFieldValue(layername, field, value):
    """
    Return True if all features have a certain value for a
    particular field. If the layer has selected features, only those will be
    taken in account
    :param layername: Layer's name as in the layers panel
    :param field: Field name
    :param value: value to confirm
    :return: Boolean
    """

    layer = layerFromName(layername)
    if layer is None:
        return False

    if layer.selectedFeatureCount():
        features = layer.selectedFeatures()
    else:
        features = layer.getFeatures()

    for feature in features:
        if feature.attribute(field) != value:
            return False

    return True
Ejemplo n.º 3
0
def selectByRectangle(layername, xmin, ymin, xmax, ymax):
    """
    Select features in rectangle
    :param layername: Layer's name as in the layers panel
    :return: None
    """

    layer = layerFromName(layername)
    if layer is not None and layer.type() == QgsMapLayer.VectorLayer:
        layer.selectByRect(QgsRectangle(xmin, ymin, xmax, ymax))
Ejemplo n.º 4
0
def isLayerSaved(layername):
    """
    Returns True if no changes were made in the layer after the last save
    :param layername: Layer name as in the layers panel
    :return: Boolean
    """

    layer = layerFromName(layername)
    return layer is not None and layer.type() == QgsMapLayer.VectorLayer and \
           not layer.isModified()
def checkLayerInProject(layername):
    layer = layerFromName(layername)
    return layer is not None
def checkEdited(layername):
    layer = layerFromName(layername)
    if layer:
        return len(hasLocalChanges(layer)) > 0
    else:
        return False
Ejemplo n.º 7
0
def isLayerEditable(*args):
    """Returns True if layer with given name is in editable mode.
    NOTE: layer should be of the vector type and be loaded into project.
    """
    layer = layerFromName(args[0])
    return layer is not None and layer.isEditable()