def AdviseRead( self, nXOff, nYOff, nXSize, nYSize, nBufXSize = None, nBufYSize = None, eDT = None, BandMap = None, options = [] ): if BandMap is None: BandMap = range(1,self.RasterCount+1) if eDT is None: eDT = self._band[0].DataType if nBufXSize is None: nBufXSize = nXSize if nBufYSize is None: nBufYSize = nYSize IntBandMap = _gdal.ptrcreate('int',0,len(BandMap)) for i in range(len(BandMap)): _gdal.ptrset( IntBandMap, BandMap[i], i ) sl_options = _gdal.ListToStringList( options ) result = _gdal.GDALDatasetAdviseRead( self._o, nXOff, nYOff, nXSize, nYSize, nBufXSize, nBufYSize, eDT, len(BandMap), IntBandMap, sl_options ) _gdal.CSLDestroy( sl_options ) _gdal.ptrfree( IntBandMap ) return result
def AdviseRead(self, nXOff, nYOff, nXSize, nYSize, nBufXSize=None, nBufYSize=None, eDT=None, BandMap=None, options=[]): if BandMap is None: BandMap = range(1, self.RasterCount + 1) if eDT is None: eDT = self._band[0].DataType if nBufXSize is None: nBufXSize = nXSize if nBufYSize is None: nBufYSize = nYSize IntBandMap = _gdal.ptrcreate('int', 0, len(BandMap)) for i in range(len(BandMap)): _gdal.ptrset(IntBandMap, BandMap[i], i) sl_options = _gdal.ListToStringList(options) result = _gdal.GDALDatasetAdviseRead(self._o, nXOff, nYOff, nXSize, nYSize, nBufXSize, nBufYSize, eDT, len(BandMap), IntBandMap, sl_options) _gdal.CSLDestroy(sl_options) _gdal.ptrfree(IntBandMap) return result
def GetColorEntryAsRGB(self, i): entry = ptrcreate('short', 0, 4) _gdal.GDALGetColorEntryAsRGB(self._o, i, ptrcast(entry, 'GDALColorEntry_p')) res = (ptrvalue(entry, 0), ptrvalue(entry, 1), ptrvalue(entry, 2), ptrvalue(entry, 3)) ptrfree(entry) return res
def GetEnvelope(self): extents = _gdal.ptrcreate('double', 0.0, 4) _gdal.OGR_G_GetEnvelope(self._o, _gdal.ptrcast(extents, 'OGREnvelope_p')) ret_extents = (_gdal.ptrvalue(extents, 0), _gdal.ptrvalue(extents, 1), _gdal.ptrvalue(extents, 2), _gdal.ptrvalue(extents, 3)) _gdal.ptrfree(extents) return ret_extents
def SetGeoTransform(self, transform): c_transform = _gdal.ptrcreate('double', 0, 6) for i in range(6): _gdal.ptrset(c_transform, transform[i], i) err = _gdal.GDALSetGeoTransform(self._o, c_transform) _gdal.ptrfree(c_transform) return err
def ComputeBandStats( self, samplestep = 1, progress_cb = None, progress_data = None ): mean_p = _gdal.ptrcreate( 'double',0,1) stddev_p = _gdal.ptrcreate( 'double',0,1) (prog_cb, prog_info) = \ _gdal.MakeProgressInfo( progress_cb, progress_data ) result = _gdal.GDALComputeBandStats( self._o, samplestep, mean_p, stddev_p, prog_cb, prog_info ) mean_stddev = ( _gdal.ptrvalue(mean_p,0), _gdal.ptrvalue(stddev_p,0) ) _gdal.ptrfree( mean_p ) _gdal.ptrfree( stddev_p ) _gdal.ptrfree( prog_info ) if result != 0: raise ValueError, GetLastErrorMsg() else: return mean_stddev
def SetGeoTransform(self,transform): c_transform = _gdal.ptrcreate('double',0,6) for i in range(6): _gdal.ptrset( c_transform, transform[i], i ); err = _gdal.GDALSetGeoTransform(self._o,c_transform) _gdal.ptrfree( c_transform ) return err
def GetScale(self): c_success_flag = ptrcreate('int',0,1) result = _gdal.GDALGetRasterScale(self._o,c_success_flag) success_flag = ptrvalue(c_success_flag,0) ptrfree(c_success_flag) if success_flag: return result else: return None
def GetScale(self): c_success_flag = ptrcreate('int', 0, 1) result = _gdal.GDALGetRasterScale(self._o, c_success_flag) success_flag = ptrvalue(c_success_flag, 0) ptrfree(c_success_flag) if success_flag: return result else: return None
def GetEnvelope( self ): extents = _gdal.ptrcreate( 'double', 0.0, 4 ) _gdal.OGR_G_GetEnvelope( self._o, _gdal.ptrcast(extents,'OGREnvelope_p') ) ret_extents = ( _gdal.ptrvalue( extents, 0 ), _gdal.ptrvalue( extents, 1 ), _gdal.ptrvalue( extents, 2 ), _gdal.ptrvalue( extents, 3 ) ) _gdal.ptrfree( extents ) return ret_extents
def ComputeBandStats(self, samplestep=1, progress_cb=None, progress_data=None): mean_p = _gdal.ptrcreate('double', 0, 1) stddev_p = _gdal.ptrcreate('double', 0, 1) (prog_cb, prog_info) = \ _gdal.MakeProgressInfo( progress_cb, progress_data ) result = _gdal.GDALComputeBandStats(self._o, samplestep, mean_p, stddev_p, prog_cb, prog_info) mean_stddev = (_gdal.ptrvalue(mean_p, 0), _gdal.ptrvalue(stddev_p, 0)) _gdal.ptrfree(mean_p) _gdal.ptrfree(stddev_p) _gdal.ptrfree(prog_info) if result != 0: raise ValueError, GetLastErrorMsg() else: return mean_stddev
def SetDefaultHistogram(self, min, max, histogram): count = len(histogram) hist_array = ptrcreate('int', 0, count) for i in range(count): ptrset(hist_array, histogram[i], i) result = _gdal.GDALSetDefaultHistogram(self._o, min, max, count, hist_array) ptrfree(hist_array) return result
def GetColorEntryAsRGB( self, i ): entry = ptrcreate( 'short', 0, 4 ) _gdal.GDALGetColorEntryAsRGB( self._o, i, ptrcast(entry,'GDALColorEntry_p') ) res = (ptrvalue(entry, 0), ptrvalue(entry, 1), ptrvalue(entry, 2), ptrvalue(entry, 3) ) ptrfree( entry ) return res
def SetDefaultHistogram( self, min, max, histogram ): count = len(histogram) hist_array = ptrcreate( 'int', 0, count) for i in range(count): ptrset( hist_array, histogram[i], i ) result = _gdal.GDALSetDefaultHistogram( self._o, min, max, count, hist_array ) ptrfree( hist_array ) return result
def SetColorEntry(self, i, color): entry = ptrcreate('short', 0, 4) for j in range(4): if j >= len(color): ptrset(entry, 255, j) else: ptrset(entry, int(color[j]), j) res = _gdal.GDALSetColorEntry(self._o, i, ptrcast(entry, 'GDALColorEntry_p')) ptrfree(entry) return res
def ToNULLableString(x): if x is None or x == 'NULL': return 'NULL' else: l = len(x) p = ptrcreate('char', '', l + 1) for i in range(l): ptrset(p, x[i], i) ptrset(p, chr(0), l) return ptrcast(p, 'NULLableString')
def ToNULLableString(x): if x is None or x == 'NULL': return 'NULL' else: l = len(x) p = ptrcreate( 'char', '', l+1 ) for i in range(l): ptrset( p, x[i], i ) ptrset( p, chr(0), l ) return ptrcast(p,'NULLableString')
def SetColorEntry( self, i, color ): entry = ptrcreate( 'short', 0, 4 ) for j in range(4): if j >= len(color): ptrset( entry, 255, j ) else: ptrset( entry, int(color[j]), j ) res = _gdal.GDALSetColorEntry( self._o, i, ptrcast(entry,'GDALColorEntry_p') ) ptrfree( entry ) return res
def GetStatistics( self, approx_ok = 0, force = 1 ): x = ptrcreate( 'double', 0, 4 ) err = _gdal.GDALGetRasterStatistics( self._o, approx_ok, force, x, ptradd(x,1), ptradd(x,2), ptradd(x,3) ) if err != 0: ptrfree( x ) raise ValueError, GetLastErrorMsg() result = (ptrvalue(x,0),ptrvalue(x,1),ptrvalue(x,2),ptrvalue(x,3)) ptrfree(x) return result
def GetTOWGS84(self): pd = ptrcreate('double', 0.0, 7) err = _gdal.OSRGetTOWGS84(self._o, pd, 7) if err != 0: print err raise ValueError, ('GetTOWGS84() failed, err = %d.' % err) result = (ptrvalue(pd, 0), ptrvalue(pd, 1), ptrvalue(pd, 2), ptrvalue(pd, 3), ptrvalue(pd, 4), ptrvalue(pd, 5), ptrvalue(pd, 6)) ptrfree(pd) return result
def GetStatistics(self, approx_ok=0, force=1): x = ptrcreate('double', 0, 4) err = _gdal.GDALGetRasterStatistics(self._o, approx_ok, force, x, ptradd(x, 1), ptradd(x, 2), ptradd(x, 3)) if err != 0: ptrfree(x) raise ValueError, GetLastErrorMsg() result = (ptrvalue(x, 0), ptrvalue(x, 1), ptrvalue(x, 2), ptrvalue(x, 3)) ptrfree(x) return result
def GetGeoTransform(self): c_transform = _gdal.ptrcreate('double',0,6) if _gdal.GDALGetGeoTransform(self._o, c_transform) == 0: transform = ( _gdal.ptrvalue(c_transform,0), _gdal.ptrvalue(c_transform,1), _gdal.ptrvalue(c_transform,2), _gdal.ptrvalue(c_transform,3), _gdal.ptrvalue(c_transform,4), _gdal.ptrvalue(c_transform,5) ) else: transform = (0,1,0,0,0,1) _gdal.ptrfree( c_transform ) return transform
def GetGeoTransform(self): c_transform = _gdal.ptrcreate('double', 0, 6) if _gdal.GDALGetGeoTransform(self._o, c_transform) == 0: transform = (_gdal.ptrvalue(c_transform, 0), _gdal.ptrvalue(c_transform, 1), _gdal.ptrvalue(c_transform, 2), _gdal.ptrvalue(c_transform, 3), _gdal.ptrvalue(c_transform, 4), _gdal.ptrvalue(c_transform, 5)) else: transform = (0, 1, 0, 0, 0, 1) _gdal.ptrfree(c_transform) return transform
def GetExtent( self, force = 1 ): """Returns the extent of the layer as a four-tuple""" extents = _gdal.ptrcreate( 'double', 0.0, 4 ) res = _gdal.OGR_L_GetExtent( self._o, _gdal.ptrcast(extents,'OGREnvelope_p'), force ) if res != 0: ret_extents = None else: ret_extents = ( _gdal.ptrvalue( extents, 0 ), _gdal.ptrvalue( extents, 1 ), _gdal.ptrvalue( extents, 2 ), _gdal.ptrvalue( extents, 3 ) ) _gdal.ptrfree( extents ) return ret_extents
def GetExtent(self, force=1): """Returns the extent of the layer as a four-tuple""" extents = _gdal.ptrcreate('double', 0.0, 4) res = _gdal.OGR_L_GetExtent(self._o, _gdal.ptrcast(extents, 'OGREnvelope_p'), force) if res != 0: ret_extents = None else: ret_extents = (_gdal.ptrvalue(extents, 0), _gdal.ptrvalue(extents, 1), _gdal.ptrvalue(extents, 2), _gdal.ptrvalue(extents, 3)) _gdal.ptrfree(extents) return ret_extents
def GetTOWGS84( self ): pd = ptrcreate( 'double', 0.0, 7 ) err = _gdal.OSRGetTOWGS84( self._o, pd, 7 ) if err != 0: print err raise ValueError, ('GetTOWGS84() failed, err = %d.' % err) result = ( ptrvalue(pd,0), ptrvalue(pd,1), ptrvalue(pd,2), ptrvalue(pd,3), ptrvalue(pd,4), ptrvalue(pd,5), ptrvalue(pd,6) ) ptrfree( pd ) return result
def UnescapeString( in_string, scheme = CPLES_BackslashQuotable ): ret_len = _gdal.ptrcreate('int',0,1) result = _gdal.CPLUnescapeString( in_string, ret_len, scheme) _gdal.ptrfree( ret_len ) return result
def ComputeRasterMinMax(self, approx_ok=0): c_minmax = ptrcreate('double', 0, 2) _gdal.GDALComputeRasterMinMax(self._o, approx_ok, c_minmax) result = (ptrvalue(c_minmax, 0), ptrvalue(c_minmax, 1)) ptrfree(c_minmax) return result
def GetBlockSize(band): x = _gdal.ptrcreate('int', 0, 2) _gdal.GDALGetBlockSize(band._o, x, _gdal.ptradd(x, 1)) result = (_gdal.ptrvalue(x, 0), _gdal.ptrvalue(x, 1)) _gdal.ptrfree(x) return result
def UnescapeString(in_string, scheme=CPLES_BackslashQuotable): ret_len = _gdal.ptrcreate('int', 0, 1) result = _gdal.CPLUnescapeString(in_string, ret_len, scheme) _gdal.ptrfree(ret_len) return result
def GetBlockSize(band): x = _gdal.ptrcreate('int', 0, 2) _gdal.GDALGetBlockSize(band._o, x, _gdal.ptradd(x, 1)) result = (_gdal.ptrvalue(x, 0), _gdal.ptrvalue(x, 1)) _gdal.ptrfree(x) return result
def ComputeRasterMinMax(self, approx_ok = 0): c_minmax = ptrcreate('double',0,2) _gdal.GDALComputeRasterMinMax(self._o, approx_ok, c_minmax ) result = ( ptrvalue(c_minmax,0), ptrvalue(c_minmax,1) ) ptrfree( c_minmax ) return result