def _check_str_table(self): """ Checks whether a table explicitly named 'social_tenure_relationship' exists in th database. :return: True if the table exists.Otherwise False. :rtype: bool """ return pg_table_exists("social_tenure_relationship", False)
def data_source_exists(self, data_source): """ :param data_source: Data source object containing table/view name and corresponding columns. :type data_source: ComposerDataSource :return: Checks if the table or view specified in the data source exists. :rtype: str """ return pg_table_exists(data_source.name())
def draw_spatial_unit(self, model, clear_existing=True): """ Draw geometry of the given model in the respective local and web views. :param model: Source model whose geometry will be drawn. :type model: object :param clear_existing: Clears any existing features prior to adding the new features. :type clear_existing: bool """ if model is None: msg = QApplication.translate("SpatialPreview", "Data model is empty, the spatial " "unit cannot be rendered.") QMessageBox.critical(self, QApplication.translate("SpatialPreview", "Spatial Unit Preview"), msg) return table_name = model.__class__.__name__.replace(' ', '_').lower() if not pg_table_exists(table_name): msg = QApplication.translate("SpatialPreview", "The spatial unit data source could " "not be retrieved, the feature cannot " "be rendered.") QMessageBox.critical(self, QApplication.translate("SpatialPreview", "Spatial Unit Preview"), msg) return spatial_cols = table_column_names(table_name, True) geom, geom_col = None, "" for sc in spatial_cols: geom = getattr(model, sc) #Use the first non-empty geometry value in the collection if not geom is None: geom_col = sc if geom is None: msg = QApplication.translate("SpatialPreview", "The selected spatial unit does not " "contain a valid geometry.") QMessageBox.critical(self, QApplication.translate("SpatialPreview", "Spatial Unit Preview"), msg) return geom_type, epsg_code = geometryType(table_name, geom_col) if self._overlay_layer is None: self._create_vector_layer(geom_type, epsg_code) #Add layer to map QgsMapLayerRegistry.instance().addMapLayer(self._overlay_layer, False) #Ensure it is always added on top QgsProject.instance().layerTreeRoot().insertLayer(0, self._overlay_layer) if clear_existing: self.delete_local_features() feat, extent = self._add_geom_to_map(geom) #Add spatial unit to web viewer self._web_spatial_loader.add_overlay(model, geom_col) #Increase bounding box by 50%, so that layer slightly zoomed out extent.scale(1.5) #Select feature. Hack for forcing a selection by using inversion self._overlay_layer.invertSelection() self._iface.mapCanvas().setExtent(extent) self._iface.mapCanvas().refresh() self.refresh_canvas_layers() #Need to force event so that layer is shown QCoreApplication.sendEvent(self.local_map, QShowEvent())