Esempio n. 1
0
    def publish_layer_group(self):
        """
        Publishes local map layers as WMS layer group on local OWS.
        """
        # temporary permission workaround: 
        # only allow public maps to be published
        if not self.is_public:
            return 'Only public maps can be saved as layer group.'

        map_layers = MapLayer.objects.filter(map=self.id)
        
        # Local Group Layer layers and corresponding styles
        layers = []
        lg_styles = []
        for ml in map_layers:
            if ml.local:
                layer = Layer.objects.get(typename=ml.name)
                style = ml.styles or getattr(layer.default_style, 'name', '')
                layers.append(layer)
                lg_styles.append(style)
        lg_layers = [l.name for l in layers]

        # Group layer bounds and name             
        lg_bounds = [str(coord) for coord in self.bbox] 
        lg_name = '%s_%d' % (slugify(self.title), self.id)

        # Update existing or add new group layer
        cat = Catalog(ogc_server_settings.rest, _user, _password)
        lg = self.layer_group
        if lg is None:
            lg = GsUnsavedLayerGroup(cat, lg_name, lg_layers, lg_styles, lg_bounds)
        else:
            lg.layers, lg.styles, lg.bounds = lg_layers, lg_styles, lg_bounds
        cat.save(lg)
        return lg_name
Esempio n. 2
0
def publish_layer_group(geonode_map):
        """
        Publishes local map layers as WMS layer group on local OWS.
        """
        if 'geonode.geoserver' in settings.INSTALLED_APPS:
            from geonode.geoserver.helpers import gs_catalog
            from geoserver.layergroup import UnsavedLayerGroup as GsUnsavedLayerGroup
        else:
            raise Exception(
                'Cannot publish layer group if geonode.geoserver is not in INSTALLED_APPS')

        # temporary permission workaround:
        # only allow public maps to be published
        if not geonode_map.is_public:
            return 'Only public maps can be saved as layer group.'

        map_layers = MapLayer.objects.filter(map=geonode_map.id)

        # Local Group Layer layers and corresponding styles
        layers = []
        lg_styles = []
        for ml in map_layers:
            if ml.local:
                layer = Layer.objects.get(typename=ml.name)
                style = ml.styles or getattr(layer.default_style, 'name', '')
                layers.append(layer)
                lg_styles.append(style)
        lg_layers = [l.name for l in layers]

        # Group layer bounds and name

        lg_bounds = [
            str(min(geonode_map.bbox_x0,geonode_map.bbox_x1)), # xmin
            str(max(geonode_map.bbox_x0,geonode_map.bbox_x1)), # xmax
            str(min(geonode_map.bbox_y0,geonode_map.bbox_y1)), # ymin
            str(max(geonode_map.bbox_y0,geonode_map.bbox_y1)), # ymax
            str(geonode_map.srid)]
        # lg_bounds = [str(coord) for coord in geonode_map.bbox]

        lg_name = '%s_%d' % (slugify(geonode_map.title), geonode_map.id)

        # Update existing or add new group layer
        lg = geonode_map.layer_group
        if lg is None:
            lg = GsUnsavedLayerGroup(
                gs_catalog,
                lg_name,
                lg_layers,
                lg_styles,
                lg_bounds)
        else:
            lg.layers, lg.styles, lg.bounds = lg_layers, lg_styles, lg_bounds
        gs_catalog.save(lg)
        return lg_name
Esempio n. 3
0
    def create_layergroup(self,
                          name,
                          layers=(),
                          styles=(),
                          bounds=None,
                          workspace=None,
                          title=None,
                          abstract=None,
                          mode=LayerGroup.Mode.SINGLE):
        '''Crete new layer group based on given layers and styles

        :param name: Name of the layer group.
        :param layers: list with layers names that conforms the group.
        :param styles: list with sytles names to style each layer.
        :param bounds: layer group extension. By default is set to "-180","180","-90","90","EPSG:4326"
        :param workspace: workspace name where layer group will be set.
        :param title: Title of the layer group. Available for GeoServer 2.4 or above.
        :param abstract: Description of the layer group. Available for GeoServer 2.4 or above.
        :param mode: Layer group publishing mode (Single, Named Tree, Container Tree, Earth Observation Tree). Available for GeoServer 2.4 or above.
        '''
        if any(g.name == name for g in self.get_layergroups()):
            raise ConflictingDataError("LayerGroup named %s already exists!" %
                                       name)
        else:
            return UnsavedLayerGroup(self, name, layers, styles, bounds,
                                     workspace, title, abstract, mode)
 def okPressed(self):
     self.name = self.nameBox.text().replace(" ", "_")
     if self.name.strip() == "":
         self.nameBox.setStyleSheet("QLineEdit{background: yellow}")
         return
     layers = []
     styles = []
     for i in range(len(self.layernames)):
         widget = self.table.cellWidget(i, 0)
         if widget.isChecked():
             layers.append(widget.text())
             styleWidget = self.table.cellWidget(i, 1)
             styles.append(styleWidget.currentText())
     if len(self.layernames) == 0:
         return
         #TODO show alert
     if self.previousgroup is not None:
         self.group = self.previousgroup
         self.group.dirty.update(layers=layers, styles=styles)
     else:
         #TODO compute bounds
         bbox = None
         self.group = UnsavedLayerGroup(self.catalog, self.name, layers,
                                        styles, bbox)
     self.close()
