Exemplo n.º 1
0
def layerAdded(qgislayer):
    try:
        if qgislayer.providerType().lower() != "wfs":
            return
    except:
        pass #Not all layers have a providerType method
    catalogs = list(_explorer.explorerTree.gsItem._catalogs.values())
    for cat in catalogs:
        if cat.layersEndpointUrl() in qgislayer.source():
            for layer in cat.get_layers():
                uri = uri_utils.layerUri(layer)
                if uri == qgislayer.source():
                    try:
                        sld = layer.default_style.sld_body.decode()
                        sld = adaptGsToQgs(sld)
                        sldfile = tempFilename("sld")
                        with open(sldfile, 'w') as f:
                            f.write(sld)
                        msg, ok = qgislayer.loadSldStyle(sldfile)
                        if not ok:
                            raise Exception("Could not load style for layer <b>%s</b>" % qgislayer.name())
                        qgislayer.styleChanged.connect(partial(updatePublishedStyle, qgislayer))
                    except Exception as e:
                        setWarning("Could not set style for layer <b>%s</b>" % qgislayer.name())
                    return
Exemplo n.º 2
0
    def addLayerToProject(self, name, destName = None):
        '''
        Adds a new layer to the current project based on a layer in a GeoServer catalog
        It will create a new layer with a WFS or WCS connection, pointing to the specified GeoServer
        layer. In the case of a vector layer, it will also fetch its associated style and set it
        as the current style for the created QGIS layer
        '''
        layer = self.catalog.get_layer(name)
        if layer is None:
            raise Exception ("A layer with the name '" + name + "' was not found in the catalog")

        resource = layer.resource
        uri = uri_utils.layerUri(layer)

        if resource.resource_type == "featureType":
            qgslayer = QgsVectorLayer(uri, destName or resource.title, "WFS")
            if not qgslayer.isValid():
                raise Exception ("Layer at %s is not a valid layer" % uri)
            ok = True
            try:
                sld = layer.default_style.sld_body
                sld = adaptGsToQgs(sld)
                sldfile = utils.tempFilename("sld")
                with open(sldfile, 'w') as f:
                    f.write(sld)
                msg, ok = qgslayer.loadSldStyle(sldfile)
            except Exception, e:
                ok = False
            QgsMapLayerRegistry.instance().addMapLayers([qgslayer])
            if not ok:
                raise Exception ("Layer was added, but style could not be set (maybe GeoServer layer is missing default style)")
Exemplo n.º 3
0
def layerAdded(qgislayer):
    try:
        qgislayer.styleChanged.connect(partial(updatePublishedStyle, qgislayer))
    except: #styleChanged only available for QGIS >2.16
        pass

    try:
        if qgislayer.providerType().lower() != "wfs":
            return
    except:
        pass #Not all layers have a providerType method
    catalogs = _explorer.explorerTree.gsItem._catalogs.values()
    for cat in catalogs:
        if cat.gs_base_url in qgislayer.source():
            for layer in cat.get_layers():
                uri = uri_utils.layerUri(layer)
                if uri == qgislayer.source():
                    try:
                        sld = layer.default_style.sld_body
                        sld = adaptGsToQgs(sld)
                        sldfile = tempFilename("sld")
                        with open(sldfile, 'w') as f:
                            f.write(sld)
                        msg, ok = qgislayer.loadSldStyle(sldfile)
                        if not ok:
                            raise Exception("Could not load style for layer <b>%s</b>" % qgislayer.name())
                    except Exception, e:
                        _explorer.setWarning("Could not set style for layer <b>%s</b>" % qgislayer.name())
                    break
