#!/usr/bin/python3 # https://docs.qgis.org/3.18/en/docs/pyqgis_developer_cookbook/intro.html # export LD_LIBRARY_PATH=/usr/lib/qgis # export PYTHONPATH=/usr/share/qgis/python # export LD_LIBRARY_PATH=/usr/share/qgis/python # export PYTHONPATH=$PYTHONPATH:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ForestRoadsNetworksUPLOAD:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/AequilibraE/aequilibrae:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/csv_tools:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/networks:/usr/share/qgis/python:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins:/usr/share/qgis/python/plugins:/usr/lib/python38.zip:/usr/lib/python3.8:/usr/lib/python3.8/lib-dynload:/home/ardo/.local/lib/python3.8/site-packages:/usr/local/lib/python3.8/dist-packages:/usr/lib/python3/dist-packages:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python:/usr/lib/python3/dist-packages/IPython/extensions:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/qgis2web:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/postgisQueryBuilder:/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins/postgisQueryBuilder/extlibs # print(os.environ['PATH']) # print(os.environ) # Lisa plugina metadata.txt faili: # ardo !!!!!!!!!!! # hasProcessingProvider=yes import qgis from qgis.core import * import sys import os # Supply path to qgis install location QgsApplication.setPrefixPath("/usr", True) # Create a reference to the QgsApplication. # Setting the second argument to True enables the GUI. We need # this since this is a custom application. # qgs = QgsApplication([], True) qgs = QgsApplication([], False) # load providers qgs.initQgis() # Append the path where processing plugin can be found sys.path.append('/usr/share/qgis/python/plugins') sys.path.append('/home/ardo/.local/share/QGIS/QGIS3/profiles/default/python/plugins') import processing ## QGIS core algoritmid from processing.core.Processing import Processing Processing.initialize() # qgis.core.QgsApplication.processingRegistry().addProvider(qgis.analysis.QgsNativeAlgorithms()) # Otsi sõna järele mooduleid. otsi = "graph" print("\nLeitud moodulid:") print([x.id() for x in QgsApplication.processingRegistry().algorithms() if otsi in x.id()]) print("\n\n") from processing.tools import * # from qgis.analysis import QgsNativeAlgorithms # QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) import PyQt5 from networks.creer_graphe import CreerGraphe print(CreerGraphe().name()) # print(CreerGraphe().shortHelpString()) # context = QgsProcessingContext() # feedback = QgsProcessingFeedback() ## !!!!!!!!! Niimoodi saab layer'eid lisada QGIS pythoni käsurealt !!!!!!!!!! ## !!!!!!!!!! Väga mugav kasutada kui palju layer'eid vaja lisada !!!!!!!!!!! ## Load postgis layer uri = QgsDataSourceUri() # set host name, port, database name, username and password uri.setConnection("localhost", "6432", "data", "osm", "osm") # set database schema, table name, geometry column and optionally # subset (WHERE clause) uri.setDataSource("minu_teed", "eesti", "geom", "id = 1", "id") vlayer = QgsVectorLayer(uri.uri(False), "my_layer", "postgres") if not vlayer.isValid(): print("Layer failed to load!") else: QgsProject.instance().addMapLayer(vlayer) ## Load gpkg layer path_to_gpkg = os.path.join("/data","gpkg","artiklid","artikkel_210127_valga_matsalu_lahemaa", "links.gpkg") # append the layername part gpkg_countries_layer = path_to_gpkg + "|layername=teedevork_riigiteed" # e.g. gpkg_places_layer = "/usr/share/qgis/resources/data/world_map.gpkg|layername=countries" vlayer2 = QgsVectorLayer(gpkg_countries_layer, "Countries layer", "ogr") if not vlayer2.isValid(): print("Layer failed to load!") else: QgsProject.instance().addMapLayer(vlayer2) # params = { 'IDENT' : 1, 'NOEUDS' : 'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' password=\'osm\' sslmode=disable table=\"minu_teed\".\"aaa1\" (geom)', 'PREFIXE' : '', 'RESEAU' : '/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa/links.gpkg', 'SENS' : '' } params = { 'IDENT' : 1, 'NOEUDS' : vlayer, 'PREFIXE' : '', 'RESEAU' : vlayer2, 'SENS' : '' } # alg = "Networks:build_graph" # processing.run(alg,params) # print(CreerGraphe().createInstance()) print(params['RESEAU']) print("---------------------") print(params['NOEUDS']) print("---------------------") CreerGraphe().initAlgorithm(config={}) # CreerGraphe().processAlgorithm(parameters = params, context=context, feedback=feedback) # CreerGraphe().initAlgorithm(config=None) # for alg in qgs.processingRegistry().algorithms(): # print(alg.id(), "->", alg.displayName()) # processing.run("native:centroids", { 'ALL_PARTS' : False, \ # 'INPUT' : 'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' sslmode=disable authcfg=0i30k14 key=\'id\' srid=3301 type=MultiPolygon checkPrimaryKeyUnicity=\'1\' table="minu_teed"."eesti" (geom)', \ # 'OUTPUT' : 'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' password=\'osm\' sslmode=disable table="minu_teed"."x325" (geom)' }) # processing.run("Networks:build_graph", { 'IDENT' : 1, 'NOEUDS' : 'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' password=\'osm\' sslmode=disable table=\"minu_teed\".\"aaa1\" (geom)', 'PREFIXE' : '', 'RESEAU' : '/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa/links.gpkg', 'SENS' : '' }) # processing.run("qneat3:shortestpathpointtopoint", {'INPUT':'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' sslmode=disable authcfg=0i30k14 key=\'link_id\' srid=3301 type=LineString checkPrimaryKeyUnicity=\'1\' table=\"minu_teed\".\"links\" (geom)','START_POINT':'640381.958323,6519317.618656 [EPSG:3301]','END_POINT':'669499.921921,6528373.950681 [EPSG:3301]','STRATEGY':0,'ENTRY_COST_CALCULATION_METHOD':0,'DIRECTION_FIELD':'','VALUE_FORWARD':'','VALUE_BACKWARD':'','VALUE_BOTH':'','DEFAULT_DIRECTION':2,'SPEED_FIELD':'','DEFAULT_SPEED':5,'TOLERANCE':0,'OUTPUT':'TEMPORARY_OUTPUT'}) # processing.algorithmHelp("qgis:creategrid") processing.algorithmHelp("Networks:build_graph") ## Load postgis layer # uri = QgsDataSourceUri() # # set host name, port, database name, username and password # uri.setConnection("localhost", "6432", "data", "osm", "osm") # # set database schema, table name, geometry column and optionally # # subset (WHERE clause) # uri.setDataSource("minu_teed", "eesti", "geom", "id = 1", "id") # vlayer = QgsVectorLayer(uri.uri(False), "my_layer", "postgres") # print (vlayer) # processing.run("native:buffer", {'INPUT': vlayer, \ # 'OUTPUT': 'postgres://dbname=\'data\' host=localhost port=6432 user=\'osm\' password=\'osm\' sslmode=disable table="minu_teed"."z225" (geom)'}) print('How many algorithms are there? '+ str(len(QgsApplication.processingRegistry().algorithms()))) # print(sys.path) # Finally, exitQgis() is called to remove the # provider and layer registries from memory qgs.exitQgis()