# How to use epanttools to retrieve coordinates of nodes in a water distribution network

I am working on finding coordinates of nodes in a water distribution network.
I installed epanettools on my computer and I changed epanettools source code according to advices collected from the link: https://www.openepanet.org/Topic/22607/x-y-coordinates-in-c-code.
But when I used code shown below to find coordinates of nodes, no matter what node indexs I entered, it always returned [251,0], [251,0] for x,y coordinates. I spent a long time on this problem, but still now I did not fix this problem.

Code:
x=Node.value_type[‘EN_COORDINATEX’]

print(es.ENgetnodevalue(1,x))

y=Node.value_type[‘EN_COORDINATEY’]

print(es.ENgetnodevalue(1,y))

Output:
[251,0]
[251,0]

If you know the alternative way to find coordinates of nodes in a water distribution network, please tell me how to do that, I appreicate a lot.

An alternative python wrapper that supports EPANET 2.2 and all its associated functions (including getting/setting coordinates) can be found here: https://pypi.org/project/owa-epanet/

The underlying C functions for coordinate manipulation are here: http://wateranalytics.org/EPANET/group___nodes.html#ga17a667c52b139fb5b3ecd44634903466

… and if you are using the python wrapper, be sure to familiarize yourself with some of the tips from the community - I found this comment very helpful: https://github.com/OpenWaterAnalytics/epanet-python/issues/70

Could I ask one more question?
I encountered one problem when installing owa-epanet package, it reported that building windows wheels for Python 3.7 requires Microsoft Visual Studio 2017.

Hi Ziyuan,

Regarding other ways to find coordinates of nodes in a water network, it is quite straightforward using the epanetReader or epanet2toolkit packages for R.

If you have an R installation, the following code should be able to get to the coordinates.

``````install.packages("epanetReader")
net\$Coordinates
``````

Hello,
After running the code: python3 setup.py sdist bdist_wheel, it returned the error:

The source directory

C:/Users/Ziyuan/AppData/Local/Programs/Python/Python37/Lib/site-packages/owa-epanet/EPANET

does not contain a CMakeLists.txt file.

Hi Ziyuan,

Before running that code, you need to run the following command:

git submodule update --init

Hello,
Before running the code: python3 setup.py sdist bdist_wheel, I ran the command shown below:

It still returned the same camke error. Could you please specify how to fix this issue in detail?

Ok,
What happens is that the owa-epanet repository has the EPANET repository embedded through git (or in other words owa-epanet depends on the EPANET project). That is why it is necessary to download both projects. Next I will detail step by step how to achieve this:

`git clone https://github.com/OpenWaterAnalytics/epanet-python.git`

`cd epanet-python/owa-epanet/`

Inside owa-panet there is the EPANET folder and it should be empty (if the folder is empty is when it shows you the error).

`git submodule update --init`

Now the EPANET folder should contain files.

1. Finally, you can build your custom library.

`python3 setup.py sdist bdist_wheel`

#### Complementary information

The steps mentioned above will help to build your custom epanet library in python. This is necessary when you need to add/edit functions to epanet. Because if your intention is to use EPANET 2.2 in python with all its functions, I think the simplest thing is to download the already built project.

`pip install owa-epanet`

Regards

Hello,
I have one more question. Did you mean installing owa-epanet by running the code “pip install owa-epanet” can also add the funcationality of retreiving coordinates of nodes in a water distribution to EPANET?

That’s right, just as @samhatchett mentioned it. To complement his answer I am attaching an example code:

``````import epanet.toolkit as en

epanet_proj = en.createproject()
en.open(ph=epanet_proj, inpFile="example_1.inp", rptFile="example_1.rpt", outFile='example_1.out')
node_index = 1
coords = en.getcoord(epanet_proj, node_index) # coords: array w/ (x,y) coordinates of a node
en.close(ph=epanet_proj)
``````

Thank you very much! You helped me a lot.But could you please me tell me what is out file?

The truth is that I have never used it. But from the documentation.

outFile: the name of a binary output file to be created.

Sorry, I am new to python and epanet. Can I ask you one more question?
If the inpfile (L-Town.inp) and rptfile (L-Town.rpt)are both in C:\Users\Ziyuan\Desktop\BattleDim-project, the code would be
en.open(ph=epanet_proj, inpFile=“L-Town.inp”, rptFile=“L-Town.rpt”, outFile=’’) or

en.open(ph=epanet_proj, inpFile=“C:\Users\Ziyuan\Desktop\BattleDim-project\L-Town.inp”, rptFile=“C:\Users\Ziyuan\Desktop\BattleDim-project\L-Town.rpt”, outFile=’’) ?

Hello Sergio!
Can I ask you one more question? Now I have installed successfully owa-epanet and I have been using this epanet toolkit to solve some practical problems. And now, there is a difficulty that I did not know how to solve. I need to using owa-epanet to find all junctions within the circle with a certain radius. So could you please tell me what code can I use to draw a circle having a radius of 250 meters centered on a junction represented by its coordinates and what code can I use to find all junctions within this circle?