def createAccessor(self): if (not self.filename and hasattr(self, 'metadatalocation') and self.metadatalocation and not self.accessMode.lower().count('write')): #it will only keep going if all ok self.filename = self.checkLocation() caster = '' or self.caster filename = self.filename scheme = self.scheme self.extraFilename = self.filename + '.' + self._extra_reader if self._accessor is None: #to avoid creating duplicates selection = self.methodSelector() if selection == 'api': size = DA.getTypeSize(self.dataType) #to optimize bip access per band we read in memory all bands and then #set the right band and write the content back leaving the other bands untouched #this requires a read and write which only works if the file is opened in #writeread (or readwrite) mode and not just write if (self.accessMode.lower() == 'write'): #if(self.scheme.lower() == 'bip' and self.accessMode.lower() == 'write'): self.accessMode = 'writeread' elif selection == self._extra_reader: size = self.getGDALDataTypeId(self.dataType) filename = self._extraFilename #GDALAccessor handles all the different scheme in the same way since it reads #always in BSQ scheme regardless of the under laying scheme scheme = 'GDAL' else: print('Cannot select appropruiate image API') raise Exception self._accessor, self._factory = DA.createAccessor( filename, self.accessMode, size, self.bands, self.width, scheme, caster, self._extraInfo) return None
def createAccessor(self): if self._accessor is None: #to avoid to creating duplicates size = DA.getTypeSize(self.dataType) caster = '' or self.caster self._accessor, self._factory = DA.createAccessor( self.filename, self.accessMode, size, self.bands, self.width, self.scheme, caster) return None
def getTypeSizeS(type_): return DA.getTypeSize(type_)
def getTypeSize(self): return DA.getTypeSize(self.dataType)
def __init__(self): size = DA.getTypeSize( 'LONG' ) #the size depends on the platform. the ImageAPI does e sizeof(long int) and returns the size #NOTE the unw doent't need a datatype so put '' self._mapDataType = { 'xml': { 'BYTE': '-i1', 'SHORT': '-i2', 'CFLOAT': '-c8', 'FLOAT': '-r4', 'INT': '-i4', 'LONG': '-i' + str(size), 'DOUBLE': '-r8' }, 'rsc': { 'cpx': '-c8', 'rmg': '-r4', 'scor': '-r4', 'dem': '-i2', 'byt': '-i1', 'amp': '-r4', 'unw': '-r4', 'cor': '' } } self._docIn = [ ' mdx.py : displays one or more data files simultaneously by ', ' specifying their names as input. The maximun number,' ' of images that can be displayed depends on the machine', ' architecture and mdx limits. If displayed (no -kml flag)', ' the images don\'t need to have the same extension, but need', ' to have same width.', ' ', ' filename: input file containing the image metadata.', ' Metadata files must be of format filename.{xml,rsc}', ' and must be present in the same directory as filename.', ' Different formats (xml,rsc) can be mixed.', ' ', ' -wrap : sets display scaling to wrap mode with a modules of Pi.', ' It must follow the filename to which the wrap is applied.', ' ', ' ... : the command can be repeated for different images.', ' ', ' -z : zoom factor (+ or -) to apply to all layers. It\'s optional', ' and can appear anywhere in the command sequence and must', ' appear only once.', ' ', ' -kml : only for geocoded images it creates a klm file with all the', ' input images overlaid. Each layer can be turn on or off in ', ' Goolge Earth. It\'s optional and can appear anywhere in the ', ' command sequence and must appear only once. The images don\'t ', ' need to be co-registed.', ' ', ' Examples:', ' mdx.py 01_02.int # Standard way to run mdx.py', ' mdx.py -P 01_02.int # Create a ppm image named out.ppm', ' mdx.py 03_04.int 05_06.int -z -8 # Display two images; zoom out by 8', ' mdx.py 03_04.geo -z 8 05_06.geo -kml fileout.klm # Create a kml file named fileout.kml with two', ' # layers, one per image. Both images are zoomed in', ' # by a factor of 8 ', ' mdx.py 03_04.int 05_06.int -wrap 6.28 # Display two images. Wrap the second modulo 2Pi', ' ' ] # the input file is the image itself. Search for the same filename # and one of the extensions below to figure out the metadata type self._metaExtensions = ['.xml', '.rsc'] self._ext = {} self._ext['cpx'] = ['slc', 'int', 'flat', 'mph', 'cpx'] self._ext['rmg'] = ['hgt', 'hgt_holes', 'rect', 'rmg'] self._ext['scor'] = ['scor'] self._ext['dem'] = ['dem', 'dte', 'dtm'] self._ext['unw'] = ['unw'] self._ext['cor'] = ['cor'] self._ext['byt'] = ['byt', 'flg'] self._ext['amp'] = ['amp'] self._ext['bil'] = ['bil'] self._ext['bip'] = ['bip'] self._ext['bsq'] = ['bsq'] # save this quantities in the case we are dealing with a geo image self._startLat = [] self._deltaLat = [] self._startLon = [] self._deltaLon = [] self._length = [] self._width = [] self._names = []