Commit c6790093 authored by mlang's avatar mlang
Browse files

Merge branch 'dev'

No related merge requests found
Showing with 415 additions and 108 deletions
+415 -108
...@@ -60,3 +60,9 @@ data/l8_20130707\.tif\.aux\.xml ...@@ -60,3 +60,9 @@ data/l8_20130707\.tif\.aux\.xml
data/l8_20130831\.tif\.aux\.xml data/l8_20130831\.tif\.aux\.xml
qgis-auth\.db qgis-auth\.db
ymraster/\.spyderproject
\.spyderworkspace
\.spyderproject
...@@ -18,7 +18,8 @@ class DriverExt(GenericDriverExt): ...@@ -18,7 +18,8 @@ class DriverExt(GenericDriverExt):
drivername_map = {'.tif': 'GTiff', drivername_map = {'.tif': 'GTiff',
'.h5': 'HDF5', '.h5': 'HDF5',
'.ers': 'ERS'} '.ers': 'ERS',
'.vrt': 'VRT'}
__slots__ = () __slots__ = ()
......
...@@ -2,13 +2,22 @@ ...@@ -2,13 +2,22 @@
try: try:
import otbApplication as otb import otbApplication as otb
OTB_IS_LOAD = True
except ImportError as e: except ImportError as e:
raise ImportError( OTB_IS_LOAD = False
str(e) ERROR_OTB = ImportError(str(e)
+ "\n\nPlease install Orfeo Toolbox if it isn't installed yet.\n\n" + "\n\nThis functionnality is not available without Orfeo Toolbox. " +
"Please install Orfeo Toolbox if it isn't installed yet.\n\n"
"Also, add the otbApplication module path " "Also, add the otbApplication module path "
"(usually something like '/usr/lib/otb/python') " "(usually something like '/usr/lib/otb/python') "
"to the environment variable PYTHONPATH.\n") "to the PYTHONPATH environment variable.")
# raise ImportError(
# str(e)
# + "\n\nPlease install Orfeo Toolbox if it isn't installed yet.\n\n"
# "Also, add the otbApplication module path "
# "(usually something like '/usr/lib/otb/python') "
# "to the environment variable PYTHONPATH.\n")
try: try:
from osgeo import gdal from osgeo import gdal
except ImportError as e: except ImportError as e:
...@@ -32,81 +41,130 @@ class IdDefaultDict(dict): ...@@ -32,81 +41,130 @@ class IdDefaultDict(dict):
return self[key] return self[key]
#class DataType(object):
# """Abstract class for a data type (int16, int32, float32, etc.)"""
#
# data_type_match = IdDefaultDict()
#
# def __set__(self, instance, value):
# instance.otb_dtype = self.data_type_match[value]
#
# def __get__(self, instance, owner):
# revert_match = {v: k for k, v in self.data_type_match.iteritems()}
# return revert_match[instance.otb_dtype]
class DataType(object): class DataType(object):
"""Abstract class for a data type (int16, int32, float32, etc.)""" """Abstract class for a data type (int16, int32, float32, etc.)"""
data_type_match = IdDefaultDict() data_type_match = IdDefaultDict()
def __set__(self, instance, value): def __set__(self, instance, value):
instance.otb_dtype = self.data_type_match[value] instance.gdal_dtype = self.data_type_match[value]
def __get__(self, instance, owner): def __get__(self, instance, owner):
revert_match = {v: k for k, v in self.data_type_match.iteritems()} revert_match = {v: k for k, v in self.data_type_match.iteritems()}
return revert_match[instance.otb_dtype] return revert_match[instance.gdal_dtype]
class LStrDataType(DataType): class LStrDataType(DataType):
"""Represent a data type given in lower string format (eg. 'int16', 'int32', """Represent a data type given in lower string format (eg. 'int16', 'int32',
'float32', etc.)""" 'float32', etc.)"""
data_type_match = {'uint8': otb.ImagePixelType_uint8, # data_type_match = {'uint8': otb.ImagePixelType_uint8,
'uint16': otb.ImagePixelType_uint16, # 'uint16': otb.ImagePixelType_uint16,
'uint32': otb.ImagePixelType_uint32, # 'uint32': otb.ImagePixelType_uint32,
'int16': otb.ImagePixelType_int16, # 'int16': otb.ImagePixelType_int16,
'int32': otb.ImagePixelType_int32, # 'int32': otb.ImagePixelType_int32,
'float32': otb.ImagePixelType_float, # 'float32': otb.ImagePixelType_float,
'float64': otb.ImagePixelType_double} # 'float64': otb.ImagePixelType_double}
data_type_match = {'uint8': gdal.GDT_Byte,
'uint16': gdal.GDT_UInt16,
'uint32': gdal.GDT_UInt32,
'int16': gdal.GDT_Int16,
'int32': gdal.GDT_Int32,
'float32': gdal.GDT_Float32,
'float64': gdal.GDT_Float64}
class UStrDataType(DataType): class UStrDataType(DataType):
"""Represent a data type given in upper string format (eg. 'Int16', 'Int32', """Represent a data type given in upper string format (eg. 'Int16', 'Int32',
'Float32', etc.)""" 'Float32', etc.)"""
data_type_match = {'UInt8': otb.ImagePixelType_uint8, # data_type_match = {'UInt8': otb.ImagePixelType_uint8,
'UInt16': otb.ImagePixelType_uint16, # 'UInt16': otb.ImagePixelType_uint16,
'UInt32': otb.ImagePixelType_uint32, # 'UInt32': otb.ImagePixelType_uint32,
'Int16': otb.ImagePixelType_int16, # 'Int16': otb.ImagePixelType_int16,
'Int32': otb.ImagePixelType_int32, # 'Int32': otb.ImagePixelType_int32,
'Float32': otb.ImagePixelType_float, # 'Float32': otb.ImagePixelType_float,
'Float64': otb.ImagePixelType_double} # 'Float64': otb.ImagePixelType_double}
data_type_match = {'UInt8': gdal.GDT_Byte,
'UInt16': gdal.GDT_UInt16,
'UInt32': gdal.GDT_UInt32,
'Int16': gdal.GDT_Int16,
'Int32': gdal.GDT_Int32,
'Float32': gdal.GDT_Float32,
'Float64': gdal.GDT_Float64}
class NumpyDataType(DataType): class NumpyDataType(DataType):
"""Represent a data type for Numpy (eg. np.int16, np.int32, np.float32, """Represent a data type for Numpy (eg. np.int16, np.int32, np.float32,
etc.)""" etc.)"""
data_type_match = {np.uint8: otb.ImagePixelType_uint8, # data_type_match = {np.uint8: otb.ImagePixelType_uint8,
np.uint16: otb.ImagePixelType_uint16, # np.uint16: otb.ImagePixelType_uint16,
np.uint32: otb.ImagePixelType_uint32, # np.uint32: otb.ImagePixelType_uint32,
np.int16: otb.ImagePixelType_int16, # np.int16: otb.ImagePixelType_int16,
np.int32: otb.ImagePixelType_int32, # np.int32: otb.ImagePixelType_int32,
np.int64: otb.ImagePixelType_int32, # np.int64: otb.ImagePixelType_int32,
np.float32: otb.ImagePixelType_float, # np.float32: otb.ImagePixelType_float,
np.float64: otb.ImagePixelType_double} # np.float64: otb.ImagePixelType_double}
data_type_match = {np.uint8: gdal.GDT_Byte,
np.uint16: gdal.GDT_UInt16,
np.uint32: gdal.GDT_UInt32,
np.int16: gdal.GDT_Int16,
np.int32: gdal.GDT_Int32,
np.float32: gdal.GDT_Float32,
np.float64: gdal.GDT_Float64}
class GdalDataType(DataType): class GdalDataType(DataType):
"""Represent a data type for gdal (eg. gdal.GDT_Int16, gdal.GDT_Iint32, """Represent a data type for gdal (eg. gdal.GDT_Int16, gdal.GDT_Iint32,
gdal.GDT_Float32, etc.)""" gdal.GDT_Float32, etc.)"""
data_type_match = {gdal.GDT_Byte: otb.ImagePixelType_uint8, # data_type_match = {gdal.GDT_Byte: otb.ImagePixelType_uint8,
gdal.GDT_UInt16: otb.ImagePixelType_uint16, # gdal.GDT_UInt16: otb.ImagePixelType_uint16,
gdal.GDT_UInt32: otb.ImagePixelType_uint32, # gdal.GDT_UInt32: otb.ImagePixelType_uint32,
gdal.GDT_Int16: otb.ImagePixelType_int16, # gdal.GDT_Int16: otb.ImagePixelType_int16,
gdal.GDT_Int32: otb.ImagePixelType_int32, # gdal.GDT_Int32: otb.ImagePixelType_int32,
gdal.GDT_Float32: otb.ImagePixelType_float, # gdal.GDT_Float32: otb.ImagePixelType_float,
gdal.GDT_Float64: otb.ImagePixelType_double} # gdal.GDT_Float64: otb.ImagePixelType_double}
def __set__(self, instance, value):
instance._gdal_type = value
def __get__(self, instance, owner):
return instance._gdal_type
class OtbDataType(DataType): class OtbDataType(DataType):
"""Represent a data type for orfeo-toolbox """Represent a data type for orfeo-toolbox
(eg. otb.ImagePixelType_int16)""" (eg. otb.ImagePixelType_int16)"""
def __set__(self, instance, value): # def __set__(self, instance, value):
instance._otb_type = value # instance._otb_type = value
#
def __get__(self, instance, owner): # def __get__(self, instance, owner):
return instance._otb_type # return instance._otb_type
if OTB_IS_LOAD:
data_type_match = {otb.ImagePixelType_uint8: gdal.GDT_Byte,
otb.ImagePixelType_uint16: gdal.GDT_UInt16,
otb.ImagePixelType_uint32: gdal.GDT_UInt32,
otb.ImagePixelType_int16: gdal.GDT_Int16,
otb.ImagePixelType_int32: gdal.GDT_Int32,
otb.ImagePixelType_float: gdal.GDT_Float32,
otb.ImagePixelType_double: gdal.GDT_Float64}
else:
def __get__(self, instance, owner):
raise ERROR_OTB
class RasterDataType(object): class RasterDataType(object):
...@@ -124,7 +182,7 @@ class RasterDataType(object): ...@@ -124,7 +182,7 @@ class RasterDataType(object):
numpy_dtype=None, numpy_dtype=None,
otb_dtype=None, otb_dtype=None,
gdal_dtype=None): gdal_dtype=None):
if lstr_dtype: if lstr_dtype:
self.lstr_dtype = lstr_dtype self.lstr_dtype = lstr_dtype
elif ustr_dtype: elif ustr_dtype:
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment