-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRasterStack.py
123 lines (87 loc) · 3.95 KB
/
RasterStack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 24 02:03:17 2020
@author: mwooten3
RasterStack describes a raster geoTIFF or VRT with mutliple layers
Inherits from Raster,
With methods designed specifically for 3DSI Zonal Stats process
RasterStack inherits the following from Raster:
self.filePath; self.extension; self.baseName; self.baseDir; self.dataset
self.noDataValue; self.ogrDataType; self.ogrGeotransform; self.ogrProjection
self.nColumns; self.nRows; self.nLayers
convertExtent(self, targetEpsg)
epsg(self)
extent(self)
extractBand(self, bandN, outTif = None)
toArray(self)
"""
import os
from Raster import Raster
#------------------------------------------------------------------------------
# class RasterStack
#------------------------------------------------------------------------------
class RasterStack(Raster):
#--------------------------------------------------------------------------
# __init__
#--------------------------------------------------------------------------
def __init__(self, filePath):
# Initialize the base class
super(RasterStack, self).__init__(filePath)
"""
# Check that the file is TIF or VRT
if self.extension != '.vrt' and self.extension != '.tif':
raise RuntimeError('{} is not a VRT or TIF file'.format(filePath))
"""
self.stackName = self.baseName.strip('_stack')
#--------------------------------------------------------------------------
# noDataLayer()
#--------------------------------------------------------------------------
def noDataLayer(self):
noDataLayer = self.filePath.replace('stack.vrt', 'mask.tif')
if os.path.isfile(noDataLayer):
return noDataLayer
else:
return None
#--------------------------------------------------------------------------
# outDir()
#--------------------------------------------------------------------------
def outDir(self, baseDir):
# zonalStatsDir --> zonalType --> DSM/LVIS/GLiHT --> stackIdentifier
outDir = os.path.join(baseDir, self.stackType(), self.stackName)
os.system('mkdir -p {}'.format(outDir))
return outDir
#--------------------------------------------------------------------------
# stackKey()
#--------------------------------------------------------------------------
def stackKey(self):
stackKey = self.filePath.replace('.vrt', '_Log.txt')
if os.path.isfile(stackKey):
return stackKey
else:
return None
#--------------------------------------------------------------------------
# stackType()
#--------------------------------------------------------------------------
def stackType(self):
# SGM, LVIS, or GLiHT
if 'Out_SGM' in self.baseDir or 'Out_EA' in self.baseDir: # TEMP UNTIL WILL FIXES STACKDIRs
return 'SGM'
elif 'out_lvis' in self.baseDir:
return 'LVIS'
elif 'out_gliht' in self.baseDir:
return 'GLiHT'
elif 'esta_year' in self.baseDir:
return 'Landsat'
elif 'TDM1_DEM' in self.baseDir:
return 'Tandemx'
else:
return None
#--------------------------------------------------------------------------
# xmlLayer()
#--------------------------------------------------------------------------
def xmlLayer(self):
xmlLayer = self.filePath.replace('_stack.vrt', '.xml')
if os.path.isfile(xmlLayer):
return xmlLayer
else:
return None