Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
hru-delin-dev
hru-delin-qgis
Commits
7ddc6352
Unverified
Commit
7ddc6352
authored
Apr 18, 2020
by
Julien Veyssier
Browse files
step1 and step2 running in the plugin !!!
Signed-off-by:
Julien Veyssier
<
eneiluj@posteo.net
>
parent
c55ad925
Changes
3
Hide whitespace changes
Inline
Side-by-side
.gitmodules
0 → 100644
View file @
7ddc6352
[submodule "hru-delin"]
path = hrudelinCore
url = https://gitlab.irstea.fr/julien.veyssier/hru-delin
hrudelinCore
@
fb621862
Subproject commit fb62186205949555763e5c7b13b9160e0f802425
hrudelin_dockwidget.py
View file @
7ddc6352
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Irip
DockWidget
HruDelin
DockWidget
A QGIS plugin
IRIP method plugin
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2018-10-18
git sha : $Format:%H$
copyright : (C) 2018 by IRSTEA
email : a@a
***************************************************************************/
/***************************************************************************
...
...
@@ -23,9 +16,11 @@
"""
import
os
,
shutil
,
sys
,
time
from
pathlib
import
Path
import
tempfile
,
configparser
from
zipfile
import
ZipFile
from
collections
import
defaultdict
from
multiprocessing
import
cpu_count
import
numpy
as
np
from
osgeo
import
gdal
,
ogr
,
osr
from
osgeo.gdalnumeric
import
*
...
...
@@ -49,6 +44,10 @@ import processing
from
hrudelin.pluginUtils
import
layerstools
from
hrudelin.pluginUtils.tools
import
isWindows
,
isMac
,
which
,
prepareGrassEnv
prepareGrassEnv
()
from
hrudelin.hrudelinCore.modules.hrudelin_1_init
import
main
as
main1
from
hrudelin.hrudelinCore.modules.hrudelin_2_basins
import
main
as
main2
# this exception is used by the QgisTasks
class
CancelException
(
Exception
):
pass
...
...
@@ -64,7 +63,6 @@ class HruDelinDockWidget(QtWidgets.QDockWidget, FORM_CLASS):
def
__init__
(
self
,
parent
,
iface
):
"""Constructor."""
super
(
HruDelinDockWidget
,
self
).
__init__
(
parent
)
prepareGrassEnv
()
# Qgis interface, used to get main window, manipulate messageBar etc...
self
.
iface
=
iface
# can be set within the interface
...
...
@@ -348,15 +346,18 @@ class HruDelinDockWidget(QtWidgets.QDockWidget, FORM_CLASS):
# load a config file and launch a full run
def
loadProject
(
self
):
self
.
loadProjectStartTime
=
time
.
time
()
self
.
resetProject
()
projectFile
,
filter
=
QFileDialog
.
getOpenFileName
(
self
,
self
.
tr
(
'Project config file'
),
None
,
'Config files (*.cfg)'
)
if
projectFile
==
''
:
projectFile
Path
,
filter
=
QFileDialog
.
getOpenFileName
(
self
,
self
.
tr
(
'Project config file'
),
None
,
'Config files (*.cfg)'
)
if
projectFile
Path
==
''
:
return
projectFileDir
=
os
.
path
.
dirname
(
projectFile
)
self
.
loadProjectStartTime
=
time
.
time
()
projectFileDir
=
os
.
path
.
dirname
(
projectFilePath
)
self
.
projectFileDir
=
projectFileDir
config
=
configparser
.
ConfigParser
()
config
.
read
(
projectFile
)
config
.
read
(
projectFilePath
)
self
.
projectFilePath
=
projectFilePath
# dir_in is absolute or relative to config file parent directory
dir
=
config
[
'dir_in'
][
'dir'
]
...
...
@@ -711,8 +712,6 @@ class HruDelinDockWidget(QtWidgets.QDockWidget, FORM_CLASS):
self
.
iface
.
messageBar
().
popWidget
(
self
.
messageBar
)
self
.
iface
.
messageBar
().
pushSuccess
(
'HRU delin'
,
self
.
tr
(
'Step 1 success'
))
# TODO we could add layers here...
## show next GUI elements
#self.groupBoxLanduse.setVisible(True)
#self.groupBoxIripPlus.setVisible(True)
...
...
@@ -877,37 +876,76 @@ class HruDelinDockWidget(QtWidgets.QDockWidget, FORM_CLASS):
def
processStep1
(
self
,
task
):
task
.
setProgress
(
0
)
# TODO move environment building from bash to hrudelin core
# TODO adapt hrudelin core to be executed AND to be imported as a module
#HruDelinCore.step1(self.configFilePath)
print
(
'inside STEP 1 task'
)
#os.environ['GISRC'] = '/home/julien/data/j2k_test/grass_db/grassdata/hru-delin/.grassrc'
#import grass.script as grass
#print('--- GISBASE')
#print(os.environ['GISBASE'])
#print('--- PATH')
#print(os.environ['PATH'])
#print('--- LD_LIB')
#print(os.environ['LD_LIBRARY_PATH'])
#grass.run_command('r.mapcalc', expression='toto=22', overwrite=True)
##import subprocess
##subp = subprocess.check_output(['r.info', 'map=toto'])
##print('SUBP %s' % subp)
#res = grass.read_command('r.info',
# #quiet=True, flags='nNc',
# map='toto')
##.decode('utf-8')
#print('RESSS %s' % res)
# do the same job as hrudelin bash script which launch python modules
if
os
.
path
.
exists
(
self
.
cfgFilesOutPath
):
shutil
.
rmtree
(
self
.
cfgFilesOutPath
)
os
.
mkdir
(
self
.
cfgFilesOutPath
)
if
os
.
path
.
exists
(
self
.
cfgResultsOutPath
):
shutil
.
rmtree
(
self
.
cfgResultsOutPath
)
os
.
mkdir
(
self
.
cfgResultsOutPath
)
tmpPath
=
os
.
path
.
join
(
self
.
projectFileDir
,
'tmp'
)
if
os
.
path
.
exists
(
tmpPath
):
shutil
.
rmtree
(
tmpPath
)
os
.
mkdir
(
tmpPath
)
# run the mzfc
main1
(
self
.
projectFilePath
)
# display layers
for
fPath
in
Path
(
self
.
cfgFilesOutPath
).
rglob
(
'*step1*.tif'
):
strPath
=
str
(
fPath
)
task
.
displayLayer
.
emit
({
'type'
:
'raster'
,
'path'
:
strPath
,
'name'
:
os
.
path
.
basename
(
strPath
),
'tag'
:
'step1'
})
for
fPath
in
Path
(
self
.
cfgFilesOutPath
).
rglob
(
'*step1*.shp'
):
strPath
=
str
(
fPath
)
task
.
displayLayer
.
emit
({
'type'
:
'vector'
,
'path'
:
strPath
,
'name'
:
os
.
path
.
basename
(
strPath
),
'tag'
:
'step1'
})
return
True
def
processStep2
(
self
,
task
):
task
.
setProgress
(
0
)
#HruDelinCore.step1(self.configFilePath)
print
(
'inside STEP 2 task'
)
for
fPath
in
Path
(
self
.
cfgFilesOutPath
).
rglob
(
'step2*.tif'
):
os
.
remove
(
str
(
fPath
))
for
fPath
in
Path
(
self
.
cfgFilesOutPath
).
rglob
(
'step3*.tif'
):
os
.
remove
(
str
(
fPath
))
if
os
.
path
.
exists
(
self
.
cfgResultsOutPath
):
shutil
.
rmtree
(
self
.
cfgResultsOutPath
)
os
.
mkdir
(
self
.
cfgResultsOutPath
)
# run the mzfc
for
progress
in
main2
(
self
.
projectFilePath
,
cpu_count
(),
True
):
task
.
setProgress
(
progress
)
# display layers
for
fPath
in
Path
(
self
.
cfgFilesOutPath
).
rglob
(
'*step2*.tif'
):
strPath
=
str
(
fPath
)
task
.
displayLayer
.
emit
({
'type'
:
'raster'
,
'path'
:
strPath
,
'name'
:
os
.
path
.
basename
(
strPath
),
'tag'
:
'step2'
})
for
fPath
in
Path
(
self
.
cfgFilesOutPath
).
rglob
(
'*step2*.shp'
):
strPath
=
str
(
fPath
)
task
.
displayLayer
.
emit
({
'type'
:
'vector'
,
'path'
:
strPath
,
'name'
:
os
.
path
.
basename
(
strPath
),
'tag'
:
'step2'
})
return
True
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment