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
data/l8_20130831\.tif\.aux\.xml
qgis-auth\.db
ymraster/\.spyderproject
\.spyderworkspace
\.spyderproject
......@@ -18,7 +18,8 @@ class DriverExt(GenericDriverExt):
drivername_map = {'.tif': 'GTiff',
'.h5': 'HDF5',
'.ers': 'ERS'}
'.ers': 'ERS',
'.vrt': 'VRT'}
__slots__ = ()
......
......@@ -2,13 +2,22 @@
try:
import otbApplication as otb
OTB_IS_LOAD = True
except ImportError as e:
raise ImportError(
str(e)
+ "\n\nPlease install Orfeo Toolbox if it isn't installed yet.\n\n"
OTB_IS_LOAD = False
ERROR_OTB = ImportError(str(e)
+ "\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 "
"(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:
from osgeo import gdal
except ImportError as e:
......@@ -32,81 +41,130 @@ class IdDefaultDict(dict):
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):
"""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]
instance.gdal_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]
return revert_match[instance.gdal_dtype]
class LStrDataType(DataType):
"""Represent a data type given in lower string format (eg. 'int16', 'int32',
'float32', etc.)"""
data_type_match = {'uint8': otb.ImagePixelType_uint8,
'uint16': otb.ImagePixelType_uint16,
'uint32': otb.ImagePixelType_uint32,
'int16': otb.ImagePixelType_int16,
'int32': otb.ImagePixelType_int32,
'float32': otb.ImagePixelType_float,
'float64': otb.ImagePixelType_double}
# data_type_match = {'uint8': otb.ImagePixelType_uint8,
# 'uint16': otb.ImagePixelType_uint16,
# 'uint32': otb.ImagePixelType_uint32,
# 'int16': otb.ImagePixelType_int16,
# 'int32': otb.ImagePixelType_int32,
# 'float32': otb.ImagePixelType_float,
# '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):
"""Represent a data type given in upper string format (eg. 'Int16', 'Int32',
'Float32', etc.)"""
data_type_match = {'UInt8': otb.ImagePixelType_uint8,
'UInt16': otb.ImagePixelType_uint16,
'UInt32': otb.ImagePixelType_uint32,
'Int16': otb.ImagePixelType_int16,
'Int32': otb.ImagePixelType_int32,
'Float32': otb.ImagePixelType_float,
'Float64': otb.ImagePixelType_double}
# data_type_match = {'UInt8': otb.ImagePixelType_uint8,
# 'UInt16': otb.ImagePixelType_uint16,
# 'UInt32': otb.ImagePixelType_uint32,
# 'Int16': otb.ImagePixelType_int16,
# 'Int32': otb.ImagePixelType_int32,
# 'Float32': otb.ImagePixelType_float,
# '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):
"""Represent a data type for Numpy (eg. np.int16, np.int32, np.float32,
etc.)"""
data_type_match = {np.uint8: otb.ImagePixelType_uint8,
np.uint16: otb.ImagePixelType_uint16,
np.uint32: otb.ImagePixelType_uint32,
np.int16: otb.ImagePixelType_int16,
np.int32: otb.ImagePixelType_int32,
np.int64: otb.ImagePixelType_int32,
np.float32: otb.ImagePixelType_float,
np.float64: otb.ImagePixelType_double}
# data_type_match = {np.uint8: otb.ImagePixelType_uint8,
# np.uint16: otb.ImagePixelType_uint16,
# np.uint32: otb.ImagePixelType_uint32,
# np.int16: otb.ImagePixelType_int16,
# np.int32: otb.ImagePixelType_int32,
# np.int64: otb.ImagePixelType_int32,
# np.float32: otb.ImagePixelType_float,
# 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):
"""Represent a data type for gdal (eg. gdal.GDT_Int16, gdal.GDT_Iint32,
gdal.GDT_Float32, etc.)"""
data_type_match = {gdal.GDT_Byte: otb.ImagePixelType_uint8,
gdal.GDT_UInt16: otb.ImagePixelType_uint16,
gdal.GDT_UInt32: otb.ImagePixelType_uint32,
gdal.GDT_Int16: otb.ImagePixelType_int16,
gdal.GDT_Int32: otb.ImagePixelType_int32,
gdal.GDT_Float32: otb.ImagePixelType_float,
gdal.GDT_Float64: otb.ImagePixelType_double}
# data_type_match = {gdal.GDT_Byte: otb.ImagePixelType_uint8,
# gdal.GDT_UInt16: otb.ImagePixelType_uint16,
# gdal.GDT_UInt32: otb.ImagePixelType_uint32,
# gdal.GDT_Int16: otb.ImagePixelType_int16,
# gdal.GDT_Int32: otb.ImagePixelType_int32,
# gdal.GDT_Float32: otb.ImagePixelType_float,
# 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):
"""Represent a data type for orfeo-toolbox
(eg. otb.ImagePixelType_int16)"""
def __set__(self, instance, value):
instance._otb_type = value
def __get__(self, instance, owner):
return instance._otb_type
# def __set__(self, instance, value):
# instance._otb_type = value
#
# def __get__(self, instance, owner):
# 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):
......@@ -124,7 +182,7 @@ class RasterDataType(object):
numpy_dtype=None,
otb_dtype=None,
gdal_dtype=None):
if lstr_dtype:
self.lstr_dtype = lstr_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