def draw_layer(self, layer_name): displayed = layer_name in self.layers if displayed: if self.layers[layer_name].isValid(): self.layers[layer_name].setCacheImage(None) self.layers[layer_name].triggerRepaint() return # Specify the view and the column to use for the layer self.uri.setDataSource('public', 'measure_formated', layer_name) # Specify the primary key of the entries. For the record, the only unique column is measure_id self.uri.setKeyColumn('measure_id') # Create a layer based on the information previously specified (database and column). The layer is # not yet added to the UI. The layer is a Postgres type layer = QgsVectorLayer(self.uri.uri(), layer_name, 'postgres') # Check if the Layer is valid or not (in case of the column/table/... does not exist if not layer.isValid(): # print("Erreur au chargement de " + layer_name) return # Save the layer into the layer list (reminder: the layer list is useful to refresh all layers when # a notification is received) # Add the created layer to the QGIS project QgsMapLayerRegistry.instance().addMapLayer(layer) self.layers[layer_name] = layer # refresh the layer layer.setCacheImage(None) layer.triggerRepaint()
def loadCsvFiles(self): # 清除画布上的所有图层 # QgsMapLayerRegistry.instance().removeAllMapLayers() # 图标样式,圆,大小设为1 # symbol = QgsMarkerSymbolV2.createSimple({'name':'circle', 'size':'1'}) filepath = self.dlg.lineEdit.text() # 获取文件夹中的所有文件,并过滤不是csv格式的文件 files = os.listdir(filepath) for file in files: if not os.path.isdir(file) and os.path.splitext( file)[1] == '.csv' and not file.startswith('.'): uri = "file:///" + filepath + "/" + file + "?delimiter=%s&crs=epsg:4326&xField=%s&yField=%s" % ( ",", "longitude", "latitude") vlayer = QgsVectorLayer(uri, os.path.splitext(file)[0], "delimitedtext") vlayer.rendererV2().symbol().setSize(1.3) if vlayer.isValid(): QgsMapLayerRegistry.instance().addMapLayer(vlayer)
point=QgsPointXY(point_vertex), neighbors=4, maxDistance=self.__user_distance) if len(pipelines_nearest) > 0: for pipeline_id in pipelines_nearest: pipeline_geometry = self.__idx_pipelines.geometry( pipeline_id) if pipeline_id not in self.__list_visited_pipelines_ids: self.__q_list_pipelines_ids.append(pipeline_id) self.__q_list_pipelines.append(pipeline_geometry) if __name__ == '__main__': path_to_pipeline_layer = "C:\\Users\\jeferson.machado\\Desktop\\QGIS\\shapes\\rede_agua_tracing.shp" path_to_valves_layer = "C:\\Users\\jeferson.machado\\Desktop\\QGIS\\shapes\\registro_manobra.shp" pipelines = QgsVectorLayer(path_to_pipeline_layer, "pipelines_tracing", "ogr") valves = QgsVectorLayer(path_to_valves_layer, "valves_tracing", "ogr") if not pipelines.isValid() or not valves.isValid(): print("Layer failed to load!") else: QgsProject.instance().addMapLayer(pipelines) QgsProject.instance().addMapLayer(valves) pipe_features = QgsProject.instance().mapLayersByName('pipelines_tracing') valves_features = QgsProject.instance().mapLayersByName('valves_tracing') tracing = TracingPipelines(pipe_features, valves_features, debug=True) tracing.run()