Exemplo n.º 4
0
    def addLayerToProject(self, name, destName=None):
        '''
        Adds a new layer to the current project based on a layer in a GeoServer catalog
        It will create a new layer with a WFS or WCS connection, pointing to the specified GeoServer
        layer. In the case of a vector layer, it will also fetch its associated style and set it
        as the current style for the created QGIS layer
        '''
        layer = self.catalog.get_layer(name)
        if layer is None:
            raise Exception("A layer with the name '" + name +
                            "' was not found in the catalog")

        resource = layer.resource
        uri = uri_utils.layerUri(layer)

        if resource.resource_type == "featureType":
            qgslayer = QgsVectorLayer(uri, destName or resource.title, "WFS")
            if not qgslayer.isValid():
                raise Exception("Layer at %s is not a valid layer" % uri)
            ok = True
            try:
                sld = layer.default_style.sld_body
                sld = adaptGsToQgs(sld)
                sldfile = utils.tempFilename("sld")
                with open(sldfile, 'w') as f:
                    f.write(sld)
                msg, ok = qgslayer.loadSldStyle(sldfile)
            except Exception, e:
                ok = False
            QgsMapLayerRegistry.instance().addMapLayers([qgslayer])
            if not ok:
                raise Exception(
                    "Layer was added, but style could not be set (maybe GeoServer layer is missing default style)"
                )
Exemplo n.º 5
0
def layerAdded(qgislayer):
    try:
        if qgislayer.providerType().lower() != "wfs":
            return
    except:
        pass  #Not all layers have a providerType method
    catalogs = list(_explorer.explorerTree.gsItem._catalogs.values())
    for cat in catalogs:
        if cat.layersEndpointUrl() in qgislayer.source():
            for layer in cat.get_layers():
                uri = uri_utils.layerUri(layer)
                if uri == qgislayer.source():
                    try:
                        sld = layer.default_style.sld_body.decode()
                        sldfile = tempFilename("sld")
                        with open(sldfile, 'w') as f:
                            f.write(sld)
                        msg, ok = qgislayer.loadSldStyle(sldfile)
                        if not ok:
                            raise Exception(
                                "Could not load style for layer <b>%s</b>" %
                                qgislayer.name())
                        qgislayer.styleChanged.connect(
                            partial(updatePublishedStyle, qgislayer))
                    except Exception as e:
                        setWarning("Could not set style for layer <b>%s</b>" %
                                   qgislayer.name())
                    return
Exemplo n.º 6
0
    def addLayerToProject(self, name, destName=None):
        '''
        Adds a new layer to the current project based on a layer in a GeoServer catalog
        It will create a new layer with a WFS or WCS connection, pointing to the specified GeoServer
        layer. In the case of a vector layer, it will also fetch its associated style and set it
        as the current style for the created QGIS layer
        '''
        layer = self.catalog.get_layer(name)
        if layer is None:
            raise Exception("A layer with the name '" + name +
                            "' was not found in the catalog")

        resource = layer.resource
        uri = uri_utils.layerUri(layer)
        QgsNetworkAccessManager.instance().cache().clear()

        if resource.resource_type == "featureType":
            qgslayer = QgsVectorLayer(uri, destName or resource.title, "WFS")
            if not qgslayer.isValid():
                raise Exception("Layer at %s is not a valid layer" % uri)
            ok = True
            try:
                sld = layer.default_style.sld_body.decode()
                sld = adaptGsToQgs(str(sld))
                sldfile = tempFilename("sld")
                with open(sldfile, 'w') as f:
                    f.write(sld)
                msg, ok = qgslayer.loadSldStyle(sldfile)
            except Exception as e:
                ok = False
            QgsProject.instance().addMapLayers([qgslayer])
            setUnits(qgslayer)
            addTrackedLayer(qgslayer, self.catalog.service_url)
            if not ok:
                raise Exception(
                    "Layer was added, but style could not be set (maybe GeoServer layer is missing default style)"
                )
        elif resource.resource_type == "coverage":
            qgslayer = QgsRasterLayer(uri, destName or resource.title, "wcs")
            if not qgslayer.isValid():
                raise Exception("Layer at %s is not a valid layer" % uri)
            QgsProject.instance().addMapLayers([qgslayer])
            addTrackedLayer(qgslayer, self.catalog.service_url)
        elif resource.resource_type == "wmsLayer":
            qgslayer = QgsRasterLayer(uri, destName or resource.title, "wms")
            if not qgslayer.isValid():
                raise Exception("Layer at %s is not a valid layer" % uri)
            QgsProject.instance().addMapLayers([qgslayer])
            addTrackedLayer(qgslayer, self.catalog.service_url)
        else:
            raise Exception("Cannot add layer. Unsupported layer type.")