Esempio n. 5
0
    def publish_layer_group(self):
        """
        Publishes local map layers as WMS layer group on local OWS.
        """
        if check_ogc_backend(geoserver.BACKEND_PACKAGE):
            from geonode.geoserver.helpers import gs_catalog
            from geoserver.layergroup import UnsavedLayerGroup as GsUnsavedLayerGroup
        else:
            raise Exception(
                'Cannot publish layer group if geonode.geoserver is not in INSTALLED_APPS')

        # temporary permission workaround:
        # only allow public maps to be published
        if not self.is_public:
            return 'Only public maps can be saved as layer group.'

        map_layers = MapLayer.objects.filter(map=self.id)

        # Local Group Layer layers and corresponding styles
        layers = []
        lg_styles = []
        for ml in map_layers:
            if ml.local:
                layer = Layer.objects.get(alternate=ml.name)
                style = ml.styles or getattr(layer.default_style, 'name', '')
                layers.append(layer)
                lg_styles.append(style)
        lg_layers = [lyr.name for lyr in layers]

        # Group layer bounds and name
        lg_bounds = [str(coord) for coord in self.bbox]
        lg_name = f'{slugify(self.title)}_{self.id}'

        # Update existing or add new group layer
        lg = self.layer_group
        if lg is None:
            lg = GsUnsavedLayerGroup(
                gs_catalog,
                lg_name,
                lg_layers,
                lg_styles,
                lg_bounds)
        else:
            lg.layers, lg.styles, lg.bounds = lg_layers, lg_styles, lg_bounds
        gs_catalog.save(lg)
        return lg_name
Esempio n. 6
0
 def create_layergroup(self, name, layers=(), styles=(), bounds=None,
                       workspace=None):
     if any(g.name == name for g in self.get_layergroups()):
         msg = "LayerGroup named {} already exists!"
         raise ConflictingDataError(msg.format(name))
     else:
         return UnsavedLayerGroup(self, name, layers, styles, bounds,
                                  workspace)
Esempio n. 7
0
    def publishGroup(self, tree, explorer):
        groupname = self.element
        groups = qgislayers.getGroups()
        grouplyrs = groups[groupname]

        cat = selectCatalog(explorer.catalogs())
        if cat is None:
            return
        catgroup = cat.get_layergroup(groupname)
        toUpdate = set()
        toUpdate.add(tree.findAllItems(cat)[0])

        overwrite = bool(QSettings().value(
            "/OpenGeo/Settings/GeoServer/OverwriteGroupLayers", True, bool))

        dlg = PublishLayerGroupDialog(cat, groupname, grouplyrs,
                                      overwritegroup=True,
                                      overwritelayers=overwrite)
        dlg.exec_()
        grpName = dlg.definedname
        toPublish = dlg.topublish
        if grpName is None:  # toPublish can be empty list
            return
        catgroup = cat.get_layergroup(grpName)

        names = []
        if toPublish:
            explorer.setProgressMaximum(len(toPublish), "Publish layers")
            progress = 0
            layernames = []
            for layer, catalog, workspace, layername in toPublish:
                layernames.append(layername)
                explorer.setProgress(progress)
                ogcat = OGCatalog(catalog)
                if not explorer.run(ogcat.publishLayer,
                                    None,
                                    [],
                                    layer, workspace, True, layername):
                    explorer.setProgress(0)
                    return
                progress += 1
                explorer.setProgress(progress)
            explorer.resetActivity()
            names = reversed(layernames)

        if catgroup:
            cat.delete(catgroup)

        #TODO calculate bounds
        bbox = None
        group = UnsavedLayerGroup(cat, grpName, names, names, bbox)

        explorer.run(cat.save,
                     "Create layer group from group '" + groupname + "'",
                     toUpdate,
                     group)
Esempio n. 8
0
    def publish_layer_group(self):
        """
        Publishes local map layers as WMS layer group on local OWS.
        """
        if "geonode.geoserver" in settings.INSTALLED_APPS:
            from geonode.geoserver.helpers import gs_catalog
            from geoserver.layergroup import UnsavedLayerGroup as GsUnsavedLayerGroup
        else:
            raise Exception("Cannot publish layer group if geonode.geoserver is not in INSTALLED_APPS")

        # temporary permission workaround:
        # only allow public maps to be published
        if not self.is_public:
            return "Only public maps can be saved as layer group."

        map_layers = MapLayer.objects.filter(map=self.id)

        # Local Group Layer layers and corresponding styles
        layers = []
        lg_styles = []
        for ml in map_layers:
            if ml.local:
                layer = Layer.objects.get(typename=ml.name)
                style = ml.styles or getattr(layer.default_style, "name", "")
                layers.append(layer)
                lg_styles.append(style)
        lg_layers = [l.name for l in layers]

        # Group layer bounds and name
        lg_bounds = [str(coord) for coord in self.bbox]
        lg_name = "%s_%d" % (slugify(self.title), self.id)

        # Update existing or add new group layer
        lg = self.layer_group
        if lg is None:
            lg = GsUnsavedLayerGroup(gs_catalog, lg_name, lg_layers, lg_styles, lg_bounds)
        else:
            lg.layers, lg.styles, lg.bounds = lg_layers, lg_styles, lg_bounds
        gs_catalog.save(lg)
        return lg_name
Esempio n. 9
0
def publishDraggedGroup(explorer, groupItem, catalog, workspace=None):
    groupname = groupItem.element
    groups = qgislayers.getGroups()
    grouplyrs = groups[groupname]

    overwrite = bool(QSettings().value(
        "/OpenGeo/Settings/GeoServer/OverwriteGroupLayers", True, bool))
    try:
        dlg = PublishLayerGroupDialog(catalog,
                                      groupname,
                                      grouplyrs,
                                      workspace=workspace,
                                      overwritegroup=True,
                                      overwritelayers=overwrite)
        dlg.exec_()
    except UserCanceledOperation:
        return False
    grpName = dlg.definedname
    toPublish = dlg.topublish
    if grpName is None:  # toPublish can be empty list
        return False
    catgroup = catalog.get_layergroup(grpName)

    names = []
    if toPublish:
        explorer.setProgressMaximum(len(toPublish), "Publish layers")
        progress = 0
        layernames = []
        for layer, catalog, workspc, layername in toPublish:
            layernames.append(layername)
            explorer.setProgress(progress)
            ogcat = OGCatalog(catalog)
            if not explorer.run(ogcat.publishLayer, None, [], layer, workspc,
                                True, layername):
                explorer.setProgress(0)
                return
            progress += 1
            explorer.setProgress(progress)
        explorer.resetActivity()
        names = reversed(layernames)

    if catgroup:
        catalog.delete(catgroup)

    #TODO calculate bounds
    bbox = None
    group = UnsavedLayerGroup(catalog, grpName, names, names, bbox)

    return explorer.run(catalog.save,
                        "Create layer group from group '" + groupname + "'",
                        [], group)
Esempio n. 10
0
 def create_layergroup(self,
                       name,
                       layers=(),
                       styles=(),
                       bounds=None,
                       mode="SINGLE",
                       abstract=None,
                       title=None,
                       workspace=None):
     if self.get_layergroups(names=name, workspaces=[workspace]):
         raise ConflictingDataError("LayerGroup named %s already exists!" %
                                    name)
     else:
         return UnsavedLayerGroup(self, name, layers, styles, bounds, mode,
                                  abstract, title, workspace)
Esempio n. 11
0
    def publish_layer_group(self):
        """
        Publishes local map layers as WMS layer group on local OWS.
        """
        # temporary permission workaround:
        # only allow public maps to be published
        if not self.is_public:
            return 'Only public maps can be saved as layer group.'

        map_layers = MapLayer.objects.filter(map=self.id)

        # Local Group Layer layers and corresponding styles
        layers = []
        lg_styles = []
        for ml in map_layers:
            if ml.local:
                layer = Layer.objects.get(typename=ml.name)
                style = ml.styles or getattr(layer.default_style, 'name', '')
                layers.append(layer)
                lg_styles.append(style)
        lg_layers = [l.name for l in layers]

        # Group layer bounds and name
        lg_bounds = [str(coord) for coord in self.bbox]
        lg_name = '%s_%d' % (slugify(self.title), self.id)

        # Update existing or add new group layer
        cat = Catalog(ogc_server_settings.rest, _user, _password)
        lg = self.layer_group
        if lg is None:
            lg = GsUnsavedLayerGroup(cat, lg_name, lg_layers, lg_styles,
                                     lg_bounds)
        else:
            lg.layers, lg.styles, lg.bounds = lg_layers, lg_styles, lg_bounds
        cat.save(lg)
        return lg_name
Esempio n. 12
0
 def okPressed(self):
     self.name = unicode(self.nameBox.definedName())
     layers = []
     styles = []
     for i in range(len(self.layernames)):
         widget = self.table.cellWidget(i, 0)
         if widget.isChecked():
             layers.append(widget.text())
             styleWidget = self.table.cellWidget(i, 1)
             styles.append(styleWidget.currentText())
     if len(self.layernames) == 0:
         return
         #TODO show alert
     if self.previousgroup is not None:
         self.group = self.previousgroup
         self.group.dirty.update(layers = layers, styles = styles)
     else:
         #TODO compute bounds
         bbox = None
         self.group =  UnsavedLayerGroup(self.catalog, self.name, layers, styles, bbox)
     self.close()
Esempio n. 13
0
 def create_layergroup(self, name, layers=(), styles=(), bounds=None):
     if any(g.name == name for g in self.get_layergroups()):
         raise ConflictingDataError("LayerGroup named %s already exists!" %
                                    name)
     else:
         return UnsavedLayerGroup(self, name, layers, styles, bounds)