Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
GeoSentinel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoSentinel
Commits
d2c2e8fb
Commit
d2c2e8fb
authored
Mar 19, 2019
by
Mario Chirinos Colunga
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
class map
parent
2b4add52
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
13 deletions
+12
-13
L2ASCLtoJSON.py
geosentinel/L2ASCLtoJSON.py
+6
-10
splitSCL.py
geosentinel/splitSCL.py
+6
-3
No files found.
geosentinel/L2ASCLtoJSON.py
View file @
d2c2e8fb
...
...
@@ -25,29 +25,25 @@ SENTINEL_PATH = config['PATHS']['PATH_GEOSENTINEL']
sys
.
path
.
append
(
SENTINEL_PATH
)
from
geosentinel
import
rasterWkt
CLASS_MAP
=
{
0
:
0
,
1
:
1
,
2
:
2
,
3
:
3
,
4
:
4
,
5
:
5
,
6
:
6
,
7
:
7
,
8
:
8
,
9
:
8
,
10
:
8
,
11
:
9
}
#-------------------------------------------------------------------------------
def
L2ASCLtoDict
(
filename
,
wkt
):
'''
L2ASCLtoDict
'''
classMap
=
lambda
x
:
[
CLASS_MAP
[
xx
]
for
xx
in
x
]
inputImage
=
gdal
.
Open
(
filename
)
rows
,
cols
,
geotransform
=
inputImage
.
RasterYSize
,
inputImage
.
RasterXSize
,
inputImage
.
GetGeoTransform
()
data
=
inputImage
.
GetRasterBand
(
1
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
)
# count = Counter([])
# for r in data:
# count = count + Counter(r)
# sclDict = {str(k):v for k,v in dict(count).items()}
# print ("data")
# print (sclDict)
data
=
np
.
bitwise_and
(
data
,
rasterWkt
.
getPolygonArray
(
inputImage
,
wkt
))
count
=
Counter
([])
for
r
in
data
:
count
=
count
+
Counter
(
r
)
count
=
count
+
Counter
(
classMap
(
r
))
sclDict
=
{
str
(
k
):
v
for
k
,
v
in
dict
(
count
)
.
items
()}
# print ("data & POLY")
# print (sclDict)
return
sclDict
#-------------------------------------------------------------------------------
def
main
(
argv
):
...
...
geosentinel/splitSCL.py
View file @
d2c2e8fb
...
...
@@ -20,7 +20,8 @@ SCL_COLOR = [
(
102
,
204
,
255
,
255
),
#THIN_CIRRUS
(
255
,
153
,
255
,
255
),
#SNOW
]
CLASS_MAP
=
{
0
:
0
,
1
:
1
,
2
:
2
,
3
:
3
,
4
:
4
,
5
:
5
,
6
:
6
,
7
:
7
,
8
:
8
,
9
:
8
,
10
:
8
,
11
:
9
}
CLASS_GROUP
=
[[
0
],
[
1
],
[
2
],
[
3
],
[
4
],
[
5
],
[
6
],
[
7
],
[
8
,
9
,
10
],
[
11
]]
#-------------------------------------------------------------------------------
def
splitSCL
(
filename
,
outdir
):
inputImage
=
gdal
.
Open
(
filename
)
...
...
@@ -33,10 +34,12 @@ def splitSCL(filename, outdir):
sr
.
ImportFromWkt
(
projection
)
driverTiff
=
gdal
.
GetDriverByName
(
'GTiff'
)
for
c
in
range
(
len
(
SCL_COLOR
)):
# for c in range(len(SCL_COLOR)):
for
c
in
range
(
len
(
CLASS_GROUP
)):
outputfile
=
outdir
+
filename
[:
-
4
]
+
"_"
+
str
(
c
)
+
".tif"
output
=
driverTiff
.
Create
(
outputfile
,
cols
,
rows
,
4
,
gdal
.
GDT_Byte
)
classMask
=
inputImage
.
GetRasterBand
(
1
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
)
==
c
# classMask = inputImage.GetRasterBand(1).ReadAsArray(0,0,cols,rows)==c
classMask
=
np
.
isin
(
inputImage
.
GetRasterBand
(
1
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
),
CLASS_GROUP
[
c
])
for
b
in
range
(
1
,
output
.
RasterCount
+
1
):
output
.
GetRasterBand
(
b
)
.
SetNoDataValue
(
0
)
...
...
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