def run(self): project_id = self.settings.value("project/id") epsg = self.settings.value("project/epsg") self.project_dir = self.settings.value("project/projectdir") self.project_id = self.settings.value("project/id") locale = QSettings().value('locale/userLocale')[ 0:2] # this is for multilingual legends if locale == "fr": pass elif locale == "it": pass else: locale = "de" if not project_id: self.message_bar.pushCritical( "Error", _translate("VeriSO_PNF_Bestockt", "project_id not set", None)) return QApplication.setOverrideCursor(Qt.WaitCursor) try: group = _translate("VeriSO_PNF_Bahn", "Lagekontrolle - Bestockte Flaeche", None) group += " (" + str(project_id) + ")" layer = { "type": "wms", "title": _translate("VeriSO_PNF_bestockt", "Orthofoto CIR", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.agi.orthofoto.cir", "format": "image/jpeg", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, False, True) layer = { "type": "wms", "title": _translate("VeriSO_PNF_bestockt", "Orthofoto RGB", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.agi.orthofoto_rgb", "format": "image/jpeg", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, True, True) layer = { "type": "wms", "title": _translate("VeriSO_PNF_bestockt", "DTM Hangneigung", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.agi.lidar_2014.hangneigung", "format": "image/jpeg", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, False, True) layer = { "type": "wms", "title": _translate("VeriSO_PNF_bestockt", "DOM", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.agi.lidar_2014.dom_relief", "format": "image/jpeg", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, False, True) layer = { "type": "wms", "title": _translate("VeriSO_PNF_bestockt", "DTM", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.agi.lidar_2014.dtm_relief", "format": "image/jpeg", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, False, True) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_bestockt", "Gemeindegrenze", None), "featuretype": "gemeindegrenzen_gemeindegrenze", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "gemeindegrenze/gemgre_strichliert.qml" } gemgrelayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_bestockt", "BB.BoFlaeche", None), "featuretype": "bodenbedeckung_boflaeche", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "bb/bb_bestockte_ortho.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_bestockt", "EO.Einzelobjekt", None), "featuretype": "einzelobjekte_einzelobjekt", "geom": "", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, #"style": "bodenbedeckung/projboflaeche_color.qml" } eoeolayer = self.layer_loader.load(layer, False, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_bestockt", "EO.Flaechenelement", None), "featuretype": "einzelobjekte_flaechenelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_fl_bestockte_ortho.qml" } eoflayer = self.layer_loader.load(layer, True, False) if eoflayer <> False: self.iface.legendInterface().setLayerVisible(eoflayer, True) if eoeolayer <> False and eoflayer <> False: joinLayerId = eoeolayer.id() for feature in eoeolayer.getFeatures(): joinIdx = feature.fieldNameIndex("ogc_fid") for t_feature in eoflayer.getFeatures(): targetIdx = t_feature.fieldNameIndex("flaechenelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "ogc_fid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "flaechenelement_von" joinInfo.memoryCache = True eoflayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_bestockt", "EO.Linienelement", None), "featuretype": "einzelobjekte_linienelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_li_bestockte_ortho.qml" } eolilayer = self.layer_loader.load(layer, True, False) if eolilayer <> False: self.iface.legendInterface().setLayerVisible(eolilayer, True) if eoeolayer <> False and eolilayer <> False: joinLayerId = eoeolayer.id() joinProvider = eoeolayer.dataProvider() joinProvider.attributeIndexes() joinIdx = joinProvider.fieldNameIndex("ogc_fid") targetProvider = eolilayer.dataProvider() targetProvider.attributeIndexes() targetIdx = targetProvider.fieldNameIndex("linienelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "ogc_fid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "linienelement_von" joinInfo.memoryCache = True eolilayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_bestockt", "EO.Punktelement", None), "featuretype": "einzelobjekte_punktelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_pk_andere.qml" } eopklayer = self.layer_loader.load(layer, True, False) if eopklayer <> False: self.iface.legendInterface().setLayerVisible(eopklayer, True) if eoeolayer <> False and eopklayer <> False: joinLayerId = eoeolayer.id() joinProvider = eoeolayer.dataProvider() joinProvider.attributeIndexes() joinIdx = joinProvider.fieldNameIndex("tid") targetProvider = eopklayer.dataProvider() targetProvider.attributeIndexes() targetIdx = targetProvider.fieldNameIndex("punktelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "tid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "punktelement_von" joinInfo.memoryCache = True eopklayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_bestockt", "Waldplan (AWJF)", None), "params": { "dbhost": "localhost", "dbport": 5432, "dbname": "grundlagen", "dbschema": "sogis" }, "featuretype": "waldplan_awjf", "geom": "wkb_geometry", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "sogis/waldplan_awjf.qml" } vlayer = self.layer_loader.load(layer, False, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_bestockt", "LI.Liegenschaft", None), "featuretype": "liegenschaften_liegenschaft", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "li/liegenschaft_ortho.qml" } vlayer = self.layer_loader.load(layer, False, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_bestockt", "TS-Einteilung", None), "featuretype": "tseinteilung_toleranzstufe", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "ts/ts_einteilung.qml" } vlayer = self.layer_loader.load(layer, False, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_bestockt", "Kontrollraster (Planeinteilung)", None), "featuretype": "t_kontrollraster_plan_bestockt", "geom": "the_geom", "key": "ogc_fid", "sql": "", "readonly": False, "group": group, "style": "kontrollraster/kontrollraster.qml" } vlayer = self.layer_loader.load(layer, False, False) if vlayer <> False: self.iface.legendInterface().setLayerVisible(vlayer, False) provider = vlayer.dataProvider() provider.attributeIndexes() ogc_fid_idx = provider.fieldNameIndex("ogc_fid") vlayer.setEditorWidgetV2(0, "Hidden") plannummer_idx = provider.fieldNameIndex("plannummer") vlayer.setEditorWidgetV2(2, "Hidden") kontrolliert_idx = provider.fieldNameIndex("kontrolliert") vlayer.setEditorWidgetV2(1, "CheckBox") vlayer.setEditorWidgetV2Config( 1, { 'fieldEditable': "1", 'UncheckedState': 'f', 'CheckedState': 't' }) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_bestockt", "Kontrollraster", None), "featuretype": "t_kontrollraster_bestockte_500", "geom": "the_geom", "key": "ogc_fid", "sql": "", "readonly": False, "group": group, "style": "kontrollraster/kontrollraster.qml" } vlayer = self.layer_loader.load(layer, True, False) if vlayer <> False: self.iface.legendInterface().setLayerVisible(vlayer, True) provider = vlayer.dataProvider() provider.attributeIndexes() ogc_fid_idx = provider.fieldNameIndex("ogc_fid") vlayer.setEditorWidgetV2(0, "Hidden") kontrolliert_idx = provider.fieldNameIndex("kontrolliert") vlayer.setEditorWidgetV2(1, "CheckBox") vlayer.setEditorWidgetV2Config( 1, { 'fieldEditable': "1", 'UncheckedState': 'f', 'CheckedState': 't' }) if gemgrelayer: rect = gemgrelayer.extent() self.iface.mapCanvas().setExtent(rect) self.iface.mapCanvas().refresh() except Exception: QApplication.restoreOverrideCursor() exc_type, exc_value, exc_traceback = sys.exc_info() self.message_bar.pushMessage( "Error", str(traceback.format_exc(exc_traceback)), level=QgsMessageBar.CRITICAL, duration=0) QApplication.restoreOverrideCursor()
def run(self): project_id = self.settings.value("project/id") epsg = self.settings.value("project/epsg") self.project_dir = self.settings.value("project/projectdir") self.project_id = self.settings.value("project/id") locale = QSettings().value('locale/userLocale')[ 0:2] # this is for multilingual legends if locale == "fr": pass elif locale == "it": pass else: locale = "de" if not project_id: self.message_bar.pushCritical( "Error", _translate("VeriSO_PNF_Seltene_Objekte", "project_id not " "set", None)) return QApplication.setOverrideCursor(Qt.WaitCursor) try: group = _translate("VeriSO_PNF_Seltene_Objekte", "Checklayer - Seltene Objekte", None) group += " (" + str(project_id) + ")" layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "BB.BoFlaeche", None), "featuretype": "bodenbedeckung_boflaeche", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "bb/bb_bb_plan.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "EO.Einzelobjekt", None), "featuretype": "einzelobjekte_einzelobjekt", "geom": "", "key": "ogc_fid", "sql": "", "readonly": True, "group": group } eoeolayer = self.layer_loader.load(layer, False, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "EO.Flaechenelement", None), "featuretype": "einzelobjekte_flaechenelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_fl_bb_plan.qml" } eoflayer = self.layer_loader.load(layer, True, False) if eoflayer <> False: self.iface.legendInterface().setLayerVisible(eoflayer, True) if eoeolayer <> False and eoflayer <> False: joinLayerId = eoeolayer.id() for feature in eoeolayer.getFeatures(): joinIdx = feature.fieldNameIndex("ogc_fid") for t_feature in eoflayer.getFeatures(): targetIdx = t_feature.fieldNameIndex("flaechenelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "ogc_fid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "flaechenelement_von" joinInfo.memoryCache = True eoflayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "EO.Linienelement", None), "featuretype": "einzelobjekte_linienelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_li_bb_plan.qml" } eolilayer = self.layer_loader.load(layer, True, False) if eolilayer <> False: self.iface.legendInterface().setLayerVisible(eolilayer, True) if eoeolayer <> False and eolilayer <> False: joinLayerId = eoeolayer.id() joinProvider = eoeolayer.dataProvider() joinProvider.attributeIndexes() joinIdx = joinProvider.fieldNameIndex("ogc_fid") targetProvider = eolilayer.dataProvider() targetProvider.attributeIndexes() targetIdx = targetProvider.fieldNameIndex("linienelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "ogc_fid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "linienelement_von" joinInfo.memoryCache = True eolilayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "Li.Liegenschaft", None), "featuretype": "liegenschaften_liegenschaft", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "li/liegenschaft_ortho.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "BB.Boeschungsbauwerk", None), "featuretype": "t_boeschungbwerke", "geom": "the_geom", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "checks/checklayer_punkt.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "EO.Brunnen", None), "featuretype": "t_brunnen", "geom": "the_geom", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "checks/checklayer_punkt.qml" } vlayer = self.layer_loader.load(layer, True, False) QApplication.restoreOverrideCursor() # Export feature count in excel file. try: settings = QSettings("CatAIS", "VeriSO") module_name = settings.value("project/appmodule") provider = settings.value("project/provider") dbhost = settings.value("project/dbhost") db_port = settings.value("project/dbport") dbname = settings.value("project/dbname") dbschema = settings.value("project/dbschema") dbuser = settings.value("project/dbuser") dbpwd = settings.value("project/dbpwd") projectId = settings.value("project/id") project_dir = settings.value("project/projectdir") db = QSqlDatabase.addDatabase("QPSQL", "SelteneObjekte") db.setDatabaseName(dbname) db.setHostName(dbhost) db.setUserName(dbuser) db.setPassword(dbpwd) if db.open() == False: QMessageBox.critical( None, "QGeoApp", QCoreApplication.translate( "QGeoApp", "Could not open database:\n") + str(db.lastError().driverText())) return filename = QDir.convertSeparators( QDir.cleanPath( os.path.join(project_dir, "seltene_objekte.xlsx"))) # Create excel file. wb = pycel.Workbook(filename) #wb.country_code = 41 style1 = wb.add_format({'bold': True}) style2 = wb.add_format({'italic': True}) # Bodenbedeckung sql = "SELECT CASE WHEN anz IS NULL THEN 0 ELSE anz END, bb_art.itfcode as art, bb_art.ilicode as art_txt " sql += "FROM (" sql += "SELECT count(art) as anz, art_txt, art" sql += " FROM " + dbschema + ".bodenbedeckung_boflaeche" sql += " WHERE art IN (7, 9, 19, 20, 21, 22, 30, 33, 35, 36, 37, 38, 39, 40)" sql += " GROUP BY art, art_txt" sql += ") bb" sql += " FULL JOIN " + dbschema + ".bodenbedeckung_bbart bb_art ON bb_art.itfcode = bb.art" sql += " WHERE bb_art.itfcode IN (7, 9, 19, 20, 21, 22, 30, 33, 35, 36, 37, 38, 39, 40)" sql += " ORDER BY bb_art.itfcode;" query = db.exec_(sql) if query.isActive() == False: QMessageBox.critical( None, "QGeoApp", QCoreApplication.translate( "QGeoApp", "Error occured while fetching data informations.")) return ws = wb.add_worksheet(u'BB seltene Objekte') ws.paper_size_code = 8 ws.print_centered_vert = False ws.print_centered_horz = False ws.top_margin = 1.0 ws.left_margin = 1.0 ws.bottom_margin = 1.0 ws.portrait = True ws.write(0, 0, str("BB seltene Objekte: "), style1) ws.write(0, 1, str(projectId)) ws.write(2, 0, str("Art")) ws.write(2, 1, str("Art-Text")) ws.write(2, 2, str("Anzahl")) i = 0 record = query.record() anz_index = record.indexOf("anz") art_index = record.indexOf("art") art_txt_index = record.indexOf("art_txt") while query.next(): anz = str(query.value(anz_index)) art = str(query.value(art_index)) art_txt = str(query.value(art_txt_index)) ws.write(3 + i, 0, art) ws.write(3 + i, 1, art_txt) ws.write(3 + i, 2, anz) i += 1 # Einzelobjekte sql = "SELECT CASE WHEN anz IS NULL THEN 0 ELSE anz END, eo_art.itfcode as art, eo_art.ilicode as art_txt" sql += " FROM" sql += " (" sql += " SELECT count(art) as anz, art_txt, art" sql += " FROM " + dbschema + ".einzelobjekte_einzelobjekt" sql += " WHERE art IN (9, 14, 15, 16, 17, 18, 23, 30, 31, 35, 36, 37, 38, 40, 42)" sql += " GROUP BY art, art_txt" sql += ") eo" sql += " FULL JOIN " + dbschema + ".einzelobjekte_eoart eo_art ON eo_art.itfcode = eo.art" sql += " WHERE eo_art.itfcode IN (9, 14, 15, 16, 17, 18, 23, 30, 31, 35, 36, 37, 38, 40, 42)" sql += " ORDER BY eo_art.itfcode" query = db.exec_(sql) if query.isActive() == False: QMessageBox.critical( None, "QGeoApp", QCoreApplication.translate( "QGeoApp", "Error occured while fetching data informations.")) return ws = wb.add_worksheet(u'EO seltene Objekte') ws.paper_size_code = 8 ws.print_centered_vert = False ws.print_centered_horz = False ws.top_margin = 1.0 ws.left_margin = 1.0 ws.bottom_margin = 1.0 ws.portrait = True ws.write(0, 0, str("EO seltene Objekte: "), style1) ws.write(0, 1, projectId) ws.write(2, 0, str("Art")) ws.write(2, 1, str("Art-Text")) ws.write(2, 2, str("Anzahl")) i = 0 record = query.record() while query.next(): anz = str(query.value(record.indexOf("anz"))) art = str(query.value(record.indexOf("art"))) art_txt = str(query.value(record.indexOf("art_txt"))) ws.write(3 + i, 0, art) ws.write(3 + i, 1, art_txt) if int(anz) > 0: ws.write(3 + i, 2, anz, style1) else: ws.write(3 + i, 2, anz) i += 1 #file = QDir.convertSeparators(QDir.cleanPath(project_dir + os.sep + "seltene_objekte.xls")) try: wb.close() QMessageBox.information( None, "", QCoreApplication.translate( "QGeoAppModule.PNF", "File written:\n") + filename) except IOError: QMessageBox.warning( None, "", QCoreApplication.translate( "QGeoAppModule.PNF", "File <b>not</b> written!<br>") + filename) return db.close() except: QMessageBox.critical( None, "QGeoApp", QCoreApplication.translate( "QGeoApp", "Error exporting data from database to excel.")) except Exception: QApplication.restoreOverrideCursor() exc_type, exc_value, exc_traceback = sys.exc_info() self.message_bar.pushMessage( "Error", str(traceback.format_exc(exc_traceback)), level=QgsMessageBar.CRITICAL, duration=0) QApplication.restoreOverrideCursor()
def run(self): project_id = self.settings.value("project/id") epsg = self.settings.value("project/epsg") self.project_dir = self.settings.value("project/projectdir") self.project_id = self.settings.value("project/id") locale = QSettings().value('locale/userLocale')[ 0:2] # this is for multilingual legends if locale == "fr": pass elif locale == "it": pass else: locale = "de" if not project_id: self.message_bar.pushCritical( "Error", _translate("VeriSO_PNF_Seltene_Objekte", "project_id not set", None)) return QApplication.setOverrideCursor(Qt.WaitCursor) try: group = _translate("VeriSO_PNF_Seltene_Objekte", "Lagekontrolle - Seltene Objekte", None) group += " (" + str(project_id) + ")" layer = { "type": "wms", "title": _translate("VeriSO_PNF_Seltene_Objekte", "Orthofoto CIR", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.agi.orthofoto.cir", "format": "image/png", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, False, True) layer = { "type": "wms", "title": _translate("VeriSO_PNF_Seltene_Objekte", "Orthofoto RGB", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.agi.orthofoto_rgb", "format": "image/png", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, True, True) layer = { "type": "wms", "title": _translate("VeriSO_PNF_Seltene_Objekte", "DTM Hangneigung", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.agi.lidar_2014.hangneigung", "format": "image/jpeg", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, False, True) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "Gemeindegrenze", None), "featuretype": "gemeindegrenzen_gemeindegrenze", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "gemeindegrenze/gemgre_strichliert.qml" } gemgrelayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "BB.BoFlaeche", None), "featuretype": "bodenbedeckung_boflaeche", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "bb/bb_seltene_objekte_ortho.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "EO.Einzelobjekt", None), "featuretype": "einzelobjekte_einzelobjekt", "geom": "", "key": "ogc_fid", "sql": "", "readonly": True, "group": group } eoeolayer = self.layer_loader.load(layer, False, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "EO.Flaechenelement", None), "featuretype": "einzelobjekte_flaechenelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_fl_seltene_objekte_ortho.qml" } eoflayer = self.layer_loader.load(layer, True, False) if eoflayer <> False: self.iface.legendInterface().setLayerVisible(eoflayer, True) if eoeolayer <> False and eoflayer <> False: joinLayerId = eoeolayer.id() for feature in eoeolayer.getFeatures(): joinIdx = feature.fieldNameIndex("ogc_fid") for t_feature in eoflayer.getFeatures(): targetIdx = t_feature.fieldNameIndex("flaechenelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "ogc_fid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "flaechenelement_von" joinInfo.memoryCache = True eoflayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "EO.Linienelement", None), "featuretype": "einzelobjekte_linienelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_li_seltene_objekte_ortho.qml" } eolilayer = self.layer_loader.load(layer, True, False) if eolilayer <> False: self.iface.legendInterface().setLayerVisible(eolilayer, True) if eoeolayer <> False and eolilayer <> False: joinLayerId = eoeolayer.id() joinProvider = eoeolayer.dataProvider() joinProvider.attributeIndexes() joinIdx = joinProvider.fieldNameIndex("ogc_fid") targetProvider = eolilayer.dataProvider() targetProvider.attributeIndexes() targetIdx = targetProvider.fieldNameIndex("linienelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "ogc_fid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "linienelement_von" joinInfo.memoryCache = True eolilayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "EO.Punktelement", None), "featuretype": "einzelobjekte_punktelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_pk_seltene_objekte_ortho.qml" } eopklayer = self.layer_loader.load(layer, True, False) if eopklayer <> False: self.iface.legendInterface().setLayerVisible(eopklayer, True) if eoeolayer <> False and eopklayer <> False: joinLayerId = eoeolayer.id() joinProvider = eoeolayer.dataProvider() joinProvider.attributeIndexes() joinIdx = joinProvider.fieldNameIndex("ogc_fid") targetProvider = eopklayer.dataProvider() targetProvider.attributeIndexes() targetIdx = targetProvider.fieldNameIndex("punktelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "ogc_fid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "punktelement_von" joinInfo.memoryCache = True eopklayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "Abbaustellen (AfU)", None), "params": { "dbhost": "localhost", "dbport": 5432, "dbname": "grundlagen", "dbschema": "sogis" }, "featuretype": "abbaustellen_afu", "geom": "wkb_geometry", "key": "gid", "sql": "", "readonly": True, "group": group, "style": "sogis/abbaustellen_afu.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "Flachmoor (AfU)", None), "params": { "dbhost": "localhost", "dbport": 5432, "dbname": "grundlagen", "dbschema": "sogis" }, "featuretype": "flachmoor_afu", "geom": "wkb_geometry", "key": "gid", "sql": "", "readonly": True, "group": group, "style": "sogis/flachmoor_afu.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "Freileitungen (ARP)", None), "params": { "dbhost": "localhost", "dbport": 5432, "dbname": "grundlagen", "dbschema": "sogis" }, "featuretype": "freileitungen_arp", "geom": "wkb_geometry", "key": "gid", "sql": "", "readonly": True, "group": group, "style": "sogis/freileitungen_arp.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Seltene_Objekte", "LI.Liegenschaft", None), "featuretype": "liegenschaften_liegenschaft", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "li/liegenschaft_ortho.qml" } vlayer = self.layer_loader.load(layer, False, False) layer = { "type": "wms", "title": _translate("VeriSO_PNF_Seltene_Objekte", "Flachmoor (BAFU)", None), "url": "http://wms.geo.admin.ch/", "layers": "ch.bafu.bundesinventare-flachmoore", "format": "image/png", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "wms", "title": _translate("VeriSO_PNF_Seltene_Objekte", "Hochmoor (BAFU)", None), "url": "http://wms.geo.admin.ch/", "layers": "ch.bafu.bundesinventare-hochmoore", "format": "image/png", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "wms", "title": _translate("VeriSO_PNF_Seltene_Objekte", "Mobilfunkantennen GSM", None), "url": "http://wms.geo.admin.ch/", "layers": "ch.bakom.mobil-antennenstandorte-gsm", "format": "image/png", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "wms", "title": _translate("VeriSO_PNF_Seltene_Objekte", "Mobilfunkantennen UMTS", None), "url": "http://wms.geo.admin.ch/", "layers": "ch.bakom.mobil-antennenstandorte-umts", "format": "image/png", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "wms", "title": _translate("VeriSO_PNF_Seltene_Objekte", "Radio- und Fernsehsender", None), "url": "http://wms.geo.admin.ch/", "layers": "ch.bakom.radio-fernsehsender", "format": "image/png", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, True, False) if gemgrelayer: rect = gemgrelayer.extent() self.iface.mapCanvas().setExtent(rect) self.iface.mapCanvas().refresh() except Exception: QApplication.restoreOverrideCursor() exc_type, exc_value, exc_traceback = sys.exc_info() self.message_bar.pushMessage( "Error", str(traceback.format_exc(exc_traceback)), level=QgsMessageBar.CRITICAL, duration=0) QApplication.restoreOverrideCursor()
def run(self): project_id = self.settings.value("project/id") epsg = self.settings.value("project/epsg") self.project_dir = self.settings.value("project/projectdir") self.project_id = self.settings.value("project/id") locale = QSettings().value('locale/userLocale')[ 0:2] # this is for multilingual legends if locale == "fr": pass elif locale == "it": pass else: locale = "de" if not project_id: self.message_bar.pushCritical( "Error", _translate("VeriSO_PNF_Bestockt", "project_id not " "set", None)) return QApplication.setOverrideCursor(Qt.WaitCursor) try: group = _translate("VeriSO_PNF_Bestockt", "Checklayer - Bestockte Flaeche", None) group += " (" + str(project_id) + ")" layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Bestockt", "BB.BoFlaeche", None), "featuretype": "bodenbedeckung_boflaeche", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "bb/bb_bestockte_bbplan.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Bestockt", "EO.Einzelobjekt", None), "featuretype": "einzelobjekte_einzelobjekt", "geom": "", "key": "ogc_fid", "sql": "", "readonly": True, "group": group } eoeolayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Bestockt", "EO.Flaechenelement", None), "featuretype": "einzelobjekte_flaechenelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_fl_bestockte_ortho.qml" } eoflayer = self.layer_loader.load(layer, True, False) if eoflayer <> False: self.iface.legendInterface().setLayerVisible(eoflayer, True) if eoeolayer <> False and eoflayer <> False: joinLayerId = eoeolayer.id() joinProvider = eoeolayer.dataProvider() joinProvider.attributeIndexes() joinIdx = joinProvider.fieldNameIndex("ogc_fid") targetProvider = eoflayer.dataProvider() targetProvider.attributeIndexes() targetIdx = targetProvider.fieldNameIndex( "flaechenelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "ogc_fid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "flaechenelement_von" joinInfo.memoryCache = True eoflayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Bestockt", "EO.Linienelement", None), "featuretype": "einzelobjekte_linienelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_li_bestockte_ortho.qml" } eolilayer = self.layer_loader.load(layer, True, False) if eolilayer <> False: self.iface.legendInterface().setLayerVisible(eolilayer, True) if eoeolayer <> False and eolilayer <> False: joinLayerId = eoeolayer.id() joinProvider = eoeolayer.dataProvider() joinProvider.attributeIndexes() joinIdx = joinProvider.fieldNameIndex("ogc_fid") targetProvider = eolilayer.dataProvider() targetProvider.attributeIndexes() targetIdx = targetProvider.fieldNameIndex("linienelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "ogc_fid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "linienelement_von" joinInfo.memoryCache = True eolilayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Bestockt", "LI.Liegenschaft", None), "featuretype": "liegenschaften_liegenschaft", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "li/liegenschaft_ortho.qml" } vlayer = self.layer_loader.load(layer, False, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Bestockt", "BB.Wald in TS2", None), "featuretype": "t_wald_in_ts2", "geom": "the_geom", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "checks/checklayer_punkt.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Bestockt", "EO.schmale_bestockte_Flaeche", None), "featuretype": "t_schm_best_flaeche", "geom": "the_geom", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "checks/checklayer_polygon.qml" } vlayer = self.layer_loader.load(layer, True, False) except Exception: QApplication.restoreOverrideCursor() exc_type, exc_value, exc_traceback = sys.exc_info() self.message_bar.pushMessage( "Error", str(traceback.format_exc(exc_traceback)), level=QgsMessageBar.CRITICAL, duration=0) QApplication.restoreOverrideCursor()
def run(self): project_id = self.settings.value("project/id") epsg = self.settings.value("project/epsg") self.project_dir = self.settings.value("project/projectdir") self.project_id = self.settings.value("project/id") locale = QSettings().value('locale/userLocale')[ 0:2] # this is for multilingual legends if locale == "fr": pass elif locale == "it": pass else: locale = "de" if not project_id: self.message_bar.pushCritical("Error", _translate("VeriSO_PNF_Gewaesser", "project_id not set", None) ) return QApplication.setOverrideCursor(Qt.WaitCursor) try: group = _translate("VeriSO_PNF_Gewaesser", "Lagekontrolle - Gewaesser", None) group += " (" + str(project_id) + ")" layer = { "type": "wms", "title": _translate("VeriSO_PNF_Gewaesser", "Orthofoto CIR", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.agi.orthofoto.cir", "format": "image/jpeg", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, False, True) layer = { "type": "wms", "title": _translate("VeriSO_PNF_Gewaesser", "Orthofoto RGB", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.agi.orthofoto_rgb", "format": "image/jpeg", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, True, True) layer = { "type": "wms", "title": _translate("VeriSO_PNF_Gewaesser", "DTM Hangneigung", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.agi.lidar_2014.hangneigung", "format": "image/jpeg", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, False, True) layer = { "type": "wms", "title": _translate("VeriSO_PNF_Gewaesser", "DTM", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.agi.lidar_2014.dtm", "format": "image/jpeg", "crs": "EPSG:" + str(epsg), "group": group } vlayer = self.layer_loader.load(layer, False, True) layer = { "type": "wms", "title": _translate("VeriSO_PNF_Gewaesser", "Gewässer", None), "url": "https://geo.so.ch/wms?", "layers": "ch.so.afu.fliessgewaesser.netz", "format": "image/png", "crs": "EPSG:" + str(epsg), "group": group, "style": "gewaesser/gewisso.qml" } vlayer = self.layer_loader.load(layer, True, True) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Gewaesser", "Gemeindegrenze", None), "featuretype": "gemeindegrenzen_gemeindegrenze", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "gemeindegrenze/gemgre_strichliert.qml" } gemgrelayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Gewaesser", "BB.BoFlaeche", None), "featuretype": "bodenbedeckung_boflaeche", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "bb/bb_gewaesser_ortho.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Gewaesser", "EO.Einzelobjekt", None), "featuretype": "einzelobjekte_einzelobjekt", "geom": "", "key": "ogc_fid", "sql": "", "readonly": True, "group": group } eoeolayer = self.layer_loader.load(layer, False, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Gewaesser", "EO.Flaechenelement", None), "featuretype": "einzelobjekte_flaechenelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_fl_gewaesser_ortho.qml" } eoflayer = self.layer_loader.load(layer, True, False) if eoflayer <> False: self.iface.legendInterface().setLayerVisible(eoflayer, True) if eoeolayer <> False and eoflayer <> False: joinLayerId = eoeolayer.id() for feature in eoeolayer.getFeatures(): joinIdx=feature.fieldNameIndex("ogc_fid") for t_feature in eoflayer.getFeatures(): targetIdx=t_feature.fieldNameIndex("flaechenelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "ogc_fid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "flaechenelement_von" joinInfo.memoryCache = True eoflayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Gewaesser", "EO.Linienelement", None), "featuretype": "einzelobjekte_linienelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_li_gewaesser_ortho.qml" } eolilayer = self.layer_loader.load(layer, True, False) if eolilayer <> False: self.iface.legendInterface().setLayerVisible(eolilayer, True) if eoeolayer <> False and eolilayer <> False: joinLayerId = eoeolayer.id() joinProvider = eoeolayer.dataProvider() joinProvider.attributeIndexes() joinIdx = joinProvider.fieldNameIndex("ogc_fid") targetProvider = eolilayer.dataProvider() targetProvider.attributeIndexes() targetIdx = targetProvider.fieldNameIndex("linienelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "ogc_fid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "linienelement_von" joinInfo.memoryCache = True eolilayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Gewaesser", "EO.Punktelement", None), "featuretype": "einzelobjekte_punktelement", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_pk_andere.qml" } eopklayer = self.layer_loader.load(layer, True, False) if eopklayer <> False: self.iface.legendInterface().setLayerVisible(eopklayer, True) if eoeolayer <> False and eopklayer <> False: joinLayerId = eoeolayer.id() joinProvider = eoeolayer.dataProvider() joinProvider.attributeIndexes() joinIdx = joinProvider.fieldNameIndex("ogc_fid") targetProvider = eopklayer.dataProvider() targetProvider.attributeIndexes() targetIdx = targetProvider.fieldNameIndex("punktelement_von") joinInfo = QgsVectorJoinInfo() joinInfo.joinFieldIndex = joinIdx joinInfo.joinFieldName = "ogc_fid" joinInfo.joinLayerId = joinLayerId joinInfo.targetFieldIndex = targetIdx joinInfo.targetFieldName = "punktelement_von" joinInfo.memoryCache = True eopklayer.addJoin(joinInfo) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Gewaesser", "BB.Symbole", None), "featuretype": "v_bodenbedeckung_boflaechesymbol", "geom": "pos", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "bb/bb_symbole.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Gewaesser", "EO.Symbole", None), "featuretype": "t_eo_symbole", "geom": "pos", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_symbole.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Gewaesser", "LI.Liegenschaft", None), "featuretype": "liegenschaften_liegenschaft", "geom": "geometrie", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "li/liegenschaft_ortho.qml" } vlayer = self.layer_loader.load(layer, False, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Gewaesser", "BB.Objektname", None), "featuretype": "v_bb_objektnamen", "geom": "pos", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "bb/bb_objektnamen.qml" } vlayer = self.layer_loader.load(layer, True, False) layer = { "type": "postgres", "title": _translate("VeriSO_PNF_Gewaesser", "EO.Objektname", None), "featuretype": "v_eo_objektnamen", "geom": "pos", "key": "ogc_fid", "sql": "", "readonly": True, "group": group, "style": "eo/eo_objektnamen.qml" } vlayer = self.layer_loader.load(layer, True, False) if gemgrelayer: rect = gemgrelayer.extent() self.iface.mapCanvas().setExtent(rect) self.iface.mapCanvas().refresh() except Exception: QApplication.restoreOverrideCursor() exc_type, exc_value, exc_traceback = sys.exc_info() self.message_bar.pushMessage("Error", str( traceback.format_exc(exc_traceback)), level=QgsMessageBar.CRITICAL, duration=0) QApplication.restoreOverrideCursor()