PyQgis API#

This is the fledgling documentation for the work-in-progress API.

Please do not rely on this API. It is likely to change at every release.

Eventually, this API will allow you to use features in PyQGIS scripts and within the python console in QGIS.

Usage#

A simple usage in the qgis console is as follows:

>>> layers = wq.to_qgis(wq.examples.KY10)
>>>
>>> # make edits to layers in qgis then...
>>>
>>> wn = wq.from_qgis(layers)

Note that when using outside of the console it is necessary to import wntrqgis and wntr as follows:

>>> import wntrqgis as wq
>>> import wntr

Reference#

wntrqgis.to_qgis(wn, results=None, crs=None, units=None)#

Write from WNTR network model to QGIS Layers

Parameters:
Return type:

dict[str, QgsVectorLayer] | None

wntrqgis.from_qgis(layers, wn=None, project=None, crs=None, units=None)#

Read from QGIS layers or feature sources to a WNTR WaterNetworkModel

Parameters:
  • layers (dict[ModelLayer, QgsFeatureSource]) – layers to read from

  • wn (WaterNetworkModel | None) – the model that the layers will be read into. Will create a new model if left blank.

  • project (QgsProject | None) – QgsProject instance, if none will use the current QgsProject.instance()

  • crs (QgsCoordinateReferenceSystem | str | None) – all geometry will be transformed into this crs for adding to the water network model

  • units (str | None) – The flow unit set that the layers being read use. If not set it will default to the value in wn.options.hydraulic.inpfile_units.

  • headloss_formula – the headloss formula to use. If not set will defualt to option in the water network model.

Return type:

WaterNetworkModel

class wntrqgis.Example#

A namespace for easily accessing file path of examples

Can be used directly to create a WNTR WaterNetworkModel

The actual value of the path will vary from one system to another.

>>> wntrqgis.Example.KY1  # "C:\Users\....\examples\ky1.inp"
>>> wn = wntr.network.WaterNetworkModel(wntrqgis.Example.KY1)
KY1: str#

KY1 from Kentucky University

KY10: str#

KY10 from kentucky

Dataset from Kentucky Water Research Institute. Slightly modified to eliminate overlapping nodes to make it spatial-compatible.

VALVES: str#

Valves

An example of all the different valve available.