Skip to content

WASAC/postgis2epanet

Repository files navigation

PostGIS2EPANET

GitHub Docker Cloud Automated build Docker Image Size (latest by date)

postgis2epanet.py

A simple tool for exporting from a PostGIS table to EPANET INP file (You can find specification of INP file from here) in Rwanda. Assumes Python 3.6+, psycopg2, Shapely, PyShp, light-progress, are already installed and in your PATH.

You can install using pip by requirements.txt as follow.

pip install -r requirements.txt

Or the following is example of installation procedures by pip installation manually.

The following is example of installation procedures by pip installation.

pip install psycopg2
pip install shapely
pip install pyshp
pip install light-progress

Shapely can be downloaded from here. You can chose the file depends on your platform(32bit or 64bit, Python version, etc).

The tool was designed for RWSS department of WASAC in Rwanda.


Example usage:

To export water pipeline networkfrom database rwss_assets as user user to EPANET INP file(.inp) and ESRI Shapefiles for each WSS and Districts:

Before running the script, kindly check the database settings at command line parameters.

python postgis2epanet.py -d yourdatabase -H localhost -p 5432 -u user -w securePassword

If you want to filter only specific dictricts, use -l parameter to list ID of district by comma(,)

python postgis2epanet.py -l 51,52,53

If you want to update elevation from DEM file, use -e parameter to update elevation. The script will not update elevation as default.

python postgis2epanet.py -e

Using Docker

Firstly, please configure docker-compose.yml.

     - db_user=postgres
     - db_password={your password}
     - db_host=host.docker.internal
     - db_port=5432
     - database=rwss_assets
     # If you want to specify districts to be exported, please put here like "51,52,53"
     - districts=

Just execute the below command.

docker-compose up

If you changed any source code, please do the below.

docker-compose up --build

Result of the Script:

A ZIP archive file as below will be created through this script.

20190813_170355_epanet_data.zip

After extracting ZIP archive, you will find other ZIP archive for each Districts as follows.

C:.
    21_Nyanza.zip
    22_Gisagara.zip
    23_Nyaruguru.zip
    24_Huye.zip
    25_Nyamagabe.zip
    26_Ruhango.zip
    27_Muhanga.zip
    28_Kamonyi.zip
    (skip)

Let us extract 24_Huye.zip here, you will see the following files as below. Name of file and folder is ID for water supply system. You can use INP file for EPANET, and you can also use Shapefiles for QGIS plugin.

C:.
│  2041.inp   <- This INP file is for EPANET application
│  20410.inp
│  20411.inp
│  (skip)
│  
├─2041  <- These Shapefiles under WSS_ID folder are for QGIS Plugin.
│      2041_junctions.dbf
│      2041_junctions.shp
│      2041_junctions.shx
│      2041_pipes.dbf
│      2041_pipes.shp
│      2041_pipes.shx
│      2041_reservoirs.dbf
│      2041_reservoirs.shp
│      2041_reservoirs.shx
│      2041_tanks.dbf
│      2041_tanks.shp
│      2041_tanks.shx
│      
├─20410
│      20410_junctions.dbf
│      20410_junctions.shp
│      20410_junctions.shx
│      (skip)

How can we analyse after creating INP file/Shapefiles?

There are 3 options as follows.

  1. Use EPANET application to do analysis. You can directly import INP file to EPANET.
    result

  2. Use QGIS to analyse by QWater Plugin.
    result

    1. You can double-click .qgz file to launch QGIS3.
    2. Install QWater Plugin on QGIS3. See manual of QWater here.
    3. To do settings of layers again.
    4. To do make model again.
    5. If necessary, you can revise the following values for some layers. 1.diameter of pipes (some diameter might be missing) 1.demand of junctions (some no of users might be missing) 1.water level & diameter of tanks (our DB don't have water level and diameter information, so I put the same values as default)
    6. Do analysis by QWater
      result
  3. If you want to import existing INP file to QWater, please use both ImportEpanetInpFiles and QWater Plugin.

    1. Install ImportEpanetInpFiles plugin to import INP file to QGIS3.
    2. You can rename column name as following table.
    3. Install QWater to do analysis.

Table. Renaming columnname for QEPANET from ImportEpanetInpFiles plugin

Layer Old column name New column name
Junctions ID DC_ID
Junctions Demand1 DEMAND
Junctions Pattern1 PATTERN
Pipes ID DC_ID
Pipes NodeFrom NODE1
Pipes NodeTo NODE2
Reservoirs ID DC_ID
Reservoirs Pattern1 PATTERN
Tanks ID DC_ID
Tanks InitLevel INITIALLEV
Tanks MinLevel MINIMUMLEV
Tanks MaxLevel MAXIMUMLEV
Tanks MinVolume MINIMUMVOL
Pumps ID DC_ID
Pumps NodeFrom Initi
Pumps NodeTo NODE2
Valves ID DC_ID
Valves NodeFrom NODE1
Valves NodeTo NODE2

This script was developed by Jin IGARASHI, JICA Expert from The Project for Strengthening Operation and Maintenance of Rural Water Supply Systems in Rwanda (RWASOM).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages