Skip to content

Commit

Permalink
Version 1.7.1
Browse files Browse the repository at this point in the history
For QGIS >= 3.34.5 using Python 3.12
  • Loading branch information
ChrisWGeorge committed May 14, 2024
1 parent e5f067b commit 303734d
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 35 deletions.
3 changes: 3 additions & 0 deletions QSWAT3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export SUBDIR
ifeq ($(QSWAT_PROJECT), QSWAT3)
METADATA = metadata32.txt
BAT_FILES = runnose32.bat runtestn32.bat runtestpoly32.bat runcovernose.bat
else ifeq ($(QSWAT_PROJECT), QSWAT3_12)
METADATA = metadata3_12.txt
BAT_FILES = runnose.bat runtestn.bat runtestpoly.bat runHUC.bat runHUC64.bat runTNC.bat runCatchments.bat runWeather.bat runContinentChange.bat
else ifeq ($(QSWAT_PROJECT), QSWAT3_9)
METADATA = metadata3_9.txt
BAT_FILES = runnose.bat runtestn.bat runtestpoly.bat runHUC.bat runHUC64.bat runTNC.bat runCatchments.bat runWeather.bat runContinentChange.bat
Expand Down
7 changes: 7 additions & 0 deletions QSWAT3/QSWAT/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ else ifeq ($(QSWAT_PROJECT), QSWAT3_9)
COMPILER = msvc
PYD_FILES = $(PYX_FILES:.pyx=.cp39-win_amd64.pyd)
EXTRAPACKAGES = imageio
else ifeq ($(QSWAT_PROJECT), QSWAT3_12)
COMPILER = msvc
PYD_FILES = $(PYX_FILES:.pyx=.cp312-win_amd64.pyd)
EXTRAPACKAGES = imageio
else ifeq ($(QSWAT_PROJECT), QSWAT3_64)
COMPILER = msvc
PYD_FILES = $(PYX_FILES:.pyx=.cp37-win_amd64.pyd)
Expand Down Expand Up @@ -92,6 +96,9 @@ compile: $(RESOURCE_FILES) $(PYD_FILES)

%.cp39-win_amd64.pyd : %.pyx
python setuppyx3_9.py build_ext --inplace --compiler=$(COMPILER)

%.cp312-win_amd64.pyd : %.pyx
$(OSGEO4W_ROOT)\apps\Python312\python setuppyx3_12.py build_ext --inplace --compiler=$(COMPILER)

#%_rc.py : %.qrc
# pyrcc5 -o $*_rc.py $<
Expand Down
2 changes: 1 addition & 1 deletion QSWAT3/QSWAT/QSWATTopology.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ def makeStreamOutletThresholds(self, gv: Any, root: QgsLayerTreeGroup) -> int:

@staticmethod
def burnStream(streamFile: str, demFile: str, burnFile: str, verticalFactor: float, burnDepth: float, isBatch: bool) -> None:
"""Create as burnFile a copy of demFile with points on lines streamFile reduced in height by 50 metres."""
"""Create as burnFile a copy of demFile with points on lines streamFile reduced in height by nurnDepth metres."""
# use vertical factor to convert from metres to vertical units of DEM
demReduction = burnDepth / verticalFactor # TODO: may want to change this value or allow user to change
assert not os.path.exists(burnFile)
Expand Down
2 changes: 1 addition & 1 deletion QSWAT3/QSWAT/delineation.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def runTauDEM(self, outletFile: Optional[str], makeWshed: bool) -> None:
self.progress('Burning streams ...')
#burnRasterFile = self.streamToRaster(demLayer, burnFile, root)
#processing.runalg('saga:burnstreamnetworkintodem', demFile, burnRasterFile, burnMethod, burnEpsilon, burnedFile)
burnDepth = 25.0 if self._gv.fromGRASS else 50.0
burnDepth = Parameters._GRASSBURNINDEPTH if self._gv.fromGRASS else Parameters._BURNINDEPTH
QSWATTopology.burnStream(burnFile, demFile, burnedDemFile, self._gv.verticalFactor, burnDepth, self._gv.isBatch)
if not os.path.exists(burnedDemFile):
self.cleanUp(-1)
Expand Down
4 changes: 4 additions & 0 deletions QSWAT3/QSWAT/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ class Parameters:
# maximum slope for RICE
_RICEMAXSLOPE = 0.005

# amount in metres to burn in streams (reduce height of DEM)
_BURNINDEPTH = 50
_GRASSBURNINDEPTH = 25

# TNC data
TNCExtents = {'CentralAmerica': (-92.3, 7.2, -59.4, 23.2),
'NorthAmerica': (-178.3, 0, -29.9, 60.0),
Expand Down
19 changes: 11 additions & 8 deletions QSWAT3/QSWAT/qswat.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class QSwat(QObject):
"""QGIS plugin to prepare geographic data for SWAT Editor."""
_SWATEDITORVERSION = Parameters._SWATEDITORVERSION

__version__ = '1.6.6'
__version__ = '1.7.1'

def __init__(self, iface: Any) -> None:
"""Constructor."""
Expand Down Expand Up @@ -604,13 +604,16 @@ def demProcessed(self) -> bool:
QSWATUtils.loginfo('demProcessed failed: no DEM info')
return False
base = QSWATUtils.join(demInfo.absolutePath(), demInfo.baseName())
useBurn = False
burnFile, found = proj.readEntry(title, 'delin/burn', '')
if found and burnFile != '':
burnFile = QSWATUtils.join(self._gv.projDir, burnFile)
useBurn = os.path.isfile(burnFile)
if useBurn:
self._gv.slopeFile = base + 'slope.tif'
if not self._gv.existingWshed:
burnFile, found = proj.readEntry(title, 'delin/burn', '')
if found and burnFile != '':
burnFile = QSWATUtils.join(self._gv.projDir, burnFile)
if not os.path.exists(burnFile):
QSWATUtils.loginfo('demProcessed failed: no burn file')
return False
self._gv.slopeFile = base + 'slope.tif'
else:
self._gv.slopeFile = base + 'slp.tif'
else:
self._gv.slopeFile = base + 'slp.tif'
# GRASS slope file should be based on original DEM
Expand Down
23 changes: 23 additions & 0 deletions QSWAT3/QSWAT/setuppyx3_12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from distutils.core import setup

from Cython.Build import cythonize # @UnresolvedImport
import os
import numpy
includePath = os.environ['OSGEO4W_ROOT'] + r'/apps/Python312/include'
if 'INCLUDE' in os.environ:
os.environ['INCLUDE'] = os.environ['INCLUDE'] + ';' + includePath + ';' + numpy.get_include()
else:
os.environ['INCLUDE'] = includePath + ';' + numpy.get_include()


# setup(
# name = "pyxes",
# package_dir = {'QSWAT3': ''},
# ext_modules = cythonize('*.pyx', include_path = [os.environ['INCLUDE']]),
# )
setup(
name = "pyxes",
package_dir = {'QSWAT': ''},
ext_modules = cythonize('*.pyx'),
include_dirs = [numpy.get_include()],
)
168 changes: 168 additions & 0 deletions QSWAT3/QSWAT3_12.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "QSWAT3_9"
#define MyAppVersion "1.7"
#define MyAppSubVersion "1"
#define MyAppPublisher "SWAT"
#define MyAppURL "https://swat.tamu.edu/"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{2FE06196-CAE4-428C-8EAF-DD05E4DE43DF}
AppName={#MyAppName}
AppVersion={#MyAppVersion}.{#MyAppSubVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={userappdata}\QGIS\QGIS3\profiles\default\python\plugins
UsePreviousAppDir=no
DisableDirPage=yes
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
OutputDir=C:\Users\Chris\QSWAT
OutputBaseFilename={#MyAppName}install{#MyAppVersion}.{#MyAppSubVersion}
Compression=lzma
SolidCompression=yes
PrivilegesRequired=lowest
PrivilegesRequiredOverridesAllowed=dialog
; use no for testing, yes for delivery??
UsePreviousPrivileges=no

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[InstallDelete]
Type: filesandordirs; Name: "C:\SWAT\SWATEditor\TauDEM539Bin"

[Files]
Source: "C:\Users\Chris\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\{#MyAppName}\*"; DestDir: "{code:QGISPLuginDir}\{#MyAppName}"; Excludes: "testdata\test,__pycache__,PIL"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\SWAT\SWATEditor\runConvertFromArc.bat"; DestDir: "C:\SWAT\SWATEditor"; Flags: ignoreversion
Source: "C:\SWAT\SWATEditor\runConvertToPlus.bat"; DestDir: "C:\SWAT\SWATEditor"; Flags: ignoreversion
; Source: "C:\SWAT\SWATEditor\TauDEM5Bin\*"; DestDir: "C:\SWAT\SWATEditor\TauDEM5Bin"; Check: IsWin64; Flags: ignoreversion
; Source: "C:\SWAT\SWATEditor\TauDEM5x86Bin\*"; DestDir: "C:\SWAT\SWATEditor\TauDEM5Bin"; Check: not IsWin64; Flags: ignoreversion
Source: "C:\SWAT\SWATPlus\TauDEM539_304Bin\*"; DestDir: "C:\SWAT\SWATEditor\TauDEM539Bin"; Flags: ignoreversion
Source: "C:\SWAT\SWATEditor\Databases\QSWATProj2012.mdb"; DestDir: "C:\SWAT\SWATEditor\Databases"; Flags: ignoreversion
Source: "C:\SWAT\SWATEditor\Databases\QSWATRef2012.mdb"; DestDir: "C:\SWAT\SWATEditor\Databases"; Flags: ignoreversion
Source: "C:\SWAT\SWATEditor\runSWATGraph_3_34_6.bat"; DestDir: "C:\SWAT\SWATEditor"; DestName: "runSWATGraph.bat"; Check: IsWin64; Flags: ignoreversion
; Source: "C:\SWAT\SWATEditor\runSWATGraphx86.bat"; DestDir: "C:\SWAT\SWATEditor"; Check: not IsWin64; DestName: "runSWATGraph.bat"; Flags: ignoreversion
Source: "C:\SWAT\SWATEditor\WeatherCheck\runWeatherCheck.bat"; DestDir: "C:\SWAT\SWATEditor\WeatherCheck"; DestName: "runWeatherCheck.bat"; Flags: ignoreversion
Source: "C:\SWAT\SWATEditor\WeatherCheck\weathercheck.py"; DestDir: "C:\SWAT\SWATEditor\WeatherCheck"; DestName: "weathercheck.py"; Flags: ignoreversion
Source: "C:\SWAT\SWATEditor\WeatherCheck\SWATWeatherCheck.pdf"; DestDir: "C:\SWAT\SWATEditor\WeatherCheck"; DestName: "SWATWeatherCheck.pdf"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Code]
var
QGISPluginDirHasRun : Boolean;
QGISPluginDirResult: String;
function MainQGISPluginDir(Param: String): String; forward;
function QGISDir(Dir: String; PartName: String): String; forward;
function SubSubVersion(Name: String): Integer; forward;
function QGISPluginDir(Param: String): String;
begin
if not QGISPluginDirHasRun then begin
if IsAdminInstallMode then begin
QGISPluginDirResult := MainQGISPluginDir(Param);
end else begin
QGISPluginDirResult := ExpandConstant('{app}');
end
end;
QGISPluginDirHasRun := True;
Result := QGISPluginDirResult;
end;
function MainQGISPluginDir(Param: String): String;
var
QGISDirectory: String;
MainQGISPluginDirResult: String;
pfDir: String;
begin
pfDir := ExpandConstant('{pf64}');
QGISDirectory := QGISDir(pfDir, 'QGIS 3.34');
if QGISDirectory = '' then begin
QGISDirectory := QGISDir(pfDir, 'QGIS 3.34');
if QGISDirectory = '' then begin
QGISDirectory := QGISDir(pfDir, 'QGIS 3.34');
if QGISDirectory = '' then begin
QGISDirectory := QGISDir(pfDir, 'QGIS 3.36');
if QGISDirectory = '' then begin
QGISDirectory := pfDir;
if not BrowseForFolder('Please locate QGIS directory', QGISDirectory, False) then
QGISDirectory := '';
end;
end;
end;
end;
if QGISDirectory = '' then begin
MainQGISPluginDirResult := '';
end else
if DirExists(QGISDirectory + '/apps/qgis-ltr') then begin
MainQGISPluginDirResult := QGISDirectory + '/apps/qgis-ltr/python/plugins';
end else
if DirExists(QGISDirectory + '/apps/qgis') then begin
MainQGISPluginDirResult := QGISDirectory + '/apps/qgis/python/plugins';
end else
if DirExists(QGISDirectory + '/apps/qgis-dev') then begin
MainQGISPluginDirResult := QGISDirectory + '/apps/qgis-dev/python/plugins';
end;
//MsgBox('Result: ' + MainQGISPluginDirResult, mbInformation, MB_OK);
Result := MainQGISPluginDirResult;
end;
// Dir is pf64, PartName is eg QGIS 3.22 and we are searching for eg QGIS 3.22.8
function QGISDir(Dir: String; PartName: String): String;
var
DirResult: String;
FindRec: TFindRec;
SearchString: String;
CurrentSubSubVersion: Integer;
NextSubSubVersion: Integer;
begin
DirResult := '';
CurrentSubSubVersion := 0;
NextSubSubVersion := 0;
SearchString := Dir + '/' + PartName + '.*'
if FindFirst(SearchString, FindRec) then begin
try
repeat
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 16 then begin
NextSubSubVersion := SubSubVersion(FindRec.Name);
//MsgBox(Format('Current is %d, next is %d', [CurrentSubSubVersion, NextSubSubVersion]), mbInformation, MB_OK);
if NextSubSubVersion > CurrentSubSubVersion then begin
DirResult := Dir + '/' + FindRec.Name;
CurrentSubSubVersion := NextSubSubVersion;
end;
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end;
//MsgBox('QGIS directory: ' + DirResult, mbInformation, MB_OK);
Result:= DirResult;
end;
// if name is QGIS A.B.nn or QGIS A.B.n then return nn or n as an integer, else -1
function SubSubVersion(Name: String): Integer;
var
I: Integer;
NumString: String;
begin
Result := -1
if WildcardMatch(Name, 'QGIS *.*.*') then begin
// start with possible two digits
NumString := Copy(Name, Length(Name) - 1, 2);
Result := StrToIntDef(NumString, -1);
if Result < 0 then begin
NumString := Copy(Name, Length(Name), 1);
Result := StrToIntDef(NumString, -1);
end
end;
end;
2 changes: 1 addition & 1 deletion QSWAT3/QSWAT3_64.iss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define MyAppName "QSWAT3_64"
#define MyAppVersion "1.6"
#define MyAppSubVersion "6"
#define MyAppSubVersion "7"
#define MyAppPublisher "SWAT"
#define MyAppURL "https://swat.tamu.edu/"

Expand Down
2 changes: 1 addition & 1 deletion QSWAT3/QSWAT3_9.iss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define MyAppName "QSWAT3_9"
#define MyAppVersion "1.6"
#define MyAppSubVersion "6"
#define MyAppSubVersion "7"
#define MyAppPublisher "SWAT"
#define MyAppURL "https://swat.tamu.edu/"

Expand Down
2 changes: 1 addition & 1 deletion QSWAT3/metadata32.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ qgisMaximumVersion=3.18
description=Create SWAT inputs
version=1.5.4
author=Chris George
email=cgeorge@mcmaster.ca
email=cgeorge@tamu.edu

# end of mandatory metadata

Expand Down
39 changes: 39 additions & 0 deletions QSWAT3/metadata3_12.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This file contains metadata for your plugin. Beginning
# with version 1.8 this is the preferred way to supply information about a
# plugin. The current method of embedding metadata in __init__.py will
# be supported until version 2.0

# This file should be included when you package your plugin.

# Mandatory items:


[general]
name=QSWAT3_12
qgisMinimumVersion=3.34.5
#qgisMaximumVersion=
description=Create SWAT inputs
version=1.7.1
author=Chris George
email=cgeorge@tamu.edu

# end of mandatory metadata

# Optional items:

# Uncomment the following line and add your changelog entries:
# changelog=

# tags are comma separated with spaces allowed
tags=SWAT, watershed model

homepage=http://swat.tamu.edu/software/qswat/
tracker=
repository=
icon=SWAT32.png
# experimental flag
experimental=False

# deprecated flag (applies to the whole plugin, not just a single version
deprecated=False

4 changes: 2 additions & 2 deletions QSWAT3/metadata3_9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ name=QSWAT3_9
qgisMinimumVersion=3.16.14
#qgisMaximumVersion=
description=Create SWAT inputs
version=1.6.6
version=1.6.7
author=Chris George
email=cgeorge@mcmaster.ca
email=cgeorge@tamu.edu

# end of mandatory metadata

Expand Down
4 changes: 2 additions & 2 deletions QSWAT3/metadata64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ name=QSWAT3_64
qgisMinimumVersion=3.16
qgisMaximumVersion=3.18
description=Create SWAT inputs
version=1.6.6
version=1.6.7
author=Chris George
email=cgeorge@mcmaster.ca
email=cgeorge@tamu.edu

# end of mandatory metadata

Expand Down
4 changes: 2 additions & 2 deletions QSWAT3/runnose.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
SET OSGEO4W_ROOT=C:\Program Files\QGIS 3.28.13
SET OSGEO4W_ROOT=C:\Program Files\QGIS 3.34.6
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis-ltr\python
rem QGIS binaries
rem Important to put OSGEO4W_ROOT\bin last, not first, or PyQt.QtCore DLL load fails
set PATH=%PATH%;%OSGEO4W_ROOT%\apps\qgis-ltr\bin;%OSGEO4W_ROOT%\apps\qgis-ltr\python;%OSGEO4W_ROOT%\apps\Python39;%OSGEO4W_ROOT%\bin
set PATH=%PATH%;%OSGEO4W_ROOT%\apps\qgis-ltr\bin;%OSGEO4W_ROOT%\apps\qgis-ltr\python;%OSGEO4W_ROOT%\apps\Python312;%OSGEO4W_ROOT%\bin
rem disable QGIS console messages
set QGIS_DEBUG=-1

Expand Down
Loading

0 comments on commit 303734d

Please sign in to comment.