Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
old_accum = gdal.GetConfigOption( 'CPL_ACCUM_ERROR_MSG', 'OFF' )
gdal.SetConfigOption( 'CPL_ACCUM_ERROR_MSG', 'ON' )
gdal.ErrorReset()
gdal.PushErrorHandler( 'CPLQuietErrorHandler' )
try:
ds = gdal.Open('data/mandrilmini_12bitjpeg.tif')
ds.GetRasterBand(1).ReadRaster(0,0,1,1)
except:
ds = None
gdal.PopErrorHandler()
gdal.SetConfigOption( 'CPL_ACCUM_ERROR_MSG', old_accum )
if gdal.GetLastErrorMsg().find(
'Unsupported JPEG data precision 12') != -1:
sys.stdout.write('(12bit jpeg not available) ... ')
return 'skip'
drv = gdal.GetDriverByName('GTiff')
dst_ds = drv.CreateCopy( 'tmp/test_74.tif', ds,
options = ['COMPRESS=JPEG', 'NBITS=12',
'JPEG_QUALITY=95',
'PHOTOMETRIC=YCBCR'] )
ds = None
dst_ds = None
dst_ds = gdal.Open( 'tmp/test_74.tif' )
stats = dst_ds.GetRasterBand(1).GetStatistics( 0, 1 )
"""
#
# NOTE: A special requirement of the Atlantis Peppers system is
# that it needs to be able to instantiate a coordinate tranform
# by just passing in a tuple with two SpatialReference objects. We
# assume this is the case if target is None.
self._o = None
if target is None:
target = source[1]
source = source[0]
gdal.ErrorReset()
self._o = _gdal.OCTNewCoordinateTransformation( source._o, target._o )
if self._o is None or self._o == 'NULL':
if len(gdal.GetLastErrorMsg()) > 0:
raise ValueError, gdal.GetLastErrorMsg()
else:
raise ValueError, 'Failed to create coordinate transformation.'
def GetUserInputAsWKT( user_def ):
srs = SpatialReference()
if srs.SetFromUserInput( user_def ) == 0:
return srs.ExportToWkt()
else:
raise ValueError, gdal.GetLastErrorMsg()
def CopyLayer(self, src_layer, new_name, options = [] ):
md_c = _gdal.ListToStringList( options )
obj = _gdal.OGR_DS_CopyLayer( self._o, src_layer._o, new_name, md_c)
_gdal.CSLDestroy(md_c)
if obj is None and obj != 'NULL':
raise OGRError, gdal.GetLastErrorMsg()
else:
return Layer( obj = obj )
def GetUserInputAsWKT( user_def ):
srs = SpatialReference()
if srs.SetFromUserInput( user_def ) == 0:
return srs.ExportToWkt()
else:
raise ValueError, gdal.GetLastErrorMsg()
def LoadFile( filename, xoff=0, yoff=0, xsize=None, ysize=None ):
ds = gdal.Open( filename )
if ds is None:
raise ValueError("Can't open "+filename+"\n\n"+gdal.GetLastErrorMsg())
return DatasetReadAsArray( ds, xoff, yoff, xsize, ysize )
def LoadFile( filename, xoff=0, yoff=0, xsize=None, ysize=None ):
ds = gdal.Open( filename )
if ds is None:
raise ValueError("Can't open "+filename+"\n\n"+gdal.GetLastErrorMsg())
return DatasetReadAsArray( ds, xoff, yoff, xsize, ysize )
str(c.name), c.python_type(c.default))
except:
raise
else:
raise Exception("Can only handle dict rows")
if self.transform:
geometry.Transform(self.transform)
feature.SetGeometryDirectly(geometry)
if self.layer.CreateFeature(feature) != 0:
raise FeatureError(
'Failed to add feature: {}: geometry={}'.format(
gdal.GetLastErrorMsg(),
geometry.ExportToWkt()))
feature.Destroy()
name = self.mangle_name(str(name))
feature.SetField(name, value)
except Exception:
raise
except NotImplementedError:
raise
geometry = ogr.CreateGeometryFromWkt(row['_wkt'])
feature.SetGeometryDirectly(geometry)
if layer.CreateFeature(feature) != 0:
import gdal
raise Exception(
'Failed to add feature: {}: geometry={}'.format(gdal.GetLastErrorMsg(), geometry.ExportToWkt()))
feature.Destroy()
ds.SyncToDisk()
ds.Release()
return True, abs_dest