Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Remote Modules
let-it-snow
Commits
ec181c26
Commit
ec181c26
authored
Oct 18, 2016
by
Manuel Grizonnet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: replace gdal translate to API calls
parent
a4f9430e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
python/s2snow/snow_detector.py
python/s2snow/snow_detector.py
+7
-5
No files found.
python/s2snow/snow_detector.py
View file @
ec181c26
...
...
@@ -171,7 +171,8 @@ class snow_detector :
gb_path_extracted
=
op
.
join
(
self
.
path_tmp
,
"green_band_extracted.tif"
)
if
gb_dataset
.
RasterCount
>
1
:
print
"extracting green band"
call_subprocess
([
"gdal_translate"
,
"-of"
,
"GTiff"
,
"-ot"
,
"Int16"
,
"-a_nodata"
,
str
(
self
.
nodata
),
"-b"
,
str
(
gb_no
),
gb_path
,
gb_path_extracted
])
#Use gdal 2 python API
gdal
.
Translate
(
gb_path_extracted
,
gb_path
,
format
=
'GTiff'
,
outputType
=
gdal
.
GDT_Int16
,
noData
=
self
.
nodata
,
bandList
=
[
gb_no
])
else
:
copyfile
(
gb_path
,
gb_path_extracted
)
...
...
@@ -183,7 +184,7 @@ class snow_detector :
rb_path_extracted
=
op
.
join
(
self
.
path_tmp
,
"red_band_extracted.tif"
)
if
rb_dataset
.
RasterCount
>
1
:
print
"extracting red band"
call_subprocess
([
"gdal_translate"
,
"-of"
,
"GTiff"
,
"-ot"
,
"Int16"
,
"-a_
no
d
ata
"
,
str
(
self
.
nodata
),
"-b"
,
str
(
rb_no
),
rb_path
,
rb_path_extracted
])
gdal
.
Translate
(
rb_path_extracted
,
rb_path
,
format
=
'GTiff'
,
outputType
=
gdal
.
GDT_Int16
,
no
D
ata
=
self
.
nodata
,
bandList
=
[
rb_no
])
else
:
copyfile
(
rb_path
,
rb_path_extracted
)
...
...
@@ -195,8 +196,7 @@ class snow_detector :
sb_path_extracted
=
op
.
join
(
self
.
path_tmp
,
"swir_band_extracted.tif"
)
if
sb_dataset
.
RasterCount
>
1
:
print
"extracting swir band"
call_subprocess
([
"gdal_translate"
,
"-of"
,
"GTiff"
,
"-ot"
,
"Int16"
,
"-a_nodata"
,
str
(
self
.
nodata
),
"-b"
,
str
(
sb_no
),
sb_path
,
sb_path_extracted
])
gdal
.
Translate
(
sb_path_extracted
,
sb_path
,
format
=
'GTiff'
,
outputType
=
gdal
.
GDT_Int16
,
noData
=
self
.
nodata
,
bandList
=
[
sb_no
])
else
:
copyfile
(
sb_path
,
sb_path_extracted
)
...
...
@@ -219,10 +219,12 @@ class snow_detector :
print
"resolution is different among band files"
#gdalwarp to max reso
max_res
=
max
(
gb_resolution
,
rb_resolution
,
sb_resolution
)
print
"cubic resampling to "
+
str
(
max_res
)
+
"of resolution"
print
"cubic resampling to "
+
str
(
max_res
)
+
" meters."
call_subprocess
([
"gdalwarp"
,
"-overwrite"
,
"-r"
,
"cubic"
,
"-tr"
,
str
(
max_res
),
str
(
max_res
),
gb_path_extracted
,
gb_path_resampled
])
call_subprocess
([
"gdalwarp"
,
"-overwrite"
,
"-r"
,
"cubic"
,
"-tr"
,
str
(
max_res
),
str
(
max_res
),
rb_path_extracted
,
rb_path_resampled
])
call_subprocess
([
"gdalwarp"
,
"-overwrite"
,
"-r"
,
"cubic"
,
"-tr"
,
str
(
max_res
),
str
(
max_res
),
sb_path_extracted
,
sb_path_resampled
])
#gdal.Warp(gb_path_resampled,gb_path_extracted,resampleAlg = gdal.GRIORA_Cubic, xRes = max_res,yRes = max_res)
else
:
gb_path_resampled
=
gb_path_extracted
rb_path_resampled
=
rb_path_extracted
...
...
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