Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Q
qgis-otb-plugin
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Catherine CALME
qgis-otb-plugin
Commits
bc6d7af4
Commit
bc6d7af4
authored
Aug 06, 2018
by
Rashad Kanavath
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
M-x flycheck-list-errors
parent
1b777212
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
43 deletions
+38
-43
otb/OTBAlgorithmProvider.py
otb/OTBAlgorithmProvider.py
+38
-43
No files found.
otb/OTBAlgorithmProvider.py
View file @
bc6d7af4
...
...
@@ -39,21 +39,19 @@ from processing.core.ProcessingConfig import ProcessingConfig, Setting
from
otb
import
OTBUtils
from
otb.OTBAlgorithm
import
OTBAlgorithm
pluginPath
=
os
.
path
.
split
(
os
.
path
.
dirname
(
__file__
))[
0
]
def
otb_exe_file
(
f
):
if
os
.
name
==
'nt'
:
return
f
+
'.exe'
else
:
return
f
return
f
class
OTBAlgorithmProvider
(
QgsProcessingProvider
):
def
__init__
(
self
):
super
().
__init__
()
self
.
algs
=
[]
#!hack for 6.6!#
self
.
version
=
'6.6.0'
self
.
descriptionFile
=
''
def
canBeActivated
(
self
):
if
not
self
.
isActive
():
...
...
@@ -72,10 +70,9 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
if
not
v
:
self
.
setActive
(
False
)
raise
ValueError
(
self
.
tr
(
'Cannot activate OTB provider'
))
return
folder
=
OTBUtils
.
otbFolder
()
otb_app_dirs
=
self
.
otb_app_dir_list
(
v
)
otb_app_dirs
=
self
.
otb_app_dir_list
(
v
)
if
len
(
otb_app_dirs
)
<
1
:
self
.
setActive
(
False
)
raise
ValueError
(
self
.
tr
(
"'{}' does not exist. OTB provider will be disabled"
.
format
(
v
)))
...
...
@@ -95,9 +92,10 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
dfile
=
os
.
path
.
join
(
descr_folder
,
app_name
+
'.txt'
)
isValid
=
True
if
not
os
.
path
.
exists
(
dfile
):
cmdlist
=
[
os
.
path
.
join
(
folder
,
'bin'
,
otb_exe_file
(
'otbQgisDescriptor'
)),
app_name
,
app_dir
,
descr_folder
+
'/'
]
cmdlist
=
[
os
.
path
.
join
(
folder
,
'bin'
,
otb_exe_file
(
'otbQgisDescriptor'
)),
app_name
,
app_dir
,
descr_folder
+
'/'
]
commands
=
' '
.
join
(
cmdlist
)
QgsMessageLog
.
logMessage
(
self
.
tr
(
commands
),
self
.
tr
(
'Processing'
),
Qgis
.
Critical
)
OTBUtils
.
executeOtb
(
commands
,
feedback
=
None
)
...
...
@@ -118,11 +116,10 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
if
not
v
or
not
os
.
path
.
exists
(
v
):
self
.
setActive
(
False
)
raise
ValueError
(
self
.
tr
(
"'{}' does not exist. OTB provider will be disabled"
.
format
(
v
)))
return
path
=
self
.
normalize_path
(
v
)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
path
,
'bin'
,
otb_exe_file
(
'otbApplicationLauncherCommandLine'
))):
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
path
,
'bin'
,
otb_exe_file
(
'otbApplicationLauncherCommandLine'
))):
self
.
setActive
(
False
)
raise
ValueError
(
self
.
tr
(
"Cannot find '{}'. OTB will be disabled"
.
format
(
os
.
path
.
join
(
v
,
'bin'
,
otb_exe_file
(
'otbApplicationLauncherCommandLine'
)))))
raise
ValueError
(
self
.
tr
(
"Cannot find '{}'. OTB will be disabled"
.
format
(
os
.
path
.
join
(
v
,
'bin'
,
otb_exe_file
(
'otbApplicationLauncherCommandLine'
)))))
def
write_otbcli_wrapper_script
(
self
):
otb_folder
=
self
.
normalize_path
(
OTBUtils
.
otbFolder
())
...
...
@@ -135,8 +132,8 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
export_cmd
=
'SET '
first_line
=
':: Setup environment for OTB package. Generated by QGIS plugin'
otb_app_launcher
=
os
.
path
.
join
(
otb_folder
,
'bin'
,
'otbApplicationLauncherCommandLine.exe'
)
gdal_data_dir
=
os
.
path
.
join
(
otb_folder
,
'share'
,
'data'
)
geotiff_csv_dir
=
os
.
path
.
join
(
otb_folder
,
'share'
,
'epsg_csv'
)
gdal_data_dir
=
os
.
path
.
join
(
otb_folder
,
'share'
,
'data'
)
geotiff_csv_dir
=
os
.
path
.
join
(
otb_folder
,
'share'
,
'epsg_csv'
)
else
:
app_vargs
=
" $@"
export_cmd
=
'export '
...
...
@@ -176,32 +173,29 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
def
load
(
self
):
group
=
self
.
name
()
ProcessingConfig
.
settingIcons
[
group
]
=
self
.
icon
()
ProcessingConfig
.
addSetting
(
Setting
(
group
,
OTBUtils
.
ACTIVATE
,
self
.
tr
(
'Activate'
),
True
))
ProcessingConfig
.
addSetting
(
Setting
(
group
,
OTBUtils
.
ACTIVATE
,
self
.
tr
(
'Activate'
),
True
))
ProcessingConfig
.
addSetting
(
Setting
(
group
,
OTBUtils
.
FOLDER
,
self
.
tr
(
"OTB folder"
),
OTBUtils
.
otbFolder
(),
valuetype
=
Setting
.
FOLDER
,
validator
=
self
.
check_otb_folder
))
self
.
tr
(
"OTB folder"
),
OTBUtils
.
otbFolder
(),
valuetype
=
Setting
.
FOLDER
,
validator
=
self
.
check_otb_folder
))
ProcessingConfig
.
addSetting
(
Setting
(
group
,
OTBUtils
.
APP_FOLDER
,
self
.
tr
(
"OTB application folder"
),
OTBUtils
.
appFolder
()
,
valuetype
=
Setting
.
MULTIPLE_FOLDERS
,
validator
=
self
.
check_app_folder
))
self
.
tr
(
"OTB application folder"
),
OTBUtils
.
appFolder
(),
valuetype
=
Setting
.
MULTIPLE_FOLDERS
,
validator
=
self
.
check_app_folder
))
ProcessingConfig
.
addSetting
(
Setting
(
group
,
OTBUtils
.
SRTM_FOLDER
,
self
.
tr
(
"SRTM tiles folder"
),
OTBUtils
.
srtmFolder
(),
valuetype
=
Setting
.
FOLDER
))
self
.
tr
(
"SRTM tiles folder"
),
OTBUtils
.
srtmFolder
(),
valuetype
=
Setting
.
FOLDER
))
ProcessingConfig
.
addSetting
(
Setting
(
group
,
OTBUtils
.
GEOID_FILE
,
self
.
tr
(
"Geoid file"
),
OTBUtils
.
geoidFile
(),
valuetype
=
Setting
.
FOLDER
))
self
.
tr
(
"Geoid file"
),
OTBUtils
.
geoidFile
(),
valuetype
=
Setting
.
FOLDER
))
ProcessingConfig
.
readSettings
()
self
.
refreshAlgorithms
()
...
...
@@ -229,16 +223,16 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
line
=
lines
.
readline
().
strip
(
'
\n
'
).
strip
()
while
line
!=
''
and
not
line
.
startswith
(
'#'
):
data
=
line
.
split
(
'|'
)
descriptionFile
=
self
.
descrFile
(
folder
,
str
(
data
[
1
])
+
'.txt'
)
self
.
descriptionFile
=
self
.
descrFile
(
folder
,
str
(
data
[
1
])
+
'.txt'
)
group
,
name
=
str
(
data
[
0
]),
str
(
data
[
1
])
if
name
not
in
alg_names
:
algs
.
append
(
OTBAlgorithm
(
group
,
name
,
descriptionFile
))
algs
.
append
(
OTBAlgorithm
(
group
,
name
,
self
.
descriptionFile
))
#avoid duplicate algorithms from algs.txt file (possible but rare)
alg_names
.
append
(
name
)
line
=
lines
.
readline
().
strip
(
'
\n
'
).
strip
()
except
Exception
as
e
:
import
traceback
errmsg
=
"Could not open OTB algorithm from file:
\n
"
+
self
.
_descriptionf
ile
+
"
\n
Error:
\n
"
+
traceback
.
format_exc
()
errmsg
=
"Could not open OTB algorithm from file:
\n
"
+
self
.
descriptionF
ile
+
"
\n
Error:
\n
"
+
traceback
.
format_exc
()
QgsMessageLog
.
logMessage
(
self
.
tr
(
errmsg
),
self
.
tr
(
'Processing'
),
Qgis
.
Critical
)
return
algs
...
...
@@ -268,8 +262,8 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
cli_ext
=
''
env_profile
=
os
.
path
.
join
(
folder
,
'otbenv.profile'
)
if
os
.
name
==
'nt'
:
cli_ext
=
'.bat'
env_profile
=
os
.
path
.
join
(
folder
,
'otbenv.bat'
)
cli_ext
=
'.bat'
env_profile
=
os
.
path
.
join
(
folder
,
'otbenv.bat'
)
if
os
.
path
.
exists
(
env_profile
)
and
os
.
path
.
isfile
(
env_profile
):
OTBUtils
.
OTB_CLI_FILE
=
os
.
path
.
join
(
QgsApplication
.
qgisSettingsDirPath
(),
'processing'
,
'qgis_otb_cli'
+
cli_ext
)
...
...
@@ -296,7 +290,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
def
otb_app_dir_list
(
self
,
v
):
#!hack needed for QGIS < 3.2!#
v
=
v
.
replace
(
';'
,
os
.
pathsep
)
v
=
v
.
replace
(
';'
,
os
.
pathsep
)
#!hack needed for QGIS < 3.2!#
folders
=
v
.
split
(
os
.
pathsep
)
app_dirs
=
[]
...
...
@@ -304,7 +298,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
if
f
is
not
None
and
os
.
path
.
exists
(
f
):
app_dirs
.
append
(
self
.
normalize_path
(
f
))
return
app_dirs
def
name
(
self
):
return
'OTB'
...
...
@@ -321,6 +315,7 @@ class OTBAlgorithmProvider(QgsProcessingProvider):
return
False
def
icon
(
self
):
pluginPath
=
os
.
path
.
split
(
os
.
path
.
dirname
(
__file__
))[
0
]
return
QIcon
(
os
.
path
.
join
(
pluginPath
,
'otb'
,
'otb.png'
))
def
tr
(
self
,
string
,
context
=
''
):
...
...
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