Exemplo n.º 7
0
    def addLayerToProject(self, name, destName = None):
        '''
        Adds a new layer to the current project based on a layer in a GeoServer catalog
        It will create a new layer with a WFS or WCS connection, pointing to the specified GeoServer
        layer. In the case of a vector layer, it will also fetch its associated style and set it
        as the current style for the created QGIS layer
        '''
        layer = self.catalog.get_layer(name)
        if layer is None:
            raise Exception ("A layer with the name '" + name + "' was not found in the catalog")

        resource = layer.resource
        uri = uri_utils.layerUri(layer)
        QgsNetworkAccessManager.instance().cache().clear()

        if resource.resource_type == "featureType":
            qgslayer = QgsVectorLayer(uri, destName or resource.title, "WFS")
            if not qgslayer.isValid():
                raise Exception ("Layer at %s is not a valid layer" % uri)
            ok = True
            try:
                sld = layer.default_style.sld_body.decode()
                sld = adaptGsToQgs(str(sld))
                sldfile = tempFilename("sld")
                with open(sldfile, 'w') as f:
                    f.write(sld)
                msg, ok = qgslayer.loadSldStyle(sldfile)
            except Exception as e:
                ok = False
            QgsProject.instance().addMapLayers([qgslayer])
            setUnits(qgslayer)
            addTrackedLayer(qgslayer, self.catalog.service_url)
            if not ok:
                raise Exception ("Layer was added, but style could not be set (maybe GeoServer layer is missing default style)")
        elif resource.resource_type == "coverage":
            qgslayer = QgsRasterLayer(uri, destName or resource.title, "wcs" )
            if not qgslayer.isValid():
                raise Exception ("Layer at %s is not a valid layer" % uri)
            QgsProject.instance().addMapLayers([qgslayer])
            addTrackedLayer(qgslayer, self.catalog.service_url)
        elif resource.resource_type == "wmsLayer":
            qgslayer = QgsRasterLayer(uri, destName or resource.title, "wms")
            if not qgslayer.isValid():
                raise Exception ("Layer at %s is not a valid layer" % uri)
            QgsProject.instance().addMapLayers([qgslayer])
            addTrackedLayer(qgslayer, self.catalog.service_url)
        else:
            raise Exception("Cannot add layer. Unsupported layer type.")
def layerAdded(qgislayer):

    if qgislayer.providerType().lower() != "wfs":
        return
    catalogs = _explorer.explorerTree.gsItem._catalogs.values()
    for cat in catalogs:
        if cat.gs_base_url in qgislayer.source():
            for layer in cat.get_layers():
                uri = uri_utils.layerUri(layer)
                if uri == qgislayer.source():
                    try:
                        sld = layer.default_style.sld_body
                        sld = adaptGsToQgs(sld)
                        sldfile = tempFilename("sld")
                        with open(sldfile, 'w') as f:
                            f.write(sld)
                        msg, ok = qgislayer.loadSldStyle(sldfile)
                        if not ok:
                            raise Exception("Could not set style for layer")
                    except Exception, e:
                        _explorer.setWarning("Could not set style for layer")
                    break
Exemplo n.º 9
0
def layerAdded(qgislayer):
    try:
        if qgislayer.providerType().lower() != "wfs":
            return
    except:
        pass #Not all layers have a providerType method
    catalogs = _explorer.explorerTree.gsItem._catalogs.values()
    for cat in catalogs:
        if cat.gs_base_url in qgislayer.source():
            for layer in cat.get_layers():
                uri = uri_utils.layerUri(layer)
                if uri == qgislayer.source():
                    try:
                        sld = layer.default_style.sld_body
                        sld = adaptGsToQgs(sld)
                        sldfile = tempFilename("sld")
                        with open(sldfile, 'w') as f:
                            f.write(sld)
                        msg, ok = qgislayer.loadSldStyle(sldfile)
                        if not ok:
                            raise Exception("Could not set style for layer")
                    except Exception, e:
                        _explorer.setWarning("Could not set style for layer")
                    break