Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#/* Get other info. */
#/* -------------------------------------------------------------------- */
poSrcFDefn = poSrcLayer.GetLayerDefn()
if poOutputSRS is None:
poOutputSRS = poSrcLayer.GetSpatialRef()
#/* -------------------------------------------------------------------- */
#/* Find the layer. */
#/* -------------------------------------------------------------------- */
#/* GetLayerByName() can instanciate layers that would have been */
#*/ 'hidden' otherwise, for example, non-spatial tables in a */
#*/ Postgis-enabled database, so this apparently useless command is */
#/* not useless... (#4012) */
gdal.PushErrorHandler('CPLQuietErrorHandler')
poDstLayer = poDstDS.GetLayerByName(pszNewLayerName)
gdal.PopErrorHandler()
gdal.ErrorReset()
iLayer = -1
if poDstLayer is not None:
nLayerCount = poDstDS.GetLayerCount()
for iLayer in range(nLayerCount):
poLayer = poDstDS.GetLayer(iLayer)
# The .cpp version compares on pointers directly, but we cannot
# do this with swig object, so just compare the names.
if poLayer is not None \
and poLayer.GetName() == poDstLayer.GetName():
break
if (iLayer == nLayerCount):
def find_ogr_layer(ds, layerName):
# From ogr2ogr.py:
#/* GetLayerByName() can instanciate layers that would have been */
#*/ 'hidden' otherwise, for example, non-spatial tables in a */
#*/ Postgis-enabled database, so this apparently useless command is */
# /* not useless... (#4012) */
gdal.PushErrorHandler('CPLQuietErrorHandler')
poDstLayer = ds.GetLayerByName(layerName)
gdal.PopErrorHandler()
gdal.ErrorReset()
iLayer = None
if poDstLayer is not None:
nLayerCount = ds.GetLayerCount()
for iLayer in range(nLayerCount):
poLayer = ds.GetLayer(iLayer)
# The .cpp version compares on pointers directly, but we cannot
# do this with swig object, so just compare the names.
if poLayer is not None and poLayer.GetName() == poDstLayer.GetName():
break
if (iLayer == nLayerCount):
# /* shouldn't happen with an ideal driver */
gdal.CE_Fatal:'Fatal'
}
err_msg = err_msg.replace('\n',' ')
err_class = errtype.get(err_class, 'None')
print('Error Number: %s' % (err_num))
print('Error Type: %s' % (err_class))
print('Error Message: %s' % (err_msg))
try:
import ogr
import osr
import gdal
version_num = int(gdal.VersionInfo('VERSION_NUM'))
if version_num >= 2000000:
has_ogr = True
gdal.PushErrorHandler(gdal_error_handler)
else:
print('GDAL version >= 2.0 is required:')
has_ogr = False
except Exception as e:
print('GDAL is not available:')
print(e)
has_ogr = False
class TestRun(unittest.TestCase):
"""Tests for (non-scalar) LagrangianArray"""
def make_OceanDrift_object(self):
self.o = OceanDrift(loglevel=30)
self.fake_eddy = reader_ArtificialOceanEddy.Reader(2, 62)
self.o.use_block = False
self.reader_landmask = reader_global_landmask.Reader(
def tiff_write_63():
md = gdaltest.tiff_drv.GetMetadata()
if md['DMD_CREATIONOPTIONLIST'].find('BigTIFF') == -1:
return 'skip'
try:
if int(gdal.VersionInfo('VERSION_NUM')) < 1700:
return 'skip'
except:
# OG-python bindings don't have gdal.VersionInfo. Too bad, but let's hope that GDAL's version isn't too old !
pass
gdal.PushErrorHandler('CPLQuietErrorHandler')
ds = gdaltest.tiff_drv.Create( 'tmp/bigtiff.tif', 150000, 150000, 1,
options = ['BIGTIFF=NO'] )
gdal.PopErrorHandler()
if ds is None:
return 'success'
return 'fail'
gdal.CE_Fatal:'Fatal'
}
err_msg = err_msg.replace('\n',' ')
err_class = errtype.get(err_class, 'None')
print('Error Number: %s' % (err_num))
print('Error Type: %s' % (err_class))
print('Error Message: %s' % (err_msg))
try:
import ogr
import osr
import gdal
version_num = int(gdal.VersionInfo('VERSION_NUM'))
if version_num >= 2000000:
has_ogr = True
gdal.PushErrorHandler(gdal_error_handler)
else:
print('GDAL version >= 2.0 is required:')
has_ogr = False
except Exception as e:
print('GDAL is not available:')
print(e)
has_ogr = False
class TestRun(unittest.TestCase):
"""Tests for (non-scalar) LagrangianArray"""
def make_OceanDrift_object(self):
self.o = OceanDrift(loglevel=30)
self.fake_eddy = reader_ArtificialOceanEddy.Reader(2, 62)
self.o.use_block = False
self.reader_basemap = reader_basemap_landmask.Reader(
for fi in file_infos:
ulx = min(ulx, fi.ulx)
uly = max(uly, fi.uly)
lrx = max(lrx, fi.lrx)
lry = min(lry, fi.lry)
if psize_x is None:
psize_x = file_infos[0].geotransform[1]
psize_y = file_infos[0].geotransform[5]
if band_type is None:
band_type = file_infos[0].band_type
# Try opening as an existing file.
gdal.PushErrorHandler( 'CPLQuietErrorHandler' )
t_fh = gdal.Open( out_file, gdal.GA_Update )
gdal.PopErrorHandler()
# Create output file if it does not already exist.
if t_fh is None:
geotransform = [ulx, psize_x, 0, uly, 0, psize_y]
xsize = int((lrx - ulx) / geotransform[1] + 0.5)
ysize = int((lry - uly) / geotransform[5] + 0.5)
if separate != 0:
bands = len(file_infos)
else:
bands = file_infos[0].bands
t_fh = Driver.Create( out_file, xsize, ysize, bands,
def open_input(self):
"""Initialization of the input raster, reprojection if necessary"""
gdal.UseExceptions()
gdal.AllRegister()
if not self.options.verbose:
gdal.PushErrorHandler('CPLQuietErrorHandler')
# Initialize necessary GDAL drivers
self.out_drv = gdal.GetDriverByName(self.tiledriver)
self.mem_drv = gdal.GetDriverByName('MEM')
if not self.out_drv:
raise Exception(
"The '%s' driver was not found, is it available in this GDAL build?",
self.tiledriver)
if not self.mem_drv:
raise Exception(
"The 'MEM' driver was not found, is it available in this GDAL build?")
# Open the input file
def rasterToArray(self, in_raster):
gdal.UseExceptions()
gdal.PushErrorHandler('CPLQuietErrorHandler')
ds = gdal.Open(in_raster).ReadAsArray()
return ds
def open_input(self):
"""Initialization of the input raster, reprojection if necessary"""
gdal.UseExceptions()
gdal.AllRegister()
if not self.options.verbose:
gdal.PushErrorHandler('CPLQuietErrorHandler')
# Initialize necessary GDAL drivers
self.out_drv = gdal.GetDriverByName(self.tiledriver)
self.mem_drv = gdal.GetDriverByName('MEM')
if not self.out_drv:
raise Exception("The '%s' driver was not found, is it available in this GDAL build?"
, self.tiledriver)
if not self.mem_drv:
raise Exception("The 'MEM' driver was not found, is it available in this GDAL build?"
)
# Open the input file
if self.input:
def startup():
#directory = sys.argv[1]
gdal.PushErrorHandler()
skiplist = ['.svn','.shx','.dbf']
startpath = options.directory
pathwalker = os.walk(startpath)
walkers = itertools.tee(pathwalker)
counterraster = 0
countervds = 0
# walkerlist = list(copy.pathwalker)
processStats(walkers[1], skiplist, startpath,xmlroot)
for eachpath in walkers[0]:
startdir = eachpath[0]
alldirs = eachpath[1]
allfiles = eachpath[2]
for eachdir in alldirs:
currentdir = os.path.join(startdir,eachdir)
#print currentdir