QGIS plugin for creating inputs for SWAT+.


The repository holds an Eclipse project. It was created on Windows but runs in Eclipse on Windows and Linux (Ubuntu at least).

There is a Makefile that should provide enough information to build QSWATPlus. It runs on Windows and Linux (Ubuntu at least). There are projects QSWATPlus64 and QSWATPlus32 for Windows 64 and 32 bit respectively, and QSWATPlusLinux64. (QSWATPlusLinux32 could be added easily.)

Build on Windows

64-bit QGIS Desktop does not include Python development files (Python.h and other header files, and python27.lib). So to compile the Cython files it is necessary to install the OSGeo4W Network Installer (64 bit):

  • download the installer osgeo4w-setup-x86_64.exe and run it
  • select Advanced Install
  • include the packages QGIS, GDAL and GRASS GIS (probably the default)
  • select Install from Internet
  • use the default root directory C:\OSGeo4W64, choose All Users if you have admin privileges, create icons if you wish
  • take default local package directory
  • use Direct Connection or as appropriate for your internet connection
  • choose a download site
  • in the Select Packages form you need to include python devel in the Libs section: click on Skip to change it to the version to be installed
  • finish to install.

For the 32 bit version of QGIS you can use the standalone installer.

For both 32 and 64 bit QGIS you will need to add the cython package. To do this, run OSGeo4W.bat in the top QGIS directory as administrator. (Find it in Windows Explorer and right click to get Run as administrator) Then use the command pip install cython. If you get a message Fatal error in launcher: Unable to create process using '"' then use the command python -m pip install cython.

The compilation of the cython files generates some warnings that you can ignore.

You also need to install Microsoft's Visual C++ for Python. Download this (VCForPython27.msi) but instead of just running it immediately (which would install it under your home directory) start a command shell and use the command msixec /i pathtomsi ALLUSERS=1 where pathtomsi is the full path, e.g. C:\Users\<user>\Downloads\VCForPython27.msi. Then it will install in C:\Program Files (x86)\Common Files\Microsoft. You will need administrator privileges to do this.

You also need to install MinGW. MinGW supplies the version of make we need, namely mingw32-make, and also the appropriate versions of utilities like mkdir. We assume it is installed in C:\Mingw.

Environment variables for Windows

The following need to be set to run make assuming VCforP is the path to Visual C++ for Python\9.0, e.g C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0

  • INCLUDE: VCforP\VC\Include;VCforP\WinSDK\Include
  • LIB: VCforP\VC\Lib\amd64;VCforP\WinSDK\Lib\x64 (64 bit) or VCforP\VC\Lib;VCforP\WinSDK\Lib (32 bit)
  • MSSdk: 1
  • OSGEO4W_ROOT: Path to QGIS e.g. C:\OSgeo4W64 (64 bit) or C:\Program Files (x86)\QGIS 2.18 (32 bit)
  • PATH: C:\MinGW\bin;C:\MinGW\msys\1.0\bin;VCforP\VC\bin\amd64;%OSGEO4W_ROOT%\bin (64 bit) or C:\MinGW\bin;C:\MinGW\msys\1.0\bin;VCforP\VC\bin;%OSGEO4W_ROOT%\bin (32 bit)
  • PYTHONHOME: %OSGEO4W_ROOT%\apps\Python27

Build on Linux

The only environment variable required is QSWAT_PROJECT, set to QSWATPlusLinux64.

The project location for make in Eclipse is hard-wired to /media/sf_Public/QSWATPlus. This was used since the QSWATPlus source directory was shared between Windows and a Linux virtual machine. Change this in Eclipse with Run -> External Tools -> External Tools Configuration and change Working Directory as appropriate for the make QSWATPlus64 and clean QSWATPlus programs.