def publishDraggedGroup(explorer, groupItem, catalog, workspace): groupName = groupItem.element groups = qgislayers.getGroups() group = groups[groupName] gslayers= [layer.name for layer in catalog.get_layers()] missing = [] overwrite = bool(QtCore.QSettings().value("/GeoServer/Settings/GeoServer/OverwriteGroupLayers", True, bool)) for layer in group: if layer.name() not in gslayers or overwrite: missing.append(layer) if missing: explorer.setProgressMaximum(len(missing), "Publish layers") progress = 0 cat = CatalogWrapper(catalog) for layer in missing: explorer.setProgress(progress) explorer.run(cat.publishLayer, None, [], layer, workspace, True) progress += 1 explorer.setProgress(progress) explorer.resetActivity() names = [layer.name() for layer in group] layergroup = catalog.create_layergroup(groupName, names, names) explorer.run(catalog.save, "Create layer group from group '" + groupName + "'", [], layergroup)
def publishProject(tree, explorer, catalog): layers = qgislayers.getAllLayers() dlg = PublishProjectDialog(catalog) dlg.exec_() if not dlg.ok: return workspace = dlg.workspace groupName = dlg.groupName overwrite = dlg.overwrite explorer.setProgressMaximum(len(layers), "Publish layers") progress = 0 cat = CatalogWrapper(catalog) for layer in layers: explorer.setProgress(progress) explorer.run(publishLayer, None, [], cat, layer, workspace, overwrite) progress += 1 explorer.setProgress(progress) explorer.resetActivity() groups = qgislayers.getGroups() for group in groups: names = [layer.name() for layer in groups[group]] try: layergroup = catalog.create_layergroup(group, names, names) explorer.run(catalog.save, "Create layer group '" + group + "'", [], layergroup) except ConflictingDataError, e: explorer.setWarning(str(e))
def layersUploaded(): groups = qgislayers.getGroups() for group in groups: names = [layer.name() for layer in groups[group][::-1]] try: layergroup = catalog.create_layergroup( group, names, names, getGroupBounds(groups[group])) except ConflictingDataError: layergroup = catalog.get_layergroups(group)[0] layergroup.dirty.update(layers=names, styles=names) explorer.run(catalog.save, "Create layer group '" + group + "'", [], layergroup) if groupName is not None: names = [layer.name() for layer in layers[::-1]] try: layergroup = catalog.create_layergroup(groupName, names, names, getGroupBounds(layers)) except ConflictingDataError: layergroup = catalog.get_layergroups(groupName)[0] layergroup.dirty.update(layers=names, styles=names) explorer.run(catalog.save, "Create global layer group", [], layergroup) tree.findAllItems(catalog)[0].refreshContent(explorer) explorer.resetActivity()
def publishGroup(self, name, destName=None, workspace=None, overwrite=False, overwriteLayers=False): """ Publishes a group in the given catalog name: the name of the QGIS group to publish. It will also be used as the GeoServer layergroup name workspace: The workspace to add the group to overwrite: if True, it will overwrite a previous group with the specified name, if it exists overwriteLayers: if False, in case a layer in the group is not found in the specified workspace, the corresponding layer from the current QGIS project will be published, but all layers of the group that can be found in the GeoServer workspace will not be published. If True, all layers in the group are published, even if layers with the same name exist in the workspace """ groups = layers.getGroups() if name not in groups: raise Exception("The specified group does not exist") destName = destName if destName is not None else name gsgroup = self.catalog.get_layergroup(destName) if gsgroup is not None and not overwrite: return group = groups[name] bounds = None def addToBounds(bbox, bounds): if bounds is not None: bounds = [ min(bounds[0], bbox.xMinimum()), max(bounds[1], bbox.xMaximum()), min(bounds[2], bbox.yMinimum()), max(bounds[3], bbox.yMaximum()), ] else: bounds = [bbox.xMinimum(), bbox.xMaximum(), bbox.yMinimum(), bbox.yMaximum()] return bounds for layer in group: gslayer = self.catalog.get_layer(layer.name()) if gslayer is None or overwriteLayers: self.publishLayer(layer, workspace, True) transform = QgsCoordinateTransform(layer.crs(), QgsCoordinateReferenceSystem("EPSG:4326")) bounds = addToBounds(transform.transformBoundingBox(layer.extent()), bounds) names = [layer.name() for layer in group] bounds = (str(bounds[0]), str(bounds[1]), str(bounds[2]), str(bounds[3]), "EPSG:4326") layergroup = self.catalog.create_layergroup(destName, names, names, bounds) self.catalog.save(layergroup)
def publishProject(tree, explorer, catalog): layers = qgislayers.getAllLayers() dlg = PublishProjectDialog(catalog) dlg.exec_() if not dlg.ok: return workspace = dlg.workspace groupName = dlg.groupName overwrite = dlg.overwrite explorer.setProgressMaximum(len(layers), "Publish layers") progress = 0 cat = CatalogWrapper(catalog) for layer in layers: explorer.setProgress(progress) explorer.run(publishLayer, None, [], cat, layer, workspace, overwrite) progress += 1 explorer.setProgress(progress) explorer.resetActivity() groups = qgislayers.getGroups() for group in groups: names = [layer.name() for layer in groups[group][::-1]] try: layergroup = catalog.create_layergroup(group, names, names, getGroupBounds(groups[group])) except ConflictingDataError: layergroup = catalog.get_layergroup(group) layergroup.dirty.update(layers = names, styles = names) explorer.run(catalog.save, "Create layer group '" + group + "'", [], layergroup) if groupName is not None: names = [layer.name() for layer in layers[::-1]] try: layergroup = catalog.create_layergroup(groupName, names, names, getGroupBounds(layers)) except ConflictingDataError: layergroup = catalog.get_layergroup(groupName) layergroup.dirty.update(layers = names, styles = names) explorer.run(catalog.save, "Create global layer group", [], layergroup) tree.findAllItems(catalog)[0].refreshContent(explorer) explorer.resetActivity()
def publishGroup(self, name, destName = None, workspace = None, overwrite = False, overwriteLayers = False): ''' Publishes a group in the given catalog name: the name of the QGIS group to publish. It will also be used as the GeoServer layergroup name workspace: The workspace to add the group to overwrite: if True, it will overwrite a previous group with the specified name, if it exists overwriteLayers: if False, in case a layer in the group is not found in the specified workspace, the corresponding layer from the current QGIS project will be published, but all layers of the group that can be found in the GeoServer workspace will not be published. If True, all layers in the group are published, even if layers with the same name exist in the workspace ''' groups = layers.getGroups() if name not in groups: raise Exception("The specified group does not exist") destName = destName if destName is not None else name gsgroup = self.catalog.get_layergroup(destName) if gsgroup is not None and not overwrite: return group = groups[name] for layer in group: gslayer = self.catalog.get_layer(layer.name()) if gslayer is None or overwriteLayers: self.publishLayer(layer, workspace, True) names = [layer.name() for layer in group] layergroup = self.catalog.create_layergroup(destName, names, names) self.catalog.save(layergroup)
def layersUploaded(): groups = qgislayers.getGroups() for group in groups: names = [layer.name() for layer in groups[group][::-1]] try: layergroup = catalog.create_layergroup(group, names, names, getGroupBounds(groups[group])) except ConflictingDataError: layergroup = catalog.get_layergroups(group)[0] layergroup.dirty.update(layers = names, styles = names) explorer.run(catalog.save, "Create layer group '" + group + "'", [], layergroup) if groupName is not None: names = [layer.name() for layer in layers[::-1]] try: layergroup = catalog.create_layergroup(groupName, names, names, getGroupBounds(layers)) except ConflictingDataError: layergroup = catalog.get_layergroups(groupName)[0] layergroup.dirty.update(layers = names, styles = names) explorer.run(catalog.save, "Create global layer group", [], layergroup) tree.findAllItems(catalog)[0].refreshContent(explorer) explorer.resetActivity()
def publishGroup(self, name, destName=None, workspace=None, overwrite=False, overwriteLayers=False): ''' Publishes a group in the given catalog name: the name of the QGIS group to publish. It will also be used as the GeoServer layergroup name workspace: The workspace to add the group to overwrite: if True, it will overwrite a previous group with the specified name, if it exists overwriteLayers: if False, in case a layer in the group is not found in the specified workspace, the corresponding layer from the current QGIS project will be published, but all layers of the group that can be found in the GeoServer workspace will not be published. If True, all layers in the group are published, even if layers with the same name exist in the workspace ''' groups = layers.getGroups() if name not in groups: raise Exception("The specified group does not exist") destName = destName if destName is not None else name gsgroup = self.catalog.get_layergroup(destName) if gsgroup is not None and not overwrite: return group = groups[name] bounds = None def addToBounds(bbox, bounds): if bounds is not None: bounds = [ min(bounds[0], bbox.xMinimum()), max(bounds[1], bbox.xMaximum()), min(bounds[2], bbox.yMinimum()), max(bounds[3], bbox.yMaximum()) ] else: bounds = [ bbox.xMinimum(), bbox.xMaximum(), bbox.yMinimum(), bbox.yMaximum() ] return bounds for layer in group: gslayer = self.catalog.get_layer(layer.name()) if gslayer is None or overwriteLayers: self.publishLayer(layer, workspace, True) transform = QgsCoordinateTransform( layer.crs(), QgsCoordinateReferenceSystem("EPSG:4326")) bounds = addToBounds( transform.transformBoundingBox(layer.extent()), bounds) names = [layer.name() for layer in group] bounds = (str(bounds[0]), str(bounds[1]), str(bounds[2]), str(bounds[3]), "EPSG:4326") layergroup = self.catalog.create_layergroup(destName, names, names, bounds) self.catalog.save(layergroup)