예제 #1
0
    def _read(self):
        data = gdal.Open( self.filename )
        if data is None:
            raise ProviderError("Can't read the file '%s'" % self.filename)

        self.geodata = {}
        self.geodata['xSize'] = data.RasterXSize
        self.geodata['ySize'] = data.RasterYSize
        self.geodata['proj']  = data.GetProjection()
        self.geodata['transform']  = data.GetGeoTransform()

        # Get units of the projection
        sr = osr.SpatialReference()
        sr.ImportFromWkt(self.geodata['proj'])
        self.geodata['units'] = sr.GetLinearUnitsName()

        self.bands = []
        for i in range(1, data.RasterCount+1):
            r = data.GetRasterBand(i)
            nodataValue =  r.GetNoDataValue()
            r = r.ReadAsArray()
            if nodataValue:
                mask = binaryzation(r, [nodataValue])
                r = ma.array(data = r, mask=mask)
            self.bands.append(r)
        self.resetMask()
        self.isNormalazed = False
예제 #2
0
    def resetMask(self, maskVals = None):
        '''
        Set mask of _ALL_ bands.  maskVals is a list of masked values.
        '''
        if not maskVals: maskVals = []

        for i in range(self.getBandsCount()):
            r = self.getBand(i)
            mask = binaryzation(r, maskVals)
            r = ma.array(data = r, mask=mask)
            self.setBand(r, i)
예제 #3
0
 def resetMask(self, maskVals=None):
     '''
     Set mask of _ALL_ bands.  maskVals is a list of masked values.
     '''
     for i in range(self.getBandsCount()):
         r = self.getBand(i)
         if maskVals != None:
             mask = binaryzation(r, maskVals)
         else:
             mask = False
         r = ma.array(data=r, mask=mask)
         self.setBand(r, i)
예제 #4
0
    def _read(self):
        try:
            data = gdal.Open(self.filename)
        except RuntimeError:
            raise ProviderError("Can't read the file '%s'" % self.filename)
        if data is None:
            raise ProviderError("Can't read the file '%s'" % self.filename)

        self.geodata = {}
        self.geodata['xSize'] = data.RasterXSize
        self.geodata['ySize'] = data.RasterYSize
        self.geodata['proj'] = data.GetProjection()
        self.geodata['transform'] = data.GetGeoTransform()

        # Get units of the projection
        sr = osr.SpatialReference()
        sr.ImportFromWkt(self.geodata['proj'])
        self.geodata['units'] = sr.GetLinearUnitsName()

        self.bands = np.ma.zeros(
            (data.RasterCount, self.geodata['ySize'], self.geodata['xSize']),
            dtype=float)
        self.bandcount = data.RasterCount
        if self.maskVals != None and len(self.maskVals) != self.bandcount:
            raise ProviderError(
                "Band count of the file '%s' does't match nodata values count"
                % self.filename)

        for i in range(1, data.RasterCount + 1):
            r = data.GetRasterBand(i)
            nodataValue = r.GetNoDataValue()
            if nodataValue != None:
                nodataValues = [nodataValue]
            else:
                nodataValues = []
            r = r.ReadAsArray()
            #self.bandgradation[i] = None
            try:
                userNodataValues = self.maskVals[i]
            except TypeError:
                userNodataValues = []
            nodataValues += userNodataValues
            if nodataValues != []:
                mask = binaryzation(r, nodataValues)
                r = ma.array(data=r, mask=mask)
            else:
                r = ma.array(data=r, mask=False)
            self.bands[i - 1, :, :] = r
        self.isNormalazed = False
예제 #5
0
    def _read(self):
        try:
            data = gdal.Open( self.filename )
        except RuntimeError:
            raise ProviderError("Can't read the file '%s'" % self.filename)
        if data is None:
            raise ProviderError("Can't read the file '%s'" % self.filename)

        self.geodata = {}
        self.geodata['xSize'] = data.RasterXSize
        self.geodata['ySize'] = data.RasterYSize
        self.geodata['proj']  = data.GetProjection()
        self.geodata['transform']  = data.GetGeoTransform()

        # Get units of the projection
        sr = osr.SpatialReference()
        sr.ImportFromWkt(self.geodata['proj'])
        self.geodata['units'] = sr.GetLinearUnitsName()

        self.bands = np.ma.zeros((data.RasterCount,self.geodata['ySize'], self.geodata['xSize']), dtype=float)
        self.bandcount = data.RasterCount
        if self.maskVals != None and len(self.maskVals) != self.bandcount:
            raise ProviderError("Band count of the file '%s' does't match nodata values count" % self.filename)

        for i in range(1, data.RasterCount+1):
            r = data.GetRasterBand(i)
            nodataValue =  r.GetNoDataValue()
            if nodataValue != None:
                nodataValues = [nodataValue]
            else:
                nodataValues = []
            r = r.ReadAsArray()
            #self.bandgradation[i] = None
            try:
                userNodataValues =  self.maskVals[i]
            except TypeError:
                userNodataValues = []
            nodataValues += userNodataValues
            if nodataValues != []:
                mask = binaryzation(r, nodataValues)
                r = ma.array(data = r, mask=mask)
            else:
                r = ma.array(data = r, mask=False)
            self.bands[i-1, :, :] = r
        self.isNormalazed = False
예제 #6
0
 def binaryzation(self, trueVals, bandNum):
     '''Reclass band bandNum to true/false mode. Set true for pixels from trueVals.'''
     r = self.getBand(bandNum)
     r = binaryzation(r, trueVals)
     self.setBand(r, bandNum)
예제 #7
0
 def binaryzation(self, trueVals, bandNum):
     '''Reclass band bandNum to true/false mode. Set true for pixels from trueVals.'''
     r = self.getBand(bandNum)
     r = binaryzation(r, trueVals)
     self.setBand(r, bandNum)