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:
wn (
WaterNetworkModel
|Path
|str
) – the water network model, or a path (strin or path object) to an input fileresults (
SimulationResults
|None
) – simulation results, if any.crs (
QgsCoordinateReferenceSystem
|str
|None
) – The coordinate Reference System of the coordinates in the wntr model / inp file.
- 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 fromwn (
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 modelunits (
str
|None
) – The flow unit set that the layers being read use. If not set it will default to the value inwn.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:
- 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)
-
KY10:
str
# KY10 from kentucky
Dataset from Kentucky Water Research Institute. Slightly modified to eliminate overlapping nodes to make it spatial-compatible.
-
KY